Skip to content

Commit 67c403b

Browse files
committed
Support for ESLint v8
1 parent 8be2ec2 commit 67c403b

File tree

7 files changed

+127
-67
lines changed

7 files changed

+127
-67
lines changed

.github/workflows/node-4+.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
matrix:
2727
node-version: ${{ fromJson(needs.matrix.outputs.latest) }}
2828
eslint:
29+
- ^8.0.0-0
2930
- 7
3031
- 6
3132
- 5
@@ -39,24 +40,44 @@ jobs:
3940
env:
4041
TS_PARSER: 2
4142
exclude:
43+
- node-version: 15
44+
eslint: ^8.0.0-0
45+
- node-version: 13
46+
eslint: ^8.0.0-0
47+
- node-version: 11
48+
eslint: ^8.0.0-0
49+
- node-version: 10
50+
eslint: ^8.0.0-0
51+
- node-version: 9
52+
eslint: ^8.0.0-0
4253
- node-version: 9
4354
eslint: 7
55+
- node-version: 8
56+
eslint: ^8.0.0-0
4457
- node-version: 8
4558
eslint: 7
59+
- node-version: 7
60+
eslint: ^8.0.0-0
4661
- node-version: 7
4762
eslint: 7
4863
- node-version: 7
4964
eslint: 6
65+
- node-version: 6
66+
eslint: ^8.0.0-0
5067
- node-version: 6
5168
eslint: 7
5269
- node-version: 6
5370
eslint: 6
71+
- node-version: 5
72+
eslint: ^8.0.0-0
5473
- node-version: 5
5574
eslint: 7
5675
- node-version: 5
5776
eslint: 6
5877
- node-version: 5
5978
eslint: 5
79+
- node-version: 4
80+
eslint: ^8.0.0-0
6081
- node-version: 4
6182
eslint: 7
6283
- node-version: 4

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@
6969
"babel-register": "^6.26.0",
7070
"babylon": "^6.18.0",
7171
"chai": "^4.3.4",
72+
"chai-as-promised": "^7.1.1",
7273
"coveralls": "^3.1.0",
7374
"cross-env": "^4.0.0",
74-
"eslint": "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0",
75+
"escope": "^3.6.0",
76+
"eslint": "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8.0.0-0",
7577
"eslint-import-resolver-node": "file:./resolvers/node",
7678
"eslint-import-resolver-typescript": "^1.0.2 || ^1.1.1",
7779
"eslint-import-resolver-webpack": "file:./resolvers/webpack",

src/rules/no-unused-modules.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,17 @@ import includes from 'array-includes';
1515

