Skip to content

Commit 18f79ec

Browse files
committedOct 10, 2021
feat: support ESLint 8.x
BREAKING CHANGE: Requires Node@^12.22.0 || ^14.17.0 || >=16.0.0 BREAKING CHANGE: Requires ESLint@^6.0.0 || ^7.0.0 || ^8.0.0
1 parent 5bb9b02 commit 18f79ec

11 files changed

+754
-536
lines changed
 

‎.github/workflows/checks.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ jobs:
3333
strategy:
3434
fail-fast: false
3535
matrix:
36-
node-version: [10.x, 12.x, 13.x, 14.x]
37-
eslint-version: [6, 7]
36+
node-version: [12, 14, 16]
37+
eslint-version: [6, 7, 8]
3838
runs-on: ubuntu-latest
3939

4040
steps:
4141
- uses: actions/checkout@v2
4242
- name: Use Node.js ${{ matrix.node-version }}
43-
uses: actions/setup-node@v2-beta
43+
uses: actions/setup-node@v2
4444
with:
4545
node-version: ${{ matrix.node-version }}
4646
- name: install with eslint v${{matrix.eslint-version }}
@@ -66,9 +66,9 @@ jobs:
6666

6767
steps:
6868
- uses: actions/checkout@v2
69-
- uses: actions/setup-node@v2-beta
69+
- uses: actions/setup-node@v2
7070
with:
71-
node-version: 12.x
71+
node-version: 16
7272
- name: install
7373
run: npm ci
7474
- name: prettier

‎.github/workflows/release.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@v2
17-
- uses: actions/setup-node@v2-beta
17+
- uses: actions/setup-node@v2
1818
with:
19-
node-version: '12.x'
19+
node-version: 16
2020

2121
- uses: actions/cache@v2
2222
with:

‎package-lock.json

