Skip to content

Commit

Permalink
Update ESLint to v9, drop support for Node.js v16 (#2250)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored Apr 9, 2024
1 parent 29025d9 commit 598f57b
Show file tree
Hide file tree
Showing 48 changed files with 615 additions and 664 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@ jobs:
matrix:
node-version:
- 20
- 16
- 18
os:
- ubuntu-latest
- windows-latest
include:
- os: ubuntu-latest
node-version: 18
# Even numbers of node-version
# include:
# - os: ubuntu-latest
# node-version: 18
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm install --legacy-peer-deps
- run: npx ava
lint-test:
runs-on: ${{ matrix.os }}
Expand All @@ -43,7 +44,7 @@ jobs:
with:
# Locked due to the difference of `zlib.gzipSync()` between Node.js versions
node-version: 20
- run: npm install
- run: npm install --legacy-peer-deps
- run: npm run lint
- run: npx del-cli test/snapshots --verbose
# Force update snapshots, https://github.com/avajs/ava/discussions/2754
Expand All @@ -61,7 +62,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm install
- run: npm install --legacy-peer-deps
- run: npm run run-rules-on-codebase
integration:
name: Integration test (${{ matrix.group }})
Expand All @@ -84,5 +85,5 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm install
- run: npm install --legacy-peer-deps
- run: npm run integration -- --group ${{ matrix.group }}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"dependencies": {
"@babel/helper-validator-identifier": "^7.22.20",
"@eslint-community/eslint-utils": "^4.4.0",
"@eslint/eslintrc": "^2.1.4",
"@eslint/eslintrc": "^3.0.0",
"ci-info": "^4.0.0",
"clean-regexp": "^1.0.0",
"core-js-compat": "^3.34.0",
Expand All @@ -69,20 +69,21 @@
"devDependencies": {
"@babel/code-frame": "^7.23.5",
"@babel/core": "^7.23.6",
"@babel/eslint-parser": "^7.23.3",
"@babel/eslint-parser": "^7.24.1",
"@lubien/fixture-beta-package": "^1.0.0-beta.1",
"@typescript-eslint/parser": "^7.5.0",
"ava": "^6.0.1",
"c8": "^8.0.1",
"chalk": "^5.3.0",
"enquirer": "^2.4.1",
"eslint": "^8.56.0",
"eslint": "^9.0.0",
"eslint-ava-rule-tester": "^5.0.1",
"eslint-doc-generator": "^1.7.0",
"eslint-plugin-eslint-plugin": "^5.2.1",
"eslint-plugin-internal-rules": "file:./scripts/internal-rules/",
"eslint-remote-tester": "^3.0.1",
"eslint-remote-tester-repositories": "^1.0.1",
"espree": "^10.0.0",
"execa": "^8.0.1",
"listr": "^0.14.3",
"lodash-es": "^4.17.21",
Expand Down
23 changes: 4 additions & 19 deletions test/better-regex.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {createRequire} from 'node:module';
import {getTester} from './utils/test.mjs';
import {getTester, parsers} from './utils/test.mjs';

const {test} = getTester(import.meta);
const require = createRequire(import.meta.url);

const MESSAGE_ID = 'better-regex';

Expand Down Expand Up @@ -220,21 +218,6 @@ test({
errors: createError('[0-9]', '\\d'),
output: 'const foo = new RegExp(\'\\\\d\', \'ig\')',
},
{
code: 'const foo = new RegExp(/[0-9]/)',
errors: createError('/[0-9]/', '/\\d/'),
output: 'const foo = new RegExp(/\\d/)',
},
{
code: 'const foo = new RegExp(/[0-9]/, \'ig\')',
errors: createError('/[0-9]/', '/\\d/'),
output: 'const foo = new RegExp(/\\d/, \'ig\')',
},
{
code: 'const foo = new RegExp(/[0-9]/)',
errors: createError('/[0-9]/', '/\\d/'),
output: 'const foo = new RegExp(/\\d/)',
},
{
code: 'const foo = new RegExp(/[0-9]/, \'ig\')',
errors: createError('/[0-9]/', '/\\d/'),
Expand Down Expand Up @@ -310,7 +293,9 @@ test({
message: 'Problem parsing /(/: \n\n/(/\n ^\nUnexpected token: "/" at 1:2.',
},
],
parser: require.resolve('@typescript-eslint/parser'),
languageOptions: {
parser: parsers.typescript,
},
},

// Not fixable
Expand Down
15 changes: 8 additions & 7 deletions test/catch-error-name.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ function invalidTestCase(options) {

test({
valid: [
'try {} catch (error) {}',
{
code: 'try {} catch (err) {}',
options: [{name: 'err'}],
Expand Down Expand Up @@ -900,12 +899,14 @@ test.typescript({

test.babel({
testerOptions: {
parserOptions: {
babelOptions: {
parserOpts: {
plugins: [
['decorators', {decoratorsBeforeExport: true}],
],
languageOptions: {
parserOptions: {
babelOptions: {
parserOpts: {
plugins: [
['decorators', {decoratorsBeforeExport: true}],
],
},
},
},
},
Expand Down
6 changes: 3 additions & 3 deletions test/consistent-destructuring.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ test({
b
}
} = foo;
console.log(foo.a.c);
console.log(foo.a.c); // 2
`,
errors: [{
message: 'Use destructured variables over properties.',
Expand All @@ -453,15 +453,15 @@ test({
{
code: outdent`
const {a} = foo;
console.log(foo.a);
console.log(foo.a); // 2
`,
errors: [{
message: 'Use destructured variables over properties.',
suggestions: [{
desc: 'Replace `foo.a` with destructured property `a`.',
output: outdent`
const {a} = foo;
console.log(a);
console.log(a); // 2
`,
}],
}],
Expand Down
18 changes: 7 additions & 11 deletions test/consistent-function-scoping.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ const createError = (functionNameWithKind, loc) => ({

test({
testerOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true,
languageOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
},
Expand Down Expand Up @@ -473,12 +475,6 @@ test({
`,
errors: [createError('arrow function \'doBar\'')],
},
{
code: outdent`
const doFoo = () => bar => bar;
`,
errors: [createError('arrow function')],
},
// `this`
{
code: outdent`
Expand Down Expand Up @@ -628,9 +624,9 @@ test({
},
// Actual message
{
code: 'function foo() { async function* bar() {} }',
code: 'function foo() { async function* baz() {} }',
errors: [{
message: 'Move async generator function \'bar\' to the outer scope.',
message: 'Move async generator function \'baz\' to the outer scope.',
}],
},
// React Hooks
Expand Down
29 changes: 15 additions & 14 deletions test/empty-brace-spaces.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ const cases = [
'switch (foo) {case bar: {/* */}}',
'switch (foo) {default: {/* */}}',
'try {/* */} catch(foo){}',
'try {} catch(foo){/* */}',
'try {} catch(bar){/* */}',
'try {} catch(foo){} finally {/* */}',
'do {/* */} while (foo)',
'while (foo){/* */}',
'foo = () => {/* */}',
'foo = function (){/* */}',
'function foo(){/* */}',
'foo = {/* */}',
'class Foo {bar() {/* */}}',
'foo = class {bar() {/* */}}',
Expand All @@ -49,11 +48,11 @@ test({
].flatMap(body => allCases.map(code => code.replace(SPACES_PLACEHOLDER, body))),
// Not empty
...cases.map(code => code.replace(SPACES_PLACEHOLDER, 'unicorn')),
...classBodyCases.map(code => code.replace(SPACES_PLACEHOLDER, 'bar() {}')),
...classBodyCases.map(code => code.replace(SPACES_PLACEHOLDER, 'baz() {}')),
// `with`
{
code: 'with (foo) {}',
parserOptions: {ecmaVersion: 5, sourceType: 'script'},
languageOptions: {ecmaVersion: 5, sourceType: 'script'},
},
// We don't check these cases
...ignoredCases.map(code => code.replace(SPACES_PLACEHOLDER, ' ')),
Expand All @@ -75,7 +74,7 @@ test({
code: 'with (foo) { }',
output: 'with (foo) {}',
errors: 1,
parserOptions: {ecmaVersion: 5, sourceType: 'script'},
languageOptions: {ecmaVersion: 5, sourceType: 'script'},
},
],
});
Expand All @@ -94,9 +93,11 @@ test.snapshot({
});

const enableBabelPlugins = plugins => ({
babelOptions: {
parserOpts: {
plugins,
parserOptions: {
babelOptions: {
parserOpts: {
plugins,
},
},
},
});
Expand All @@ -110,19 +111,19 @@ test.babel({
};
`,
output: 'const foo = do {};',
parserOptions: enableBabelPlugin('doExpressions'),
languageOptions: enableBabelPlugin('doExpressions'),
errors: 1,
},
{
code: 'const record = #{ };',
output: 'const record = #{};',
parserOptions: enableBabelPlugin(['recordAndTuple', {syntaxType: 'hash'}]),
languageOptions: enableBabelPlugin(['recordAndTuple', {syntaxType: 'hash'}]),
errors: 1,
},
{
code: 'const record = {| |};',
output: 'const record = {||};',
parserOptions: enableBabelPlugin(['recordAndTuple', {syntaxType: 'bar'}]),
languageOptions: enableBabelPlugin(['recordAndTuple', {syntaxType: 'bar'}]),
errors: 1,
},
{
Expand All @@ -137,14 +138,14 @@ test.babel({
static {}
}
`,
parserOptions: enableBabelPlugin('classStaticBlock'),
languageOptions: enableBabelPlugin('classStaticBlock'),
errors: 1,
},
// ESLint can't parse this now
// {
// code: 'const foo = module { };',
// output: 'const foo = module {};',
// parserOptions: enableBabelPlugin('moduleBlocks'),
// languageOptions: enableBabelPlugin('moduleBlocks'),
// errors: 1
// },
{
Expand All @@ -153,7 +154,7 @@ test.babel({
};
`,
output: 'const foo = async do {};',
parserOptions: enableBabelPlugins(['doExpressions', 'asyncDoExpressions']),
languageOptions: enableBabelPlugins(['doExpressions', 'asyncDoExpressions']),
errors: 1,
},
],
Expand Down
Loading

0 comments on commit 598f57b

Please sign in to comment.