Skip to content

Commit 56a1aaf

Browse files
author
梁伟然
committed
release: 1.0 for eslint 9 - migrate to stylistic rules
- breaking: `@stylistic/eslint-plugin` rules migration following this guide https://eslint.style/guide/migration - remove dependency `eslint-config-standard`, all rules imported (with deprecated rules replacing) - bump `eslint-plugin-import` and restore rule 'import/export' ref import-js/eslint-plugin-import#2556 new / changed rules - disable 'import/no-webpack-loader-syntax' (imported webmail rules) - add 'no-restricted-globals' to forbid using global event (imported webmail rules) - change 'generator-star-spacing' and 'yield-star-spacing' to always 'after'
1 parent 425b77f commit 56a1aaf

12 files changed

+427
-143
lines changed

README.md

+59-41
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,70 @@
11

2-
# ESLint config files for Coremail (c)
3-
[![npm][npm-image]][npm-url]
2+
# eslint-config-email [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url]
43

54
[npm-image]: https://img.shields.io/npm/v/eslint-config-coremail.svg
65
[npm-url]: https://npmjs.org/package/eslint-config-coremail
6+
[downloads-image]: https://img.shields.io/npm/dm/eslint-config-coremail.svg
7+
[downloads-url]: https://npmjs.org/package/eslint-config-coremail
78

