@july_cm/eslint-config 1.0.0 → 2.0.0

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 ADDED
@@ -0,0 +1,89 @@
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 * as config from '@july_cm/eslint-config';
23
+
24
+ // only javascript
25
+ export default config.javascript;
26
+
27
+ // only typescript
28
+ export default config.typescript;
29
+
30
+ /**
31
+ * recommended
32
+ * - javascript
33
+ * - typescript
34
+ * - package.json
35
+ */
36
+ export default config.recommended;
37
+ ```
38
+
39
+
40
+ ## Abort `package.json` key order
41
+
42
+ 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).
43
+
44
+ ```javascript
45
+ // root keys order
46
+ const order = ['name', 'version', 'author', 'scripts', 'dependencies', 'devDependencies'];
47
+
48
+ // dependencies package order
49
+ const pkg = {
50
+ pathPattern: '^(?:dev|peer|optional|bundled)?[Dd]ependencies$',
51
+ order: { type: 'asc' },
52
+ },
53
+ ```
54
+
55
+ ## With `Visual Studio Code`
56
+
57
+ 1. Install [VS Code ESLint extension](https://github.com/microsoft/vscode-eslint).
58
+
59
+ 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:
60
+
61
+ ```json
62
+ {
63
+ "editor.defaultFormatter": "dbaeumer.vscode-eslint",
64
+ }
65
+ ```
66
+
67
+ 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.
68
+
69
+ `@july_cm/eslint-config` has already integrated `eslint-plugin-prettier`, ensuring that both can work simultaneously without conflict.
70
+
71
+
72
+ 2. Fix on save
73
+
74
+ ```json
75
+ {
76
+ "editor.codeActionsOnSave": {
77
+ "source.fixAll.eslint": "explicit"
78
+ }
79
+ }
80
+ ```
81
+
82
+ 3. Debug
83
+
84
+ Open VSCode Command Panel(Ctrl + Shift + P / Cmd + Shift + P) and run:
85
+
86
+ ```
87
+ ESLint: Show Output Channel
88
+ ```
89
+ Fix errors if they exist.
@@ -0,0 +1,55 @@
1
+ import eslintJs from '@eslint/js';
2
+ import { defineConfig } from 'eslint/config';
3
+ import importPlugin from 'eslint-plugin-import';
4
+
5
+ import eslintPrettier from './prettier.js';
6
+
7
+ /**
8
+ * defineConfig 会 flat 一层 extends,并且将 files 字段赋值给所有 extends
9
+ * 可以借助这个函数为所有插件添加 files 约束,防止语言之间的污染
10
+ */
11
+ const javascriptConfig = defineConfig({
12
+ extends: [eslintJs.configs.recommended, importPlugin.flatConfigs.recommended, ...eslintPrettier],
13
+ files: ['**/*.{js,mjs,cjs,jsx}'],
14
+ rules: {
15
+ 'import/order': [
16
+ 'warn',
17
+ {
18
+ groups: ['builtin', 'external', 'internal', ['parent', 'sibling'], 'object', 'type', 'index'],
19
+ 'newlines-between': 'always',
20
+ pathGroupsExcludedImportTypes: ['builtin'],
21
+ alphabetize: { order: 'asc', caseInsensitive: true },
22
+ pathGroups: [
23
+ {
24
+ pattern: 'react**',
25
+ group: 'external',
26
+ position: 'before',
27
+ },
28
+ {
29
+ pattern: '{@/**,@**}',
30
+ group: 'internal',
31
+ position: 'before',
32
+ },
33
+ {
34
+ pattern: '**/*.{scss,json,svg,css,less}',
35
+ group: 'index',
36
+ position: 'after',
37
+ },
38
+ ],
39
+ },
40
+ ],
41
+ },
42
+ settings: {
43
+ 'import/resolver': {
44
+ node: true,
45
+ /**
46
+ * https://github.com/import-js/eslint-plugin-import/issues/3140
47
+ * eslint-plugin-import-node 解析器不支持 export 字段,所以不得不使用 eslint-plugin-import-typescript
48
+ */
49
+ typescript: true,
50
+ },
51
+ },
52
+ });
53
+
54
+ export { javascriptConfig };
55
+ export default javascriptConfig;
@@ -0,0 +1,26 @@
1
+ import { defineConfig } from 'eslint/config';
2
+ import eslintPluginJsonc from 'eslint-plugin-jsonc';
3
+
4
+ /**
5
+ * defineConfig 会 flat 一层 extends,并且将 files 字段赋值给所有 extends
6
+ * 可以借助这个函数为所有插件添加 files 约束,防止语言之间的污染
7
+ */
8
+ const packageJsonConfig = defineConfig({
9
+ extends: [...eslintPluginJsonc.configs['flat/prettier']],
10
+ rules: {
11
+ 'jsonc/sort-keys': [
12
+ 'warn',
13
+ {
14
+ pathPattern: '^$',
15
+ order: ['name', 'version', 'author', 'scripts', 'dependencies', 'devDependencies'],
16
+ },
17
+ {
18
+ pathPattern: '^(?:dev|peer|optional|bundled)?[Dd]ependencies$',
19
+ order: { type: 'asc' },
20
+ },
21
+ ],
22
+ },
23
+ });
24
+
25
+ export { packageJsonConfig };
26
+ 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,58 @@
1
+ import eslintJs from '@eslint/js';
2
+ import { defineConfig } from 'eslint/config';
3
+ import eslintPluginImport from 'eslint-plugin-import';
4
+ import tsEslint from 'typescript-eslint';
5
+
6
+ import eslintPrettier from './prettier.js';
7
+ /**
8
+ * defineConfig 会 flat 一层 extends,并且将 files 字段赋值给所有 extends
9
+ * 可以借助这个函数为所有插件添加 files 约束,防止语言之间的污染
10
+ */
11
+ const typescriptConfig = defineConfig({
12
+ extends: [
13
+ eslintJs.configs.recommended,
14
+ ...tsEslint.configs.recommended,
15
+ ...tsEslint.configs.stylistic,
16
+ eslintPluginImport.flatConfigs.recommended,
17
+ eslintPluginImport.flatConfigs.typescript,
18
+ ...eslintPrettier,
19
+ ],
20
+ files: ['**/*.{ts,tsx}'],
21
+ rules: {
22
+ 'import/order': [
23
+ 'warn',
24
+ {
25
+ groups: ['builtin', 'external', 'internal', ['parent', 'sibling'], 'object', 'type', 'index'],
26
+ 'newlines-between': 'always',
27
+ pathGroupsExcludedImportTypes: ['builtin'],
28
+ alphabetize: { order: 'asc', caseInsensitive: true },
29
+ pathGroups: [
30
+ {
31
+ pattern: 'react**',
32
+ group: 'external',
33
+ position: 'before',
34
+ },
35
+ {
36
+ pattern: '{@/**,@**}',
37
+ group: 'internal',
38
+ position: 'before',
39
+ },
40
+ {
41
+ pattern: '**/*.{scss,json,svg,css,less}',
42
+ group: 'index',
43
+ position: 'after',
44
+ },
45
+ ],
46
+ },
47
+ ],
48
+ },
49
+ settings: {
50
+ 'import/resolver': {
51
+ node: true,
52
+ typescript: true,
53
+ },
54
+ },
55
+ });
56
+
57
+ export { typescriptConfig };
58
+ export default typescriptConfig;
package/lib/index.js ADDED
@@ -0,0 +1,17 @@
1
+ import { defineConfig } from 'eslint/config';
2
+
3
+ import { javascriptConfig } from './configs/javascript.js';
4
+ import { packageJsonConfig } from './configs/package.js';
5
+ import { typescriptConfig } from './configs/typescript.js';
6
+
7
+ export const recommended = defineConfig(javascriptConfig, typescriptConfig, packageJsonConfig);
8
+ export const javascript = javascriptConfig;
9
+ export const typescript = typescriptConfig;
10
+ export const packageJson = packageJsonConfig;
11
+
12
+ export default {
13
+ recommended,
14
+ javascript,
15
+ typescript,
16
+ packageJson,
17
+ };
package/package.json CHANGED
@@ -1,24 +1,41 @@
1
1
  {
2
2
  "name": "@july_cm/eslint-config",
3
- "version": "1.0.0",
4
- "main": "index.js",
5
- "author": "",
6
- "license": "ISC",
3
+ "version": "2.0.0",
4
+ "main": "./lib/index.js",
5
+ "type": "module",
6
+ "files": [
7
+ "README.md",
8
+ "lib"
9
+ ],
10
+ "author": "July",
11
+ "dependencies": {
12
+ "@eslint/js": "^9.22.0",
13
+ "eslint-config-prettier": "^10.1.1",
14
+ "eslint-import-resolver-node": "^0.3.9",
15
+ "eslint-import-resolver-typescript": "^3.8.6",
16
+ "eslint-plugin-import": "^2.31.0",
17
+ "eslint-plugin-jsonc": "^2.19.1",
18
+ "eslint-plugin-prettier": "^5.2.3",
19
+ "typescript-eslint": "^8.26.1"
20
+ },
7
21
  "devDependencies": {
8
- "eslint": "^7.32.0"
22
+ "@release-it/conventional-changelog": "^10.0.0",
23
+ "eslint": "^9.22.0",
24
+ "release-it": "^18.1.2",
25
+ "release-it-pnpm": "^4.6.4"
9
26
  },
10
- "dependencies": {
11
- "@typescript-eslint/eslint-plugin": "^4.29.2",
12
- "@typescript-eslint/parser": "^4.29.2",
13
- "eslint-config-prettier": "^8.3.0",
14
- "eslint-plugin-prettier": "^3.4.1",
15
- "eslint-plugin-react": "^7.24.0",
16
- "prettier": "^2.3.2"
27
+ "optionalPeerDependencies": {
28
+ "eslint": "^9"
17
29
  },
18
30
  "repository": {
19
31
  "type": "git",
20
- "url": "git+https://github.com/Crownprime/eslint-config.git"
32
+ "url": "https://github.com/JxJuly/eslint-config.git"
33
+ },
34
+ "homepage": "https://github.com/JxJuly/eslint-config/blob/main/README.md",
35
+ "bugs": {
36
+ "url": "https://github.com/JxJuly/eslint-config/issues"
21
37
  },
22
- "homepage": "https://github.com/Crownprime/eslint-config#readme",
23
- "description": ""
24
- }
38
+ "scripts": {
39
+ "release": "release-it -ci"
40
+ }
41
+ }
package/index.js DELETED
@@ -1,19 +0,0 @@
1
- module.export = {
2
- "parser": "@typescript-eslint/parser",
3
- "extends": ["plugin:@typescript-eslint/recommended", "prettier"],
4
- "plugins": ["@typescript-eslint", "react", "prettier"],
5
- "rules": {
6
- "@typescript-eslint/explicit-module-boundary-types": 0,
7
- "prettier/prettier": ["error", {
8
- "printWidth": 80,
9
- "tabWidth": 2,
10
- "useTabs": false,
11
- "semi": false,
12
- "singleQuote": true,
13
- "trailingComma": "all",
14
- "bracketSpacing": true,
15
- "jsxBracketSameLine": false,
16
- "arrowParens": "avoid"
17
- }]
18
- }
19
- }