1616
// eslint/lib/util/glob-util has been moved to eslint/lib/util/glob-utils with version 5.3
1717
// and has been moved to eslint/lib/cli-engine/file-enumerator in version 6
18+
// and has been moved to eslint/use-at-your-own-risk in version 8
1819
let listFilesToProcess;
1920
try {
20-
const FileEnumerator = require('eslint/lib/cli-engine/file-enumerator').FileEnumerator;
21+
// eslint/lib/cli-engine/file-enumerator has been moved to eslint/use-at-your-own-risk
22+
// in version 8
23+
let FileEnumerator;
24+
try {
25+
FileEnumerator = require('eslint/use-at-your-own-risk').FileEnumerator;
26+
} catch (e) {
27+
FileEnumerator = require('eslint/lib/cli-engine/file-enumerator').FileEnumerator;
28+
}
2129
listFilesToProcess = function (src, extensions) {
2230
const e = new FileEnumerator({
2331
extensions: extensions,
@@ -228,7 +236,7 @@ const prepareImportsAndExports = (srcFiles, context) => {
228236
}
229237
const localImport = imports.get(key) || new Set();
230238
value.declarations.forEach(({ importedSpecifiers }) =>
231-
importedSpecifiers.forEach(specifier => localImport.add(specifier))
239+
importedSpecifiers.forEach(specifier => localImport.add(specifier)),
232240
);
233241
imports.set(key, localImport);
234242
});
@@ -544,13 +552,13 @@ module.exports = {
544552
if (exportStatement.whereUsed.size < 1) {
545553
context.report(
546554
node,
547-
`exported declaration '${value}' not used within other modules`
555+
`exported declaration '${value}' not used within other modules`,
548556
);
549557
}
550558
} else {
551559
context.report(
552560
node,
553-
`exported declaration '${value}' not used within other modules`
561+
`exported declaration '${value}' not used within other modules`,
554562
);
555563
}
556564
};

tests/dep-time-travel.sh

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,23 @@ export NPM_CONFIG_LEGACY_PEER_DEPS=true
88

99
npm install --no-save "eslint@${ESLINT_VERSION}" --ignore-scripts
1010

11-
# completely remove the new TypeScript parser for ESLint < v5
12-
if [[ "$ESLINT_VERSION" -lt "5" ]]; then
13-
echo "Removing @typescript-eslint/parser..."
14-
npm uninstall --no-save @typescript-eslint/parser
15-
fi
16-
17-
# use these alternate TypeScript dependencies for ESLint < v4
18-
if [[ "$ESLINT_VERSION" -lt "4" ]]; then
19-
echo "Downgrading babel-eslint..."
20-
npm i --no-save babel-eslint@8.0.3
21-
22-
echo "Downgrading TypeScript dependencies..."
23-
npm i --no-save typescript-eslint-parser@15 typescript@2.8.1
11+
re="^[0-9]+$"
12+
13+
if [[ "$ESLINT_VERSION" =~ $re ]] ; then
14+
# completely remove the new TypeScript parser for ESLint < v5
15+
if [[ "$ESLINT_VERSION" -lt "5" ]]; then
16+
echo "Removing @typescript-eslint/parser..."
17+
npm uninstall --no-save @typescript-eslint/parser
18+
fi
19+
20+
# use these alternate TypeScript dependencies for ESLint < v4
21+
if [[ "$ESLINT_VERSION" -lt "4" ]]; then
22+
echo "Downgrading babel-eslint..."
23+
npm i --no-save babel-eslint@8.0.3
24+
25+
echo "Downgrading TypeScript dependencies..."
26+
npm i --no-save typescript-eslint-parser@15 typescript@2.8.1
27+
fi
2428
fi
2529

2630
# typescript-eslint-parser 1.1.1+ is not compatible with node 6

tests/src/cli.js

Lines changed: 72 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,82 +3,107 @@
33
*/
44
import path from 'path';
55

6-
import { expect } from 'chai';
7-
import { CLIEngine } from 'eslint';
6+
import { expect, use } from 'chai';
7+
import chaiAsPromised from 'chai-as-promised';
8+
import { CLIEngine, ESLint as ESLintClass } from 'eslint';
89
import eslintPkg from 'eslint/package.json';
910
import semver from 'semver';
11+
import * as importPlugin from '../../src/index';
12+
13+
use(chaiAsPromised);
14+
15+
const ESLint = ESLintClass || class {
16+
constructor(options) {
17+
options = Object.assign({},options);
18+
const overrideConfig = options.overrideConfig;
19+
delete options.overrideConfig;
20+
const overrideConfigFile = options.overrideConfigFile;
21+
delete options.overrideConfigFile;
22+
const pluginsMap = options.plugins;
23+
delete options.plugins;
24+
this.engine = new CLIEngine(Object.assign(options, overrideConfig, overrideConfigFile ? { configFile:overrideConfigFile }: {}));
25+
26+
for (const [name, plugin] of Object.entries(pluginsMap || {})) {
27+
this.engine.addPlugin(name, plugin);
28+
}
29+
}
30+
lintFiles(params) {
31+
const result = this.engine.executeOnFiles(params);
32+
return Promise.resolve(result.results);
33+
}
34+
};
1035

1136
describe('CLI regression tests', function () {
1237
describe('issue #210', function () {
13-
let cli;
38+
let eslint;
1439
before(function () {
15-
cli = new CLIEngine({
40+
eslint = new ESLint({
1641
useEslintrc: false,
17-
configFile: './tests/files/issue210.config.js',
42+
overrideConfigFile: './tests/files/issue210.config.js',
1843
rulePaths: ['./src/rules'],
19-
rules: {
20-
'named': 2,
44+
overrideConfig: {
45+
rules: {
46+
'named': 2,
47+
},
2148
},
49+
plugins: { 'eslint-plugin-import': importPlugin },
2250
});
2351
});
2452
it("doesn't throw an error on gratuitous, erroneous self-reference", function () {
25-
expect(() => cli.executeOnFiles(['./tests/files/issue210.js'])).not.to.throw();
53+
return expect(eslint.lintFiles(['./tests/files/issue210.js'])).not.to.rejected;
2654
});
2755
});
2856

2957
describe('issue #1645', function () {
30-
let cli;
58+
let eslint;
3159
beforeEach(function () {
3260
if (semver.satisfies(eslintPkg.version, '< 6')) {
3361
this.skip();
3462
} else {
35-
cli = new CLIEngine({
63+
eslint = new ESLint({
3664
useEslintrc: false,
37-
configFile: './tests/files/just-json-files/.eslintrc.json',
65+
overrideConfigFile: './tests/files/just-json-files/.eslintrc.json',
3866
rulePaths: ['./src/rules'],
3967
ignore: false,
68+
plugins: { 'eslint-plugin-import': importPlugin },
4069
});
4170
}
4271
});
4372

4473
it('throws an error on invalid JSON', () => {
4574
const invalidJSON = './tests/files/just-json-files/invalid.json';
46-
const results = cli.executeOnFiles([invalidJSON]);
47-
expect(results).to.eql({
48-
results: [
49-
{
50-
filePath: path.resolve(invalidJSON),
51-
messages: [
52-
{
53-
column: 2,
54-
endColumn: 3,
55-
endLine: 1,
56-
line: 1,
57-
message: 'Expected a JSON object, array or literal.',
58-
nodeType: results.results[0].messages[0].nodeType, // we don't care about this one
59-
ruleId: 'json/*',
60-
severity: 2,
61-
source: results.results[0].messages[0].source, // NewLine-characters might differ depending on git-settings
62-
},
63-
],
64-
errorCount: 1,
65-
...(semver.satisfies(eslintPkg.version, '>= 7.32') && {
66-
fatalErrorCount: 0,
67-
}),
68-
warningCount: 0,
69-
fixableErrorCount: 0,
70-
fixableWarningCount: 0,
71-
source: results.results[0].source, // NewLine-characters might differ depending on git-settings
72-
},
73-
],
74-
...(semver.satisfies(eslintPkg.version, '>= 7.32') && {
75-
fatalErrorCount: 0,
76-
}),
77-
errorCount: 1,
78-
warningCount: 0,
79-
fixableErrorCount: 0,
80-
fixableWarningCount: 0,
81-
usedDeprecatedRules: results.usedDeprecatedRules, // we don't care about this one
75+
return eslint.lintFiles([invalidJSON]).then(results => {
76+
expect(results).to.eql(
77+
[
78+
{
79+
filePath: path.resolve(invalidJSON),
80+
messages: [
81+
{
82+
column: 2,
83+
endColumn: 3,
84+
endLine: 1,
85+
line: 1,
86+
message: 'Expected a JSON object, array or literal.',
87+
nodeType: results[0].messages[0].nodeType, // we don't care about this one
88+
ruleId: 'json/*',
89+
severity: 2,
90+
source: results[0].messages[0].source, // NewLine-characters might differ depending on git-settings
91+
},
92+
],
93+
errorCount: 1,
94+
...(semver.satisfies(eslintPkg.version, '>= 7.32 || ^8.0.0-0') && {
95+
fatalErrorCount: 0,
96+
}),
97+
warningCount: 0,
98+
fixableErrorCount: 0,
99+
fixableWarningCount: 0,
100+
source: results[0].source, // NewLine-characters might differ depending on git-settings
101+
...(semver.satisfies(eslintPkg.version, '>= 7.0.0') && {
102+
usedDeprecatedRules: results[0].usedDeprecatedRules, // we don't care about this one
103+
}),
104+
},
105+
],
106+
);
82107
});
83108
});
84109
});

tests/src/rules/no-amd.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { RuleTester } from 'eslint';
22
import eslintPkg from 'eslint/package.json';
33
import semver from 'semver';
44

5-
const ruleTester = new RuleTester();
5+
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2015, sourceType: 'module' } });
66

77
ruleTester.run('no-amd', require('rules/no-amd'), {
88
valid: [

tests/src/rules/no-commonjs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import semver from 'semver';
55
const EXPORT_MESSAGE = 'Expected "export" or "export default"';
66
const IMPORT_MESSAGE = 'Expected "import" instead of "require()"';
77

8-
const ruleTester = new RuleTester();
8+
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2015, sourceType: 'module' } });
99

1010
ruleTester.run('no-commonjs', require('rules/no-commonjs'), {
1111
valid: [

0 commit comments

Comments
 (0)