8-
## Usage
9-
10-
This package exports [a flat ESLint configuration](https://eslint.org/blog/2022/08/new-config-system-part-2/)
11-
which is supported since `eslint 8.21.0`
12-
13-
```bash
14-
npm install --save-dev eslint eslint-config-coremail
15-
```
16-
17-
Example `eslint.config.js` in esm:
18-
```js
19-
import {configs} from 'eslint-config-coremail';
20-
21-
export default [
22-
// default using browser & node env
23-
configs.standard,
24-
// for old IE compatible
25-
{
26-
files : ['path/to/legacy/**'],
27-
...configs.legacy,
28-
},
29-
]
30-
```
31-
32-
Example `eslint.config.js` in commonjs:
33-
```js
34-
module.export = import('eslint-config-coremail').then(({configs}) => [
35-
// default using browser & node env
36-
configs.standard,
37-
// for old IE compatible
38-
{
39-
files : ['path/to/legacy/**'],
40-
...configs.legacy,
41-
},
42-
]);
43-
```
9+
#### The eslint config for [Coremail (c)](https://www.coremail.cn)
10+
11+
This module exports [a flat ESLint configuration](https://eslint.org/blog/2022/08/new-config-system-part-2/) which is
12+
supported since `eslint 8.21.0`, basing [eslint-config-standard].
13+
14+
Notes that [eslint-config-standard] is likely [deprecated and stop maintaining](https://github.com/standard/eslint-config-standard/issues/351).
15+
It's encouraged to switch to [neo-standard] for [standard] users.
16+
17+
This project is only focus on eslint config, and not providing framework tooling like [neo-standard].
18+
19+
[eslint-config-standard]: https://github.com/standard/eslint-config-standard
20+
[neo-standard]: https://github.com/neostandard/neostandard
21+
[standard]: https://standardjs.com
22+
23+
## Quick start
24+
25+
1. `npm install --save-dev eslint eslint-config-coremail`
26+
27+
2. For projects using esm, add `eslint.config.js` as:
28+
```js
29+
import {configs} from 'eslint-config-coremail';
30+
31+
export default [
32+
// default enables browser & node env, you can change to `configs.node` for server side project
33+
configs.standard, {
34+
// your overrides here
35+
}, {
36+
// for legacy codes compliant with old IE
37+
...configs.legacy,
38+
files : ['path/to/legacy/codes/**'],
39+
},
40+
]
41+
```
42+
43+
3. For projects using commonjs, add `eslint.config.js` as:
44+
```js
45+
module.exports = import('eslint-config-coremail').then(({configs}) => [
46+
// default enables browser & node env, you can change to `configs.node` for server side project
47+
configs.standard, {
48+
// your overrides here
49+
}, {
50+
// for legacy codes compliant with old IE
51+
...configs.legacy,
52+
files : ['path/to/legacy/codes/**'],
53+
},
54+
]);
55+
```
56+
57+
## Migrating from eslint-config-coremail 0.x / eslint-config-standard 17.x
58+
59+
1. Read [this article](https://eslint.org/blog/2024/04/eslint-v9.0.0-released/) for ESLint 9 migration
60+
2. Migrate [deprecated ESLint style rules](https://eslint.org/blog/2023/10/deprecating-formatting-rules/)
61+
with [eslint-stylistic](https://eslint.style/) rules following [this guide](https://eslint.style/guide/migration)
4462

4563
## Learn more
4664

47-
For the full listing of rules that eslint supports, and more, visit
48-
For more information on the full listing of rules, editor plugins, FAQs, and more, visit the
49-
[ESLint official site](http://eslint.org/docs/rules/).
65+
For more information on the full listing of rules that eslint supports, and more, visit
66+
- [ESLint official site](http://eslint.org/docs/rules/)
67+
- [ESLint Stylistic](https://eslint.style/packages/default#rules)
5068

5169
## License
5270

config/imported.js

+242
Large diffs are not rendered by default.

config/legacy.js

+8-16
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
11
/**
2-
* Copyright (c) 2023 Coremail.cn, Ltd. All Rights Reserved.
2+
* Copyright (c) 2024 Coremail.cn, Ltd. All Rights Reserved.
33
*/
44

55
import {error} from './util.js';
66

77
export default {
8-
98
languageOptions : {
109
ecmaVersion : 3,
1110
sourceType : 'script',
1211
parserOptions : {allowReserved : true},
1312
},
1413

15-
rules : {
16-
/* eslint-disable indent *//* @formatter:off */
14+
plugins : {'@stylistic' : (await import('@stylistic/eslint-plugin')).default},
1715

18-
// here two rules are only for ES3 compliant / IE6 supports
19-
'quote-props' : [error, 'as-needed', {
20-
keywords : true,
21-
unnecessary : false,
22-
}],
23-
'dot-notation' : [error, {
24-
allowKeywords : false,
25-
allowPattern : '.*',
26-
}],
27-
'comma-dangle' : [error, 'never'],
28-
// ES3 compliant END
29-
'no-tabs' : [error],
16+
// rules only for ES3 compliant / IE6 ~ IE8
17+
rules : {
18+
'dot-notation' : [error, {allowKeywords : false, allowPattern : '.*'}],
19+
'@stylistic/quote-props' : [error, 'as-needed', {keywords : true, unnecessary : false}],
20+
'@stylistic/comma-dangle' : [error, 'never'],
21+
'@stylistic/no-tabs' : [error],
3022
},
3123
};

config/standard.js

+67-70
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,82 @@
11
/**
2-
* Copyright (c) 2023 Coremail.cn, Ltd. All Rights Reserved.
2+
* Copyright (c) 2024 Coremail.cn, Ltd. All Rights Reserved.
33
*/
44

5-
import standard from 'eslint-config-standard';
5+
import {baseRules, plugins, styleRules} from './imported.js';
66
import {error, first, mergeRules, never, off} from './util.js';
77

88
export default {
9-
109
languageOptions : {
1110
ecmaVersion : 'latest',
1211
parserOptions : {ecmaFeatures : {jsx : true}},
1312
},
1413

15-
plugins : Object.fromEntries(await Promise.all(standard.plugins.map(async key => [
16-
key, (await import(`eslint-plugin-${key}`)).default,
17-
]))),
14+
plugins,
15+
rules : mergeRules(baseRules, styleRules, { /* eslint-disable @stylistic/indent */// @formatter:off
16+
'no-var' : [error],
17+
'@stylistic/no-tabs' : [error],
18+
'@stylistic/indent' : [error, 4, {
19+
SwitchCase : 0,
20+
VariableDeclarator : {var : 1, let : 1, const : 1},
21+
ImportDeclaration : first,
22+
ArrayExpression : first,
23+
ObjectExpression : first,
24+
FunctionDeclaration : {parameters: first},
25+
FunctionExpression : {parameters: first},
26+
CallExpression : {arguments: 1},
27+
MemberExpression : off,
28+
ignoreComments : true,
29+
ignoredNodes : styleRules['@stylistic/indent'][2].ignoredNodes,
30+
}],
31+
'@stylistic/semi' : [off],
32+
'@stylistic/quotes' : [error, 'single', 'avoid-escape'],
33+
'@stylistic/arrow-parens' : [error, 'as-needed'],
34+
'@stylistic/operator-linebreak' : [error, 'before'], // ternary operator should have nothing special
35+
'@stylistic/multiline-ternary' : [off],
36+
'@stylistic/comma-dangle' : [error, { // more friendly to VCS system / manual code arrangements
37+
arrays : 'always-multiline',
38+
objects : 'always-multiline',
39+
imports : 'always-multiline',
40+
exports : 'always-multiline',
41+
functions : 'only-multiline',
42+
}],
43+
'@stylistic/padded-blocks' : [off], // extra space in blocks should not be a problem
44+
'prefer-const' : [off],
45+
'yoda' : [off],
46+
'no-new' : [off],
47+
'no-void' : [off],
48+
'no-case-declarations' : [off],
49+
'no-inner-declarations' : [off],
50+
'default-case' : [off],
51+
'one-var' : [off],
52+
'dot-notation' : [off],
53+
'@stylistic/quote-props' : [off],
54+
'@stylistic/object-curly-spacing' : [off],
55+
'@stylistic/space-before-function-paren' : [error, {named: 'never', anonymous: 'ignore', asyncArrow: 'always'}],
56+
'@stylistic/generator-star-spacing' : [error, 'after'],
57+
'@stylistic/yield-star-spacing' : [error, 'after'],
58+
'@stylistic/no-multiple-empty-lines' : [off],
59+
'@stylistic/no-multi-spaces' : [error, {
60+
exceptions: {VariableDeclarator: true, ImportDeclaration: true},
61+
ignoreEOLComments: true,
62+
}],
63+
'@stylistic/key-spacing' : [off],
64+
'camelcase' : [error, {
65+
properties : never,
66+
ignoreDestructuring : true,
67+
ignoreGlobals : true,
68+
}],
69+
70+
'array-callback-return' : [off],
71+
'no-empty' : [off],
72+
'no-restricted-globals' : [error, {
73+
name : 'event',
74+
message : 'Use local parameter instead.',
75+
}],
1876

19-
/* eslint-disable indent */// @formatter:off
20-
rules : mergeRules(standard.rules, {
21-
'no-var' : [error],
22-
'no-tabs' : [error],
23-
'indent' : [error, 4, {
24-
SwitchCase : 0,
25-
VariableDeclarator : { var : 1, let : 1, const : 1 },
26-
ImportDeclaration : first,
27-
ArrayExpression : first,
28-
ObjectExpression : first,
29-
FunctionDeclaration : {parameters: first},
30-
FunctionExpression : {parameters: first},
31-
CallExpression : {arguments: 1},
32-
MemberExpression : off,
33-
ignoreComments : true,
34-
}],
35-
'semi' : [off, never],
36-
'quotes' : [error, 'single', 'avoid-escape'],
37-
'arrow-parens' : [error, 'as-needed'],
38-
'operator-linebreak' : [error, 'before'], // corrected now, ternary operator should have nothing special
39-
'comma-dangle' : [error, { // more friendly to VCS system / manual code arrangements
40-
arrays : 'always-multiline',
41-
objects : 'always-multiline',
42-
imports : 'always-multiline',
43-
exports : 'always-multiline',
44-
functions : 'only-multiline',
45-
}],
46-
'padded-blocks' : [off], // extra space in blocks should not be a problem
47-
'prefer-const' : [off],
48-
'yoda' : [off],
49-
'no-new' : [off],
50-
'no-void' : [off],
51-
'no-case-declarations' : [off],
52-
'no-inner-declarations' : [off],
53-
'default-case' : [off],
54-
'one-var' : [off],
55-
'dot-notation' : [off],
56-
'quote-props' : [off],
57-
'object-curly-spacing' : [off],
58-
'space-before-function-paren' : [error, {named: never, anonymous: 'ignore', asyncArrow: 'always'}],
59-
'space-before-blocks' : [error],
60-
'no-multiple-empty-lines' : [off],
61-
'no-multi-spaces' : [error, {
62-
exceptions: {VariableDeclarator: true, ImportDeclaration: true},
63-
ignoreEOLComments: true,
64-
}],
65-
'keyword-spacing' : [error],
66-
'key-spacing' : [off],
67-
'comma-spacing' : [error],
68-
'space-infix-ops' : [error],
69-
'spaced-comment' : [error],
70-
'eol-last' : [error],
71-
'camelcase' : [error, {
72-
properties : never,
73-
ignoreDestructuring : true,
74-
ignoreGlobals : true,
75-
}],
76-
'multiline-ternary' : [off],
77-
'array-callback-return' : [off],
78-
'no-empty' : [off],
79-
'n/no-path-concat' : [off],
80-
'n/no-exports-assign' : [off],
77+
'n/no-path-concat' : [off],
78+
'n/no-exports-assign' : [off],
8179

82-
// waiting https://github.com/import-js/eslint-plugin-import/issues/2556
83-
'import/export' : [off],
80+
'import/no-webpack-loader-syntax' : [off],
8481
}),
8582
};

eslint.config.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
// noinspection JSUnusedGlobalSymbols
1+
/**
2+
* Copyright (c) 2024 Coremail.cn, Ltd. All Rights Reserved.
3+
*/
24

35
import {configs} from './config/index.js';
46

5-
export default [configs.es, {
7+
export default [configs.node, {
68
files : ['test/samples/**'],
79
rules : {
810
// disable debatable rules
9-
'semi' : 'off',
10-
'quotes' : 'off',
11+
'@stylistic/semi' : 'off',
12+
'@stylistic/quotes' : 'off',
13+
1114
// sample test codes have many unused / undeclared symbols
1215
'no-undef' : 'off',
1316
'no-unused-vars' : 'off',

package.json

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name" : "eslint-config-coremail",
33
"description" : "Javascript Standard Style - ESLint Shareable Config for coremail.cn",
4-
"version" : "0.99.1",
4+
"version" : "1.0.2",
55
"author" : {
66
"name" : "William Leung",
77
"email" : "williamleung2006@gmail.com"
@@ -24,6 +24,10 @@
2424

2525
"license" : "MIT",
2626
"main" : "config/index.js",
27+
"exports" : {
28+
"." : "./config/index.js",
29+
"./package.json" : "./package.json"
30+
},
2731
"files" : [
2832
"config/*"
2933
],
@@ -33,15 +37,18 @@
3337
},
3438

3539
"peerDependencies" : {
36-
"eslint" : "^8.52.0",
40+
"eslint" : "^9.13.0",
3741
"globals" : "*"
3842
},
3943

4044
"devDependencies" : {
41-
"eslint" : "~8.52.0"
45+
"eslint" : "~9.13.0"
4246
},
4347

4448
"dependencies" : {
45-
"eslint-config-standard" : "~17.1.0"
49+
"eslint-plugin-import" : "^2.31.0",
50+
"eslint-plugin-n" : "^17.11.1",
51+
"eslint-plugin-promise" : "^7.1.0",
52+
"@stylistic/eslint-plugin" : "^2.9.0"
4653
}
4754
}

test/samples/esm1.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//
2+
3+
export const one = 1;
4+
export const two = 2;

test/samples/esm2.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//
2+
3+
export * from './esm1.js'

test/samples/sample1-indent-const.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//
2-
// The indent rule do not supports '1.5' as unit (6 space) or other multiline alignment technic
3-
/* eslint indent: "off" */
2+
// The indent rule does not support '1.5' as unit (6 space) or other multiline alignment technic
3+
/* eslint @stylistic/indent: "off" */
44

55
// noinspection JSUnusedGlobalSymbols
66
const A = 'a',
77
B = 'b',
88
C = 'c';
9-

0 commit comments

Comments
 (0)