+715-484
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+12-12
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
]
8080
},
8181
"dependencies": {
82-
"@typescript-eslint/experimental-utils": "^4.11.1",
82+
"@typescript-eslint/experimental-utils": "^5.0.0-0",
8383
"require-relative": "^0.8.7"
8484
},
8585
"devDependencies": {
@@ -93,25 +93,25 @@
9393
"@semantic-release/changelog": "^5.0.1",
9494
"@semantic-release/git": "^9.0.0",
9595
"@types/dedent": "^0.7.0",
96-
"@types/eslint": "^7.2.6",
96+
"@types/eslint": "^7.28.0",
9797
"@types/jest": "^26.0.19",
9898
"@types/node": "^12.19.11",
9999
"@types/prettier": "^2.1.6",
100100
"@types/require-relative": "^0.8.0",
101-
"@typescript-eslint/eslint-plugin": "^4.11.1",
102-
"@typescript-eslint/parser": "^4.11.1",
101+
"@typescript-eslint/eslint-plugin": "^5.0.0-0",
102+
"@typescript-eslint/parser": "^5.0.0-0",
103103
"babel-jest": "^26.6.3",
104104
"babel-plugin-replace-ts-export-assignment": "^0.0.2",
105105
"dedent": "^0.7.0",
106-
"eslint": "^7.17.0",
107-
"eslint-config-ackama": "^2.0.1",
106+
"eslint": "^8.0.0",
107+
"eslint-config-ackama": "^2.2.0",
108108
"eslint-plugin-eslint-comments": "^3.2.0",
109109
"eslint-plugin-eslint-plugin": "^2.3.0",
110-
"eslint-plugin-import": "^2.22.1",
111-
"eslint-plugin-jest": "^24.1.3",
112-
"eslint-plugin-jest-formatting": "^2.0.0",
110+
"eslint-plugin-import": "^2.24.2",
111+
"eslint-plugin-jest": "^25.0.1",
112+
"eslint-plugin-jest-formatting": "^2.0.1",
113113
"eslint-plugin-node": "^11.1.0",
114-
"eslint-plugin-prettier": "^3.3.0",
114+
"eslint-plugin-prettier": "^3.4.1",
115115
"husky": "^4.3.6",
116116
"jest": "^26.6.3",
117117
"jest-runner-eslint": "^0.10.0",
@@ -124,10 +124,10 @@
124124
"typescript": "^4.1.3"
125125
},
126126
"peerDependencies": {
127-
"eslint": ">=5"
127+
"eslint": "^6.0.0 || ^7.0.0 || ^8.0.0"
128128
},
129129
"engines": {
130-
"node": ">=10"
130+
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
131131
},
132132
"release": {
133133
"plugins": [

‎src/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ESLint from 'eslint';
1+
import { Linter, Rule } from 'eslint';
22
import { readdirSync } from 'fs';
33
import { join, parse } from 'path';
44

@@ -16,7 +16,7 @@ const rules = readdirSync(rulesDir)
1616
);
1717

1818
const allRules = Object.keys(rules).reduce<
19-
Record<string, ESLint.Linter.RuleLevel>
19+
Record<string, Linter.RuleLevel>
2020
>(
2121
(theRules, key) => ({
2222
...theRules,
@@ -25,7 +25,7 @@ const allRules = Object.keys(rules).reduce<
2525
{}
2626
);
2727

28-
interface PluginConfig extends ESLint.Linter.Config {
28+
interface PluginConfig extends Linter.Config {
2929
plugins: ['eslint-config'];
3030
}
3131

@@ -35,7 +35,7 @@ const plugin: {
3535
PluginConfig & Required<Pick<PluginConfig, 'rules'>>
3636
> &
3737
Record<string, PluginConfig>;
38-
rules: Record<string, ESLint.Rule.RuleModule>;
38+
rules: Record<string, Rule.RuleModule>;
3939
} = {
4040
configs: {
4141
'all': {

‎src/rules/no-deprecated-rules.ts

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export = ESLintUtils.RuleCreator(name => name)({
2222
type: 'problem',
2323
docs: {
2424
description: 'Checks for usage of deprecated eslint rules',
25-
category: 'Best Practices',
2625
recommended: 'warn',
2726
suggestion: true
2827
},

‎src/rules/no-invalid-config.ts

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export = ESLintUtils.RuleCreator(name => name)({
2424
type: 'problem',
2525
docs: {
2626
description: 'Checks that the config exported by a file is valid',
27-
category: 'Best Practices',
2827
recommended: 'error'
2928
},
3029
messages: {

‎src/rules/no-unknown-rules.ts

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export = ESLintUtils.RuleCreator(name => name)({
77
type: 'problem',
88
docs: {
99
description: 'Ensures that all rules are known',
10-
category: 'Best Practices',
1110
recommended: 'error'
1211
},
1312
messages: {

‎src/rules/sort-rules.ts

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export = ESLintUtils.RuleCreator(name => name)({
5050
type: 'problem',
5151
docs: {
5252
description: 'Ensures that rules are sorted in a consistent order',
53-
category: 'Best Practices',
5453
recommended: false
5554
},
5655
fixable: 'code',

‎src/rules/utils.ts

+16-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ESLint from 'eslint';
1+
import { CLIEngine, Linter } from 'eslint';
22
import requireRelative from 'require-relative';
33
import { runInNewContext } from 'vm';
44

@@ -32,25 +32,25 @@ const relativeRequire = (name: string): unknown =>
3232
relativeRequire.resolve = (name: string): string =>
3333
requireRelative.resolve(name, process.cwd());
3434

35-
const compileConfigCodeCache = new Map<string, ESLint.Linter.Config>();
35+
const compileConfigCodeCache = new Map<string, Linter.Config>();
3636

37-
const compileConfigCode = (fileCode: string): ESLint.Linter.Config => {
37+
const compileConfigCode = (fileCode: string): Linter.Config => {
3838
return getsertCache(
3939
compileConfigCodeCache,
4040
fileCode,
4141
() =>
4242
(runInNewContext(fileCode, {
4343
module: { exports: {} },
4444
require: relativeRequire
45-
}) ?? {}) as ESLint.Linter.Config,
45+
}) ?? {}) as Linter.Config,
4646
'compileConfigCode'
4747
);
4848
};
4949

50-
const createCliEngineCache = new Map<string, ESLint.CLIEngine>();
50+
const createCliEngineCache = new Map<string, CLIEngine>();
5151

52-
const createCLIEngine = (config: ESLint.Linter.Config): ESLint.CLIEngine => {
53-
const extraConfig: ESLint.Linter.Config = {
52+
const createCLIEngine = (config: Linter.Config): CLIEngine => {
53+
const extraConfig: Linter.Config = {
5454
parserOptions: {
5555
...config.parserOptions,
5656
project: require.resolve('../../tsconfig.fake.json'),
@@ -72,7 +72,7 @@ const createCLIEngine = (config: ESLint.Linter.Config): ESLint.CLIEngine => {
7272
createCliEngineCache,
7373
JSON.stringify(config),
7474
() =>
75-
new ESLint.CLIEngine({
75+
new CLIEngine({
7676
useEslintrc: false,
7777
ignorePath: pathToBlankFile,
7878
ignorePattern: ['!node_modules/*'],
@@ -88,7 +88,7 @@ const createCLIEngine = (config: ESLint.Linter.Config): ESLint.CLIEngine => {
8888
};
8989

9090
interface ConfigInfo {
91-
deprecatedRules: ESLint.CLIEngine.DeprecatedRuleUse[];
91+
deprecatedRules: CLIEngine.DeprecatedRuleUse[];
9292
unknownRules: string[];
9393
errors: ESLintError[];
9494
}
@@ -107,10 +107,7 @@ const ensureArray = <T>(v: T | T[] = []): T[] => (Array.isArray(v) ? v : [v]);
107107
* Merging is done at the top level only, and based on explicit named properties,
108108
* so any additional properties on either config will be lost.
109109
*/
110-
const mergeConfigs = (
111-
a: ESLint.Linter.Config,
112-
b: ESLint.Linter.Config
113-
): ESLint.Linter.Config => ({
110+
const mergeConfigs = (a: Linter.Config, b: Linter.Config): Linter.Config => ({
114111
parser: b.parser ?? a.parser,
115112
parserOptions: { ...a.parserOptions, ...b.parserOptions },
116113
processor: b.processor ?? a.processor,
@@ -126,9 +123,7 @@ const mergeConfigs = (
126123
rules: { ...a.rules, ...b.rules }
127124
});
128125

129-
const extractRelevantConfigs = (
130-
config: ESLint.Linter.Config
131-
): ESLint.Linter.Config[] => [
126+
const extractRelevantConfigs = (config: Linter.Config): Linter.Config[] => [
132127
{ ...config, overrides: [] },
133128
...(config.overrides ?? [])
134129
.map(override =>
@@ -279,9 +274,9 @@ const parseESLintError = (error: Error): ESLintError => {
279274
};
280275

281276
const followErrorPathToConfig = (
282-
config: ESLint.Linter.Config,
277+
config: Linter.Config,
283278
error: ESLintError
284-
): ESLint.Linter.Config => {
279+
): Linter.Config => {
285280
if (!error.path || !config.overrides) {
286281
return config;
287282
}
@@ -296,7 +291,7 @@ const followErrorPathToConfig = (
296291
};
297292

298293
const tryRemoveErrorPointFromConfig = (
299-
config: ESLint.Linter.Config,
294+
config: Linter.Config,
300295
error: ESLintError
301296
): boolean => {
302297
const configToDeleteFrom = followErrorPathToConfig(config, error);
@@ -350,9 +345,7 @@ const tryRemoveErrorPointFromConfig = (
350345
return false;
351346
};
352347

353-
const collectConfigInfoFromESLint = (
354-
config: ESLint.Linter.Config
355-
): ConfigInfo => {
348+
const collectConfigInfoFromESLint = (config: Linter.Config): ConfigInfo => {
356349
const theConfig = { rules: {}, ...config };
357350
const errors: ESLintError[] = [];
358351
let counter = 0;
@@ -406,7 +399,7 @@ const collectConfigInfoCache = new Map<string, ConfigInfo>();
406399
* Info about any `overrides` the `config` might have will be collected and
407400
* merged into the returned info object.
408401
*/
409-
const collectConfigInfo = (config: ESLint.Linter.Config): ConfigInfo => {
402+
const collectConfigInfo = (config: Linter.Config): ConfigInfo => {
410403
return getsertCache(
411404
collectConfigInfoCache,
412405
JSON.stringify(config),

‎test/helpers.ts

-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ export const mockEslintPluginPrettier = (): void => {
8080
type: 'problem',
8181
docs: {
8282
description: 'Fake rule that is deprecated, for use in testing',
83-
category: 'Best Practices',
8483
recommended: 'warn'
8584
},
8685
deprecated: true,
@@ -99,7 +98,6 @@ export const mockEslintPluginPrettier = (): void => {
9998
type: 'problem',
10099
docs: {
101100
description: 'Fake rule that always throws, for use in testing',
102-
category: 'Best Practices',
103101
recommended: 'warn'
104102
},
105103
messages: {},

0 commit comments

Comments
 (0)