@july_cm/eslint-config 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -0
- package/lib/configs/config-merge.js +5 -0
- package/lib/configs/javascript.js +13 -0
- package/lib/configs/package.js +29 -0
- package/lib/configs/prettier.js +26 -0
- package/lib/configs/typescript.js +53 -0
- package/lib/index.js +3 -0
- package/package.json +21 -0
package/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# @july_cm/eslint-config
|
|
2
|
+
|
|
3
|
+
This is my common ESlint configuration.
|
|
4
|
+
|
|
5
|
+
It depends on ESLint v9 or later and is only compatible with Flat Configuration.
|
|
6
|
+
|
|
7
|
+
❌ [legacy configuration](https://eslint.org/docs/latest/use/configure/configuration-files-deprecated) (legacy: `.eslintrc*`)
|
|
8
|
+
|
|
9
|
+
✅ [flat configuration](https://eslint.org/docs/latest/use/configure/configuration-files-new) (new: `eslint.config.js`)
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install --save-dev eslint @july_cm/eslint-config
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`@july_cm/eslint-config` does not install ESLint for you. You must install these yourself.
|
|
18
|
+
|
|
19
|
+
## Language support
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
const { javascriptConfig, typescriptConfig, packageJsonConfig } from '@july_cm/eslint-config';
|
|
23
|
+
|
|
24
|
+
// only javascript
|
|
25
|
+
export default javascriptConfig;
|
|
26
|
+
|
|
27
|
+
// only typescript
|
|
28
|
+
export default typescriptConfig;
|
|
29
|
+
|
|
30
|
+
// recommended
|
|
31
|
+
export default [
|
|
32
|
+
...javascriptConfig,
|
|
33
|
+
...typescriptConfig,
|
|
34
|
+
...packageJsonConfig
|
|
35
|
+
]
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## Abort `package.json` key order
|
|
40
|
+
|
|
41
|
+
The sorting functionality is implemented based on [eslint-plugin-jsonc](https://github.com/ota-meshi/eslint-plugin-jsonc) and [prettier](https://github.com/prettier/prettier).
|
|
42
|
+
|
|
43
|
+
```javascript
|
|
44
|
+
// root keys order
|
|
45
|
+
const order = ['name', 'version', 'author', 'scripts', 'dependencies', 'devDependencies'];
|
|
46
|
+
|
|
47
|
+
// dependencies package order
|
|
48
|
+
const pkg = {
|
|
49
|
+
pathPattern: '^(?:dev|peer|optional|bundled)?[Dd]ependencies$',
|
|
50
|
+
order: { type: 'asc' },
|
|
51
|
+
},
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## With `Visual Studio Code`
|
|
55
|
+
|
|
56
|
+
1. Install [VS Code ESLint extension](https://github.com/microsoft/vscode-eslint).
|
|
57
|
+
|
|
58
|
+
Check if there are other plugins set as the default formatter in the editor. If so, they need to be removed or replaced with ESLint:
|
|
59
|
+
|
|
60
|
+
```json
|
|
61
|
+
{
|
|
62
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
If the Prettier extension is also active in this workspace, it should be disabled. This is because both will conflict with each other, leading to formatting issues.
|
|
67
|
+
|
|
68
|
+
`@july_cm/eslint-config` has already integrated `eslint-plugin-prettier`, ensuring that both can work simultaneously without conflict.
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
2. Fix on save
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"editor.codeActionsOnSave": {
|
|
76
|
+
"source.fixAll.eslint": "explicit"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
3. Debug
|
|
82
|
+
|
|
83
|
+
Open VSCode Command Panel(Ctrl + Shift + P / Cmd + Shift + P) and run:
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
ESLint: Show Output Channel
|
|
87
|
+
```
|
|
88
|
+
Fix errors if they exist.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import eslintJs from '@eslint/js';
|
|
2
|
+
|
|
3
|
+
import { configMerge } from './config-merge.js';
|
|
4
|
+
import eslintPrettier from './prettier.js';
|
|
5
|
+
|
|
6
|
+
const configs = [eslintJs.configs.recommended, ...eslintPrettier];
|
|
7
|
+
|
|
8
|
+
const javascriptConfig = configMerge(configs, {
|
|
9
|
+
files: ['**/*.{js,mjs,cjs,jsx}'],
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export { javascriptConfig };
|
|
13
|
+
export default javascriptConfig;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import eslintPluginJsonc from 'eslint-plugin-jsonc';
|
|
2
|
+
|
|
3
|
+
import { configMerge } from './config-merge.js';
|
|
4
|
+
|
|
5
|
+
const configs = [
|
|
6
|
+
...eslintPluginJsonc.configs['flat/prettier'],
|
|
7
|
+
{
|
|
8
|
+
rules: {
|
|
9
|
+
'jsonc/sort-keys': [
|
|
10
|
+
'warn',
|
|
11
|
+
{
|
|
12
|
+
pathPattern: '^$',
|
|
13
|
+
order: ['name', 'version', 'author', 'scripts', 'dependencies', 'devDependencies'],
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
pathPattern: '^(?:dev|peer|optional|bundled)?[Dd]ependencies$',
|
|
17
|
+
order: { type: 'asc' },
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
const packageJsonConfig = configMerge(configs, {
|
|
25
|
+
files: ['package.json'],
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export { packageJsonConfig };
|
|
29
|
+
export default packageJsonConfig;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import recommended from 'eslint-plugin-prettier/recommended';
|
|
2
|
+
|
|
3
|
+
const prettierConfig = [
|
|
4
|
+
recommended,
|
|
5
|
+
{
|
|
6
|
+
rules: {
|
|
7
|
+
'prettier/prettier': [
|
|
8
|
+
'warn',
|
|
9
|
+
{
|
|
10
|
+
// 优先使用单引号
|
|
11
|
+
singleQuote: true,
|
|
12
|
+
printWidth: 110,
|
|
13
|
+
// 需要分号
|
|
14
|
+
semi: true,
|
|
15
|
+
// 仅在 es5 中有效的结构尾随逗号
|
|
16
|
+
trailingComma: 'es5',
|
|
17
|
+
// 不读取 prettier 配置文件,统一走 eslint 配置
|
|
18
|
+
usePrettierrc: false,
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
export { prettierConfig };
|
|
26
|
+
export default prettierConfig;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import eslintJs from '@eslint/js';
|
|
2
|
+
|
|
3
|
+
import tsEslint from 'typescript-eslint';
|
|
4
|
+
import eslintPluginImportX from 'eslint-plugin-import-x';
|
|
5
|
+
import eslintPrettier from './prettier.js';
|
|
6
|
+
|
|
7
|
+
import { configMerge } from './config-merge.js';
|
|
8
|
+
|
|
9
|
+
const configs = [
|
|
10
|
+
eslintJs.configs.recommended,
|
|
11
|
+
...tsEslint.configs.recommended,
|
|
12
|
+
...tsEslint.configs.stylistic,
|
|
13
|
+
...eslintPrettier,
|
|
14
|
+
eslintPluginImportX.flatConfigs.recommended,
|
|
15
|
+
eslintPluginImportX.flatConfigs.typescript,
|
|
16
|
+
{
|
|
17
|
+
rules: {
|
|
18
|
+
'import-x/order': [
|
|
19
|
+
'warn',
|
|
20
|
+
{
|
|
21
|
+
groups: ['builtin', 'external', 'internal', ['parent', 'sibling'], 'object', 'type', 'index'],
|
|
22
|
+
'newlines-between': 'always',
|
|
23
|
+
pathGroupsExcludedImportTypes: ['builtin'],
|
|
24
|
+
alphabetize: { order: 'asc', caseInsensitive: true },
|
|
25
|
+
pathGroups: [
|
|
26
|
+
{
|
|
27
|
+
pattern: 'react**',
|
|
28
|
+
group: 'external',
|
|
29
|
+
position: 'before',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
pattern: '{@/**,@**}',
|
|
33
|
+
group: 'internal',
|
|
34
|
+
position: 'before',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
pattern: '{**.scss,**.json,**.svg,,**.css}',
|
|
38
|
+
group: 'index',
|
|
39
|
+
position: 'after',
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
const typescriptConfig = configMerge(configs, {
|
|
49
|
+
files: ['**/*.{ts,tsx}'],
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export { typescriptConfig };
|
|
53
|
+
export default typescriptConfig;
|
package/lib/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@july_cm/eslint-config",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"main": "./lib/index.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": ["README.md", "lib"],
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@eslint/js": "^9.22.0",
|
|
9
|
+
"eslint-config-prettier": "^10.1.1",
|
|
10
|
+
"eslint-plugin-import-x": "^4.6.1",
|
|
11
|
+
"eslint-plugin-jsonc": "^2.19.1",
|
|
12
|
+
"eslint-plugin-prettier": "^5.2.3",
|
|
13
|
+
"typescript-eslint": "^8.26.1"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"eslint": "^9.22.0"
|
|
17
|
+
},
|
|
18
|
+
"optionalPeerDependencies": {
|
|
19
|
+
"eslint": "^9"
|
|
20
|
+
}
|
|
21
|
+
}
|