Skip to content

Commit 4f21b85

Browse files
committed
build: update to eslint v9
This change adds support for eslint v9. All three example projects have been updated to use the latest eslint, and the root package's dev and peer deps have been updated. In order to make this work with both v9 and older versions, I had to update the parser options helper to adjust the config passed into the `RuleTester`. It was also necessary update jest to a newer version, in order to resolve eslint's use of `node:fs/promises`. Note: the removed test cases are exact duplicates of other tests. v9 fails tests when its determined to be an exact duplicate.
1 parent 05a5e49 commit 4f21b85

21 files changed

+170
-88
lines changed

.flowconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
<PROJECT_ROOT>/lib/.*
44
<PROJECT_ROOT>/docs/.*
55
<PROJECT_ROOT>/reports/.*
6+
<PROJECT_ROOT>/examples/.*
67
[options]
78
suppress_type=$FlowFixMe

.github/workflows/node-4+.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,26 @@ jobs:
2525
matrix:
2626
node-version: ${{ fromJson(needs.matrix.outputs.latest) }}
2727
eslint:
28+
- 9
2829
- 8
2930
- 7
3031
- 6
3132
- 5
3233
- 4
3334
- 3
3435
exclude:
36+
- node-version: 16
37+
eslint: 9
38+
- node-version: 15
39+
eslint: 9
40+
- node-version: 13
41+
eslint: 9
42+
- node-version: 11
43+
eslint: 9
44+
- node-version: 10
45+
eslint: 9
46+
- node-version: 9
47+
eslint: 9
3548
- node-version: 15
3649
eslint: 8
3750
- node-version: 13
@@ -90,7 +103,7 @@ jobs:
90103
steps:
91104
- uses: actions/checkout@v4
92105
with:
93-
fetch-depth: 0
106+
fetch-depth: 0
94107
- uses: ljharb/actions/node/install@main
95108
name: 'nvm install ${{ matrix.node-version }} && npm install'
96109
env:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import assert from 'assert';
2+
3+
export default assert;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import fs from 'fs/promises';
2+
3+
export default fs;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import fs from 'fs';
2+
3+
export default fs;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import path from 'path';
2+
3+
export default path;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import url from 'url';
2+
3+
export default url;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import util from 'util';
2+
3+
export default util;
Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,53 @@
1+
import { version as eslintVersion } from 'eslint/package.json';
2+
import semver from 'semver';
3+
4+
const usingLegacy = semver.major(eslintVersion) < 9;
5+
16
const defaultParserOptions = {
2-
ecmaVersion: 2018,
37
ecmaFeatures: {
48
experimentalObjectRestSpread: true,
59
jsx: true,
610
},
711
};
812

13+
const defaultLegacyParserOptions = {
14+
...defaultParserOptions,
15+
ecmaVersion: 2018,
16+
};
17+
18+
const defaultLanguageOptions = {
19+
ecmaVersion: 'latest',
20+
parserOptions: {
21+
...defaultParserOptions,
22+
},
23+
};
24+
925
export default function parserOptionsMapper({
1026
code,
1127
errors,
1228
options = [],
13-
parserOptions = {},
14-
settings,
29+
languageOptions = {},
30+
settings = {},
1531
}) {
16-
return {
17-
code,
18-
errors,
19-
options,
20-
parserOptions: {
21-
...defaultParserOptions,
22-
...parserOptions,
23-
},
24-
settings,
25-
};
32+
return usingLegacy
33+
? {
34+
code,
35+
errors,
36+
options,
37+
parserOptions: {
38+
...defaultLegacyParserOptions,
39+
...languageOptions,
40+
},
41+
settings,
42+
}
43+
: {
44+
code,
45+
errors,
46+
options,
47+
languageOptions: {
48+
...defaultLanguageOptions,
49+
...languageOptions,
50+
},
51+
settings,
52+
};
2653
}

__tests__/src/rules/anchor-is-valid-test.js

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,9 @@ ruleTester.run('anchor-is-valid', rule, {
272272
options: noHrefAspect,
273273
},
274274

275-
// CUSTOM COMPONENTS AND SPECIALLINK AND ASPECT
275+
// CUSTOM COMPONENTS AND SPECIAL LINK AND ASPECT
276276
{ code: '<Anchor hrefLeft={undefined} />', options: componentsAndSpecialLinkAndInvalidHrefAspect },
277277
{ code: '<Anchor hrefLeft={null} />', options: componentsAndSpecialLinkAndInvalidHrefAspect },
278-
{ code: '<Anchor hrefLeft={undefined} />', options: componentsAndSpecialLinkAndInvalidHrefAspect },
279-
{ code: '<Anchor hrefLeft={null} />', options: componentsAndSpecialLinkAndInvalidHrefAspect },
280-
{ code: '<Anchor hrefLeft={undefined} />', options: componentsAndSpecialLinkAndInvalidHrefAspect },
281-
{ code: '<Anchor hrefLeft={null} />', options: componentsAndSpecialLinkAndInvalidHrefAspect },
282-
283278
)).map(parserOptionsMapper),
284279
invalid: parsers.all([].concat(
285280
// DEFAULT ELEMENT 'a' TESTS
@@ -372,7 +367,7 @@ ruleTester.run('anchor-is-valid', rule, {
372367
options: specialLink,
373368
},
374369

375-
// CUSTOM BOTH COMPONENTS AND SPECIALLINK TESTS
370+
// CUSTOM BOTH COMPONENTS AND SPECIAL LINK TESTS
376371
// NO HREF
377372
{ code: '<Anchor Anchor={undefined} />', errors: [noHrefexpectedError], options: componentsAndSpecialLink },
378373
{ code: '<Anchor hrefLeft={null} />', errors: [noHrefexpectedError], options: componentsAndSpecialLink },
@@ -522,27 +517,7 @@ ruleTester.run('anchor-is-valid', rule, {
522517
errors: [invalidHrefexpectedError],
523518
},
524519

525-
// CUSTOM COMPONENTS AND SPECIALLINK AND ASPECT
526-
{
527-
code: '<Anchor hrefLeft={undefined} />',
528-
options: componentsAndSpecialLinkAndNoHrefAspect,
529-
errors: [noHrefexpectedError],
530-
},
531-
{
532-
code: '<Anchor hrefLeft={null} />',
533-
options: componentsAndSpecialLinkAndNoHrefAspect,
534-
errors: [noHrefexpectedError],
535-
},
536-
{
537-
code: '<Anchor hrefLeft={undefined} />',
538-
options: componentsAndSpecialLinkAndNoHrefAspect,
539-
errors: [noHrefexpectedError],
540-
},
541-
{
542-
code: '<Anchor hrefLeft={null} />',
543-
options: componentsAndSpecialLinkAndNoHrefAspect,
544-
errors: [noHrefexpectedError],
545-
},
520+
// CUSTOM COMPONENTS AND SPECIAL LINK AND ASPECT
546521
{
547522
code: '<Anchor hrefLeft={undefined} />',
548523
options: componentsAndSpecialLinkAndNoHrefAspect,

0 commit comments

Comments
 (0)