Skip to content

Commit 07de720

Browse files
jeddy3ybiquitous
andauthored
Add support for ESLint 9.x (#298)
* Add support for ESLint 9.x * Revert disable comment change * Update package.json Co-authored-by: Masafumi Koba <[email protected]> * Update jest.js Co-authored-by: Masafumi Koba <[email protected]> * Remove eslint/js package * Fix syntax error * Remove support less than node 18.18 * Document flat config examples * Document changes * Update README.md Co-authored-by: Masafumi Koba <[email protected]> * Update eslint.config.js Co-authored-by: Masafumi Koba <[email protected]> * Add exports * Revert adding jest to local config --------- Co-authored-by: Masafumi Koba <[email protected]>
1 parent 3419143 commit 07de720

11 files changed

+1865
-2487
lines changed

.eslintrc.js

-19
This file was deleted.

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Head
4+
5+
- Removed: Node.js less than 18.18 support
6+
- Removed: ESLint 8.x support
7+
- Added: ESLint 9.x support
8+
39
## 22.0.0
410

511
- Removed: `no-confusing-arrow` because of the deprecation of formatting rules.

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ $ npm install eslint-config-stylelint --save-dev
1717

1818
Add this to your ESLint config:
1919

20-
```json
21-
{
22-
"extends": ["stylelint"]
23-
}
20+
```js
21+
import stylelintConfig from "eslint-config-stylelint";
22+
23+
export default [...stylelintConfig];
2424
```
2525

2626
### For Jest
@@ -33,11 +33,11 @@ $ npm install eslint-plugin-jest --save-dev
3333

3434
Then, update your config:
3535

36-
```diff json
37-
{
38-
- "extends": ["stylelint"]
39-
+ "extends": ["stylelint", "stylelint/jest"]
40-
}
36+
```js
37+
import stylelintConfig from "eslint-config-stylelint";
38+
import stylelintJestConfig from "eslint-config-stylelint/jest";
39+
40+
export default [...stylelintConfig, ...stylelintJestConfig];
4141
```
4242

4343
## [Changelog](CHANGELOG.md)

__tests__/helper.js

-7
This file was deleted.

__tests__/index.test.js

+1-11
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,7 @@ const assert = require('node:assert/strict');
66

77
const { ESLint } = require('eslint');
88

9-
const config = require('../index');
10-
const { isObject } = require('./helper');
11-
12-
const newESLint = () => new ESLint({ baseConfig: config, useEslintrc: false, fix: true });
13-
14-
test('basic properties of config', () => {
15-
assert(isObject(config.parserOptions));
16-
assert(isObject(config.env));
17-
assert(isObject(config.rules));
18-
assert(Array.isArray(config.extends));
19-
});
9+
const newESLint = () => new ESLint({ fix: true });
2010

2111
test('load config in ESLint to validate all rule syntax is correct', async () => {
2212
const results = await newESLint().lintText('var foo\n');

__tests__/jest.test.js

+7-10
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,17 @@ const assert = require('node:assert/strict');
77
const { ESLint } = require('eslint');
88

99
const config = require('../jest');
10-
const { isObject } = require('./helper');
11-
12-
test('basic properties of jest config', () => {
13-
assert(isObject(config.extends));
14-
});
1510

1611
test('load jest config in ESLint to validate all rule syntax is correct', async () => {
17-
const baseConfig = {
12+
const baseConfig = [
1813
...config,
19-
settings: {
20-
jest: { version: 27 },
14+
{
15+
settings: {
16+
jest: { version: 27 },
17+
},
2118
},
22-
};
23-
const eslint = new ESLint({ baseConfig, useEslintrc: false });
19+
];
20+
const eslint = new ESLint({ baseConfig });
2421
const results = await eslint.lintText('test("foo");');
2522

2623
assert(results);

eslint.config.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
const config = require('./index.js');
4+
5+
module.exports = [
6+
...config,
7+
{
8+
// TODO: Keep backward compatibility with CommonJS. We may delete after ESM migration.
9+
languageOptions: {
10+
globals: {
11+
module: true,
12+
require: true,
13+
},
14+
},
15+
},
16+
];

index.js

+122-116
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,130 @@
11
'use strict';
22

3-
module.exports = {
4-
parserOptions: {
5-
ecmaVersion: 2023,
6-
sourceType: 'module',
7-
},
8-
env: {
9-
es6: true,
10-
node: true,
11-
},
12-
extends: [
13-
// `prettier` must be last.
14-
'eslint:recommended',
15-
'plugin:n/recommended',
16-
'plugin:regexp/recommended',
17-
'prettier',
18-
],
19-
plugins: ['@stylistic/js'],
20-
rules: {
21-
'array-callback-return': 'error',
22-
'dot-notation': 'error',
23-
eqeqeq: ['error', 'smart'],
24-
'func-name-matching': 'error',
25-
'func-names': ['error', 'as-needed'],
26-
'guard-for-in': 'error',
27-
'no-console': [
28-
'error',
29-
{
30-
allow: ['warn', 'error'],
31-
},
32-
],
33-
'no-else-return': [
34-
'error',
35-
{
36-
allowElseIf: false,
37-
},
38-
],
39-
'no-implicit-coercion': 'error',
40-
'no-lonely-if': 'error',
41-
'no-shadow': 'error',
42-
'no-unneeded-ternary': 'error',
43-
'no-unused-vars': [
44-
'error',
45-
{
46-
ignoreRestSiblings: true,
47-
},
48-
],
49-
'no-use-before-define': ['error', 'nofunc'],
50-
'no-useless-return': 'error',
51-
'no-var': 'error',
52-
'object-shorthand': 'error',
53-
'one-var': ['error', 'never'],
54-
'operator-assignment': 'error',
55-
'prefer-arrow-callback': 'error',
56-
'prefer-object-spread': 'error',
57-
'prefer-regex-literals': 'error',
58-
'prefer-rest-params': 'error',
59-
'prefer-spread': 'error',
60-
'prefer-template': 'error',
61-
'sort-imports': ['error', { allowSeparatedGroups: true }],
3+
const globals = require('globals');
4+
const js = require('@eslint/js'); // eslint-disable-line n/no-extraneous-require
5+
const nPlugin = require('eslint-plugin-n');
6+
const regexpPlugin = require('eslint-plugin-regexp');
7+
const stylisticPlugin = require('@stylistic/eslint-plugin');
628

63-
// Migrated from the deprecated built-in 'padding-line-between-statements'
64-
'@stylistic/js/padding-line-between-statements': [
65-
'error',
66-
// Require blank lines after all directive prologues (e. g. 'use strict')
67-
{
68-
blankLine: 'always',
69-
prev: 'directive',
70-
next: '*',
71-
},
72-
// Disallow blank lines between all directive prologues (e. g. 'use strict')
73-
{
74-
blankLine: 'never',
75-
prev: 'directive',
76-
next: 'directive',
77-
},
78-
// Require blank lines after every sequence of variable declarations
79-
{
80-
blankLine: 'always',
81-
prev: ['const', 'let', 'var'],
82-
next: '*',
83-
},
84-
// Blank lines could be between variable declarations
85-
{
86-
blankLine: 'any',
87-
prev: ['const', 'let', 'var'],
88-
next: ['const', 'let', 'var'],
89-
},
90-
// Require blank lines before all return statements
91-
{
92-
blankLine: 'always',
93-
prev: '*',
94-
next: 'return',
95-
},
96-
// Require blank lines before and after all following statements
97-
{
98-
blankLine: 'always',
99-
prev: '*',
100-
next: ['for', 'function', 'if', 'switch', 'try'],
101-
},
102-
{
103-
blankLine: 'always',
104-
prev: ['for', 'function', 'if', 'switch', 'try'],
105-
next: '*',
9+
module.exports = [
10+
js.configs.recommended,
11+
nPlugin.configs['flat/recommended-script'],
12+
regexpPlugin.configs['flat/recommended'],
13+
{
14+
plugins: {
15+
'@stylistic': stylisticPlugin,
16+
},
17+
languageOptions: {
18+
ecmaVersion: 2023,
19+
sourceType: 'module',
20+
globals: {
21+
...globals.node,
10622
},
107-
],
23+
},
24+
linterOptions: {
25+
reportUnusedDisableDirectives: 'error',
26+
},
27+
rules: {
28+
'array-callback-return': 'error',
29+
'dot-notation': 'error',
30+
eqeqeq: ['error', 'smart'],
31+
'func-name-matching': 'error',
32+
'func-names': ['error', 'as-needed'],
33+
'guard-for-in': 'error',
34+
'no-console': [
35+
'error',
36+
{
37+
allow: ['warn', 'error'],
38+
},
39+
],
40+
'no-else-return': [
41+
'error',
42+
{
43+
allowElseIf: false,
44+
},
45+
],
46+
'no-implicit-coercion': 'error',
47+
'no-lonely-if': 'error',
48+
'no-shadow': 'error',
49+
'no-unneeded-ternary': 'error',
50+
'no-unused-vars': [
51+
'error',
52+
{
53+
ignoreRestSiblings: true,
54+
},
55+
],
56+
'no-use-before-define': ['error', 'nofunc'],
57+
'no-useless-return': 'error',
58+
'no-var': 'error',
59+
'object-shorthand': 'error',
60+
'one-var': ['error', 'never'],
61+
'operator-assignment': 'error',
62+
'prefer-arrow-callback': 'error',
63+
'prefer-object-spread': 'error',
64+
'prefer-regex-literals': 'error',
65+
'prefer-rest-params': 'error',
66+
'prefer-spread': 'error',
67+
'prefer-template': 'error',
68+
'sort-imports': ['error', { allowSeparatedGroups: true }],
10869

109-
// Avoid a global variable unique to Node.js.
110-
'n/prefer-global/process': ['error', 'never'],
70+
// Migrated from the deprecated built-in 'padding-line-between-statements'
71+
'@stylistic/padding-line-between-statements': [
72+
'error',
73+
// Require blank lines after all directive prologues (e. g. 'use strict')
74+
{
75+
blankLine: 'always',
76+
prev: 'directive',
77+
next: '*',
78+
},
79+
// Disallow blank lines between all directive prologues (e. g. 'use strict')
80+
{
81+
blankLine: 'never',
82+
prev: 'directive',
83+
next: 'directive',
84+
},
85+
// Require blank lines after every sequence of variable declarations
86+
{
87+
blankLine: 'always',
88+
prev: ['const', 'let', 'var'],
89+
next: '*',
90+
},
91+
// Blank lines could be between variable declarations
92+
{
93+
blankLine: 'any',
94+
prev: ['const', 'let', 'var'],
95+
next: ['const', 'let', 'var'],
96+
},
97+
// Require blank lines before all return statements
98+
{
99+
blankLine: 'always',
100+
prev: '*',
101+
next: 'return',
102+
},
103+
// Require blank lines before and after all following statements
104+
{
105+
blankLine: 'always',
106+
prev: '*',
107+
next: ['for', 'function', 'if', 'switch', 'try'],
108+
},
109+
{
110+
blankLine: 'always',
111+
prev: ['for', 'function', 'if', 'switch', 'try'],
112+
next: '*',
113+
},
114+
],
111115

112-
// Prefer code readability, e.g. `[0-9A-Za-z]`.
113-
'regexp/prefer-d': 'off',
116+
// Avoid a global variable unique to Node.js.
117+
'n/prefer-global/process': ['error', 'never'],
118+
119+
// Prefer code readability, e.g. `[0-9A-Za-z]`.
120+
'regexp/prefer-d': 'off',
121+
},
114122
},
115-
overrides: [
116-
{
117-
files: ['*.mjs'],
118-
rules: {
119-
'no-restricted-globals': ['error', 'module', 'require'],
120-
strict: ['error', 'never'],
121-
},
123+
{
124+
files: ['*.mjs'],
125+
rules: {
126+
'no-restricted-globals': ['error', 'module', 'require'],
127+
strict: ['error', 'never'],
122128
},
123-
],
124-
};
129+
},
130+
];

jest.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
22

3-
module.exports = {
4-
extends: ['plugin:jest/recommended', 'plugin:jest/style'],
5-
};
3+
const jest = require('eslint-plugin-jest');
4+
5+
module.exports = [jest.configs['flat/recommended'], jest.configs['flat/style']];

0 commit comments

Comments
 (0)