@july_cm/eslint-config 1.0.1 → 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 CHANGED
@@ -19,20 +19,21 @@ npm install --save-dev eslint @july_cm/eslint-config
19
19
  ## Language support
20
20
 
21
21
  ```javascript
22
- const { javascriptConfig, typescriptConfig, packageJsonConfig } from '@july_cm/eslint-config';
22
+ const * as config from '@july_cm/eslint-config';
23
23
 
24
24
  // only javascript
25
- export default javascriptConfig;
25
+ export default config.javascript;
26
26
 
27
27
  // only typescript
28
- export default typescriptConfig;
29
-
30
- // recommended
31
- export default [
32
- ...javascriptConfig,
33
- ...typescriptConfig,
34
- ...packageJsonConfig
35
- ]
28
+ export default config.typescript;
29
+
30
+ /**
31
+ * recommended
32
+ * - javascript
33
+ * - typescript
34
+ * - package.json
35
+ */
36
+ export default config.recommended;
36
37
  ```
37
38
 
38
39
 
@@ -1,12 +1,54 @@
1
1
  import eslintJs from '@eslint/js';
2
+ import { defineConfig } from 'eslint/config';
3
+ import importPlugin from 'eslint-plugin-import';
2
4
 
3
- import { configMerge } from './config-merge.js';
4
5
  import eslintPrettier from './prettier.js';
5
6
 
6
- const configs = [eslintJs.configs.recommended, ...eslintPrettier];
7
-
8
- const javascriptConfig = configMerge(configs, {
7
+ /**
8
+ * defineConfig 会 flat 一层 extends,并且将 files 字段赋值给所有 extends
9
+ * 可以借助这个函数为所有插件添加 files 约束,防止语言之间的污染
10
+ */
11
+ const javascriptConfig = defineConfig({
12
+ extends: [eslintJs.configs.recommended, importPlugin.flatConfigs.recommended, ...eslintPrettier],
9
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
+ },
10
52
  });
11
53
 
12
54
  export { javascriptConfig };
@@ -1,28 +1,25 @@
1
+ import { defineConfig } from 'eslint/config';
1
2
  import eslintPluginJsonc from 'eslint-plugin-jsonc';
2
3
 
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
- },
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
+ ],
21
22
  },
22
- ];
23
-
24
- const packageJsonConfig = configMerge(configs, {
25
- files: ['package.json'],
26
23
  });
27
24
 
28
25
  export { packageJsonConfig };
@@ -1,52 +1,57 @@
1
1
  import eslintJs from '@eslint/js';
2
-
2
+ import { defineConfig } from 'eslint/config';
3
+ import eslintPluginImport from 'eslint-plugin-import';
3
4
  import tsEslint from 'typescript-eslint';
4
- import eslintPluginImportX from 'eslint-plugin-import-x';
5
- import eslintPrettier from './prettier.js';
6
5
 
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
- ],
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,
44
53
  },
45
54
  },
46
- ];
47
-
48
- const typescriptConfig = configMerge(configs, {
49
- files: ['**/*.{ts,tsx}'],
50
55
  });
51
56
 
52
57
  export { typescriptConfig };
package/lib/index.js CHANGED
@@ -1,3 +1,17 @@
1
- export { packageJsonConfig } from './configs/package.js';
2
- export { javascriptConfig } from './configs/javascript.js';
3
- export { typescriptConfig } from './configs/typescript.js';
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,20 +1,28 @@
1
1
  {
2
2
  "name": "@july_cm/eslint-config",
3
- "version": "1.0.1",
3
+ "version": "2.0.0",
4
4
  "main": "./lib/index.js",
5
5
  "type": "module",
6
- "files": ["README.md", "lib"],
6
+ "files": [
7
+ "README.md",
8
+ "lib"
9
+ ],
7
10
  "author": "July",
8
11
  "dependencies": {
9
12
  "@eslint/js": "^9.22.0",
10
13
  "eslint-config-prettier": "^10.1.1",
11
- "eslint-plugin-import-x": "^4.6.1",
14
+ "eslint-import-resolver-node": "^0.3.9",
15
+ "eslint-import-resolver-typescript": "^3.8.6",
16
+ "eslint-plugin-import": "^2.31.0",
12
17
  "eslint-plugin-jsonc": "^2.19.1",
13
18
  "eslint-plugin-prettier": "^5.2.3",
14
19
  "typescript-eslint": "^8.26.1"
15
20
  },
16
21
  "devDependencies": {
17
- "eslint": "^9.22.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"
18
26
  },
19
27
  "optionalPeerDependencies": {
20
28
  "eslint": "^9"
@@ -26,5 +34,8 @@
26
34
  "homepage": "https://github.com/JxJuly/eslint-config/blob/main/README.md",
27
35
  "bugs": {
28
36
  "url": "https://github.com/JxJuly/eslint-config/issues"
37
+ },
38
+ "scripts": {
39
+ "release": "release-it -ci"
29
40
  }
30
41
  }
@@ -1,5 +0,0 @@
1
- const configMerge = (configs, config) => {
2
- return configs.map((conf) => ({ ...conf, ...config }));
3
- };
4
-
5
- export { configMerge };