Skip to content

Commit a252868

Browse files
committed
fix(default-expressions and examples configs): avoid applying deprecated rules now that ESLint warns against them; fixes #1651
Use `@stylistic` rules instead
1 parent 122d283 commit a252868

File tree

2 files changed

+50
-30
lines changed

2 files changed

+50
-30
lines changed

src/index-cjs.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ import tsNoUnnecessaryTemplateExpression from './rules/tsNoUnnecessaryTemplateEx
7373
import tsPreferFunctionType from './rules/tsPreferFunctionType.js';
7474
import typeFormatting from './rules/typeFormatting.js';
7575
import validTypes from './rules/validTypes.js';
76+
import {
77+
ESLint,
78+
} from 'eslint';
79+
import semver from 'semver';
7680

7781
/**
7882
* @typedef {"recommended" | "stylistic" | "contents" | "logical" | "requirements"} ConfigGroups
@@ -592,9 +596,6 @@ index.configs.examples = /** @type {import('eslint').Linter.Config[]} */ ([
592596

593597
'@typescript-eslint/no-unused-vars': 0,
594598

595-
// "always" newline rule at end unlikely in sample code
596-
'eol-last': 0,
597-
598599
// Wouldn't generally expect example paths to resolve relative to JS file
599600
'import/no-unresolved': 0,
600601

@@ -614,9 +615,18 @@ index.configs.examples = /** @type {import('eslint').Linter.Config[]} */ ([
614615
// Unlikely to have inadvertent debugging within examples
615616
'no-console': 0,
616617

617-
// Often wish to start `@example` code after newline; also may use
618-
// empty lines for spacing
619-
'no-multiple-empty-lines': 0,
618+
/* c8 ignore next 11 -- Coercion should work */
619+
...(semver.gte(semver.coerce(ESLint.version) ?? '9.0.0', '9.0.0') ? {} : {
620+
// "always" newline rule at end unlikely in sample code
621+
'eol-last': 0,
622+
623+
// Often wish to start `@example` code after newline; also may use
624+
// empty lines for spacing
625+
'no-multiple-empty-lines': 0,
626+
627+
// Can generally look nicer to pad a little even if code imposes more stringency
628+
'padded-blocks': 0,
629+
}),
620630

621631
// Many variables in examples will be `undefined`
622632
'no-undef': 0,
@@ -626,9 +636,6 @@ index.configs.examples = /** @type {import('eslint').Linter.Config[]} */ ([
626636
// See import/no-unresolved
627637
'node/no-missing-import': 0,
628638
'node/no-missing-require': 0,
629-
630-
// Can generally look nicer to pad a little even if code imposes more stringency
631-
'padded-blocks': 0,
632639
},
633640
},
634641
]);
@@ -666,12 +673,15 @@ index.configs['default-expressions'] = /** @type {import('eslint').Linter.Config
666673
'no-empty-function': 0,
667674
'no-new': 0,
668675
'no-unused-expressions': 0,
669-
quotes: [
670-
'error', 'double',
671-
],
672-
semi: [
673-
'error', 'never',
674-
],
676+
/* c8 ignore next 8 -- Coercion should work */
677+
...(semver.gte(semver.coerce(ESLint.version) ?? '9.0.0', '9.0.0') ? {} : {
678+
quotes: [
679+
'error', 'double',
680+
],
681+
semi: [
682+
'error', 'never',
683+
],
684+
}),
675685
strict: 0,
676686
},
677687
},

src/index.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ import tsNoUnnecessaryTemplateExpression from './rules/tsNoUnnecessaryTemplateEx
7979
import tsPreferFunctionType from './rules/tsPreferFunctionType.js';
8080
import typeFormatting from './rules/typeFormatting.js';
8181
import validTypes from './rules/validTypes.js';
82+
import {
83+
ESLint,
84+
} from 'eslint';
85+
import semver from 'semver';
8286

8387
/**
8488
* @typedef {"recommended" | "stylistic" | "contents" | "logical" | "requirements"} ConfigGroups
@@ -598,9 +602,6 @@ index.configs.examples = /** @type {import('eslint').Linter.Config[]} */ ([
598602

599603
'@typescript-eslint/no-unused-vars': 0,
600604

601-
// "always" newline rule at end unlikely in sample code
602-
'eol-last': 0,
603-
604605
// Wouldn't generally expect example paths to resolve relative to JS file
605606
'import/no-unresolved': 0,
606607

@@ -620,9 +621,18 @@ index.configs.examples = /** @type {import('eslint').Linter.Config[]} */ ([
620621
// Unlikely to have inadvertent debugging within examples
621622
'no-console': 0,
622623

623-
// Often wish to start `@example` code after newline; also may use
624-
// empty lines for spacing
625-
'no-multiple-empty-lines': 0,
624+
/* c8 ignore next 11 -- Coercion should work */
625+
...(semver.gte(semver.coerce(ESLint.version) ?? '9.0.0', '9.0.0') ? {} : {
626+
// "always" newline rule at end unlikely in sample code
627+
'eol-last': 0,
628+
629+
// Often wish to start `@example` code after newline; also may use
630+
// empty lines for spacing
631+
'no-multiple-empty-lines': 0,
632+
633+
// Can generally look nicer to pad a little even if code imposes more stringency
634+
'padded-blocks': 0,
635+
}),
626636

627637
// Many variables in examples will be `undefined`
628638
'no-undef': 0,
@@ -632,9 +642,6 @@ index.configs.examples = /** @type {import('eslint').Linter.Config[]} */ ([
632642
// See import/no-unresolved
633643
'node/no-missing-import': 0,
634644
'node/no-missing-require': 0,
635-
636-
// Can generally look nicer to pad a little even if code imposes more stringency
637-
'padded-blocks': 0,
638645
},
639646
},
640647
]);
@@ -672,12 +679,15 @@ index.configs['default-expressions'] = /** @type {import('eslint').Linter.Config
672679
'no-empty-function': 0,
673680
'no-new': 0,
674681
'no-unused-expressions': 0,
675-
quotes: [
676-
'error', 'double',
677-
],
678-
semi: [
679-
'error', 'never',
680-
],
682+
/* c8 ignore next 8 -- Coercion should work */
683+
...(semver.gte(semver.coerce(ESLint.version) ?? '9.0.0', '9.0.0') ? {} : {
684+
quotes: [
685+
'error', 'double',
686+
],
687+
semi: [
688+
'error', 'never',
689+
],
690+
}),
681691
strict: 0,
682692
},
683693
},

0 commit comments

Comments
 (0)