@whitetrefoil/eslint-config 0.24.1 → 0.25.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/.eslintrc.js CHANGED
@@ -1,7 +1,12 @@
1
1
  module.exports = {
2
+ root: true,
2
3
 
3
4
  extends: ['./node'],
4
5
 
6
+ parserOptions: {
7
+ sourceType: 'script',
8
+ },
9
+
5
10
  rules: {
6
11
  'no-magic-numbers': [
7
12
  1,
package/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  My Personal Default ESLint Rules Settings
2
+ =========================================
2
3
 
3
4
  Installation
4
- ============
5
+ ------------
5
6
 
6
7
  Install below package (just pick needed):
7
8
  ```sh
@@ -26,124 +27,53 @@ npm install --save-dev @whitetrefoil/eslint-config \
26
27
  typescript
27
28
  ```
28
29
 
29
- Type Info
30
- =========
31
-
32
- TypeScript rules may need or not type info.
33
- The rules require type info are much slower than ones needn't,
34
- so they're better for single-time full scan or CI scan a little more.
35
-
36
- Using type info requires a `"tsconfig.eslint.json"` file in the root dir,
37
- which contains all files to lint, e.g.:
38
- ```json
39
- {
40
- "extends" : "./tsconfig.json",
41
- "compilerOptions": {
42
- "module": "esnext",
43
- "target": "esnext"
44
- },
45
- "include" : [
46
- "**/*.tsx",
47
- "**/*.ts",
48
- "**/*.jsx",
49
- "**/*.js"
50
- ],
51
- "exclude" : [
52
- "**/node_modules",
53
- "**/.*",
54
- "**/~*"
55
- ]
56
- }
57
- ```
30
+ Example
31
+ -------
58
32
 
59
- Rule Presets
60
- ============
33
+ ```js
34
+ /**
35
+ * @type {import('eslint').Linter.Config}
36
+ */
37
+ module.exports = {
38
+ root: true,
61
39
 
62
- Includes 7 presets can be used in `extends` in `eslintrc.xxx`:
63
- * `@whitetrefoil/eslint-config/presets/js` - Basic JS rules, disallow tailing semi;
64
- * `@whitetrefoil/eslint-config/presets/js/semi` - Same as above, excepts requiring tailing semi;
65
- * `@whitetrefoil/eslint-config/presets/node` - node.js rules;
66
- * `@whitetrefoil/eslint-config/presets/react` - React rules;
67
- * `@whitetrefoil/eslint-config/presets/ts` - TypeScript rules (needn't type info), disallow tailing semi;
68
- * `@whitetrefoil/eslint-config/presets/ts/semi` - Same as above, excepts requiring tailing semi;
69
- * `@whitetrefoil/eslint-config/presets/ts-with-type` - TypeScript rules require type info,append to `@whitetrefoil/eslint-config/presets/ts` if enabled;
70
- * `@whitetrefoil/eslint-config/presets/vue` - Vue2.x Rules;
71
- * `@whitetrefoil/eslint-config/presets/vue3` - Vue3.x Rules;
72
-
73
- Use 1 from 2 JS presets in the root `extends`.
74
- Pick what needed in the 5 detail presets for the `overrides` section.
75
- E.g.
76
-
77
- ```json
78
- {
79
- "root": true,
80
- "settings": {
81
- "react": {
82
- "version": "detect"
83
- }
84
- },
85
- "parserOptions": {
86
- "sourceType" : "module",
87
- "ecmaFeatures": {
88
- "legacyDecorators": true
89
- }
40
+ // In case the project structure is too complex, try specify `tsconfigRootDir` to boost performance
41
+ parserOptions: {
42
+ tsconfigRootDir: __dirname,
90
43
  },
91
- "env": {
92
- "es6" : true,
93
- "node": true
94
- },
95
- "extends": ["@whitetrefoil/eslint-config/preset/js"],
96
- "overrides": [
97
- {
98
- "files": ["Gulpfile.js", "dev/**/*.ts", "stubapi/**/*.ts"],
99
- "extends": ["@whitetrefoil/eslint-config/presets/node"]
100
- },
101
- {
102
- "files": ["**/*.ts", "**/*.tsx"],
103
- "extends": ["@whitetrefoil/eslint-config/presets/ts"]
104
- },
105
- {
106
- "files": ["**/*.tsx"],
107
- "extends": ["@whitetrefoil/eslint-config/presets/react"]
108
- }
109
- ]
44
+
45
+ extends: [
46
+ '@whitetrefoil/eslint-config/web-react',
47
+ ],
110
48
  }
111
49
  ```
112
50
 
51
+ Project Level Presets
52
+ ---------------------
113
53
 
114
- Full Presets
115
- ============
54
+ Presets for usual project types:
55
+ * `@whitetrefoil/eslint-config/web-react` - Web projects base on React (app or lib);
56
+ * `@whitetrefoil/eslint-config/web-others` - Other web projects (app or lib);
57
+ * `@whitetrefoil/eslint-config/node` - Node.js;
58
+ * `@whitetrefoil/eslint-config/base` - Base of above, includes only basic JS & TS stuff;
116
59
 
117
- * `@whitetrefoil/eslint-config` - For general project, no semi;
118
- * `@whitetrefoil/eslint-config/semi` - For general project, with semi;
119
- * `@whitetrefoil/eslint-config/node` - For node.js project, no semi;
120
- * `@whitetrefoil/eslint-config/node-semi` - For node.js project, with semi;
121
- * `@whitetrefoil/eslint-config/react` - For react project, no semi;
122
- * `@whitetrefoil/eslint-config/react-semi` - For react project, with semi;
123
- * `@whitetrefoil/eslint-config/vue` - For Vue2.x project, no semi;
124
- * `@whitetrefoil/eslint-config/vue-semi` - For Vue2.x project, with semi;
125
- * `@whitetrefoil/eslint-config/vue3` - For Vue3.x project, no semi;
126
- * `@whitetrefoil/eslint-config/vue3-semi` - For Vue3.x project, with semi;
127
-
128
- Above 4 don't include rules require type info.
129
- The full ones locate in `/with-type` for full / CI scan:
130
- * `@whitetrefoil/eslint-config/with-type`
131
- * `@whitetrefoil/eslint-config/with-type/semi`
132
- * `@whitetrefoil/eslint-config/with-type/node`;
133
- * `@whitetrefoil/eslint-config/with-type/node-semi`;
134
- * `@whitetrefoil/eslint-config/with-type/react`
135
- * `@whitetrefoil/eslint-config/with-type/react-semi`
136
- * `@whitetrefoil/eslint-config/with-type/vue`;
137
- * `@whitetrefoil/eslint-config/with-type/vue-semi`;
138
- * `@whitetrefoil/eslint-config/with-type/vue3`;
139
- * `@whitetrefoil/eslint-config/with-type/vue3-semi`;
140
-
141
- Each preset contains nearly full settings includes `overrides`.
142
- The example in the above section is actually the `@whitetrefoil/eslint-config/react` preset.
60
+ Rule Presets
61
+ ============
143
62
 
63
+ Including some rule presets which will be helpful when constructing special config if the project type is unusual:
64
+ * `@whitetrefoil/eslint-config/rules/base` - **Basic JS** rules (no tailing semi);
65
+ * `@whitetrefoil/eslint-config/rules/base-semi` - **Basic JS** rules (w/ tailing semi);
66
+ * `@whitetrefoil/eslint-config/rules/dependencies` - **`implicit-dependencies`** rules;
67
+ * `@whitetrefoil/eslint-config/rules/node` - **Node.js** rules;
68
+ * `@whitetrefoil/eslint-config/rules/react` - **React** rules;
69
+ * `@whitetrefoil/eslint-config/rules/ts` - **`eslint-typescript`** rules no type info required (no tailing semi);
70
+ * `@whitetrefoil/eslint-config/rules/ts-semi` - **`eslint-typescript`** rules no type info required (w/ tailing semi);
71
+ * `@whitetrefoil/eslint-config/rules/ts-types` - **`eslint-typescript`** rules require type info;
72
+ * `@whitetrefoil/eslint-config/rules/vue2` - **Vue 2.x** official rules;
73
+ * `@whitetrefoil/eslint-config/rules/vue3` - **Vue 3.x** official rules;
144
74
 
145
75
  See Also
146
- ========
76
+ --------
147
77
 
148
78
  1. [ESLint Rules](https://eslint.org/docs/rules/)
149
79
  2. [ESLint Configuring](https://eslint.org/docs/user-guide/configuring)
@@ -154,11 +84,15 @@ See Also
154
84
 
155
85
 
156
86
  Changelog
157
- =========
87
+ ---------
88
+
89
+ ### v0.25.0
90
+
91
+ * Totally refactored in order to simplify usage;
158
92
 
159
93
  ### v0.24.1
160
94
 
161
- * Disable `"prefer-object-has-own"` for TS due to TS hasn't support it yet.
95
+ * Disable `"prefer-object-has-own"` for TS due to TS hasn't support it yet;
162
96
 
163
97
  ### v0.24.0
164
98
 
package/base.js ADDED
@@ -0,0 +1,40 @@
1
+ module.exports = {
2
+ parserOptions: {
3
+ tsconfigRootDir: process.cwd(),
4
+ project : [
5
+ '**/tsconfig.json',
6
+ '!**/node_modules/**',
7
+ ],
8
+ ecmaVersion : 'latest',
9
+ sourceType : 'module',
10
+ ecmaFeatures : {
11
+ globalReturn : true,
12
+ impliedStrict: true,
13
+ },
14
+ },
15
+
16
+ env: {
17
+ es6 : true,
18
+ es2017: true,
19
+ es2020: true,
20
+ es2021: true,
21
+ },
22
+
23
+ extends: [
24
+ './rules/base',
25
+ ],
26
+
27
+ overrides: [
28
+ {
29
+ files : [
30
+ '**/*.ts',
31
+ '**/*.tsx',
32
+ ],
33
+ parser : '@typescript-eslint/parser',
34
+ extends: [
35
+ './rules/ts',
36
+ './rules/ts-types',
37
+ ],
38
+ },
39
+ ],
40
+ }
package/node.js CHANGED
@@ -1,18 +1,56 @@
1
1
  module.exports = {
2
-
3
- root: true,
4
-
5
2
  extends: [
6
- './presets/js',
7
- './presets/node',
3
+ './base',
8
4
  ],
9
5
 
10
6
  overrides: [
11
7
  {
12
- files : ['**/*.ts'],
8
+ files : [
9
+ 'src/**/*.ts',
10
+ ],
11
+ excludedFiles: [
12
+ 'src/**/*.spec.ts',
13
+ ],
14
+ extends: [
15
+ './rules/dependencies',
16
+ ],
17
+ },
18
+
19
+ {
20
+ files: [
21
+ 'src/**/*.spec.ts',
22
+ 'tests/**/*.ts',
23
+ ],
24
+ env : {
25
+ jest: true,
26
+ },
27
+ },
28
+
29
+ {
30
+ files : [
31
+ '*.ts',
32
+ '*.cjs',
33
+ '*.js',
34
+ 'dev/*.ts',
35
+ 'dev/*.cjs',
36
+ 'dev/*.js',
37
+ 'scripts/*.ts',
38
+ 'scripts/*.cjs',
39
+ 'scripts/*.js',
40
+ 'stubapi/*.ts',
41
+ 'stubapi/*.cjs',
42
+ 'stubapi/*.js',
43
+ ],
13
44
  extends: [
14
- './presets/ts',
45
+ './rules/node',
15
46
  ],
47
+ env : {
48
+ node: true,
49
+ },
50
+ rules : {
51
+ 'no-console' : [0],
52
+ 'node/no-process-exit': [0],
53
+ },
16
54
  },
17
55
  ],
18
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitetrefoil/eslint-config",
3
- "version": "0.24.1",
3
+ "version": "0.25.0",
4
4
  "author": "WhiteTrefoil <whitetrefoil@gmail.com>",
5
5
  "license": "Unlicense",
6
6
  "engines": {
@@ -8,8 +8,7 @@
8
8
  },
9
9
  "files": [
10
10
  "*.js",
11
- "presets",
12
- "with-type"
11
+ "rules"
13
12
  ],
14
13
  "dependencies": {
15
14
  "eslint": "^8.5.0",
@@ -1,7 +1,6 @@
1
1
  module.exports = {
2
-
3
2
  extends: [
4
- './index',
3
+ './base',
5
4
  ],
6
5
 
7
6
  rules: {
@@ -2,25 +2,6 @@
2
2
  // @see https://github.com/eslint/eslint/releases
3
3
 
4
4
  module.exports = {
5
-
6
- plugins: [
7
- 'implicit-dependencies',
8
- ],
9
-
10
- parserOptions: {
11
- sourceType: 'module',
12
- // eslint-disable-next-line no-magic-numbers
13
- ecmaVersion : 2021,
14
- ecmaFeatures: {
15
- legacyDecorators: true,
16
- impliedStrict : true,
17
- },
18
- },
19
-
20
- env: {
21
- es6: true,
22
- },
23
-
24
5
  extends: [
25
6
  'eslint:recommended',
26
7
  ],
@@ -150,7 +131,7 @@ module.exports = {
150
131
  'no-implicit-coercion' : [1],
151
132
  'no-implicit-globals' : [2],
152
133
  'no-implied-eval' : [2],
153
- 'no-inline-comments' : [2],
134
+ 'no-inline-comments' : [0],
154
135
  'no-invalid-this' : [2],
155
136
  'no-iterator' : [2],
156
137
  'no-label-var' : [2],
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ plugins: [
3
+ 'implicit-dependencies',
4
+ ],
5
+
6
+ rules: {
7
+ 'implicit-dependencies/no-implicit': [2, { peer: true, optional: true }],
8
+ },
9
+ }
@@ -2,20 +2,13 @@
2
2
  // @see https://github.com/mysticatea/eslint-plugin-node/releases
3
3
 
4
4
  module.exports = {
5
-
6
5
  plugins: ['node'],
7
6
 
8
- env: {
9
- es6 : true,
10
- node: true,
11
- },
12
-
13
7
  extends: [
14
8
  'plugin:node/recommended',
15
9
  ],
16
10
 
17
11
  rules: {
18
-
19
12
  // eslint-plugin-node
20
13
  // ------------------
21
14
  'node/handle-callback-err' : [1],
@@ -37,9 +30,9 @@ module.exports = {
37
30
  'node/process-exit-as-throw' : [2],
38
31
  'node/shebang' : [2],
39
32
 
40
- 'node/no-deprecated-api': [2],
33
+ 'node/no-deprecated-api': [0],
41
34
 
42
- 'node/callback-return' : [1],
35
+ 'node/callback-return' : [0],
43
36
  'node/exports-style' : [2],
44
37
  'node/file-extension-in-import' : [0],
45
38
  'node/global-require' : [1],
@@ -2,16 +2,6 @@
2
2
  // @see https://github.com/yannickcr/eslint-plugin-react/blob/master/CHANGELOG.md
3
3
 
4
4
  module.exports = {
5
- settings: {
6
- react: {
7
- version: 'detect',
8
- },
9
- },
10
-
11
- parserOptions: {
12
- jsx: true,
13
- },
14
-
15
5
  plugins: [
16
6
  'react',
17
7
  'react-hooks',
@@ -1,7 +1,6 @@
1
1
  module.exports = {
2
-
3
2
  extends: [
4
- './index',
3
+ './ts',
5
4
  ],
6
5
 
7
6
  rules: {
@@ -4,6 +4,8 @@
4
4
  // These are rules need type info which will be much slower
5
5
 
6
6
  module.exports = {
7
+ plugins: ['@typescript-eslint'],
8
+
7
9
  rules: {
8
10
  '@typescript-eslint/await-thenable' : [1],
9
11
  '@typescript-eslint/consistent-type-exports' : [1],
@@ -4,17 +4,6 @@
4
4
  // These are rules don't need type info
5
5
 
6
6
  module.exports = {
7
-
8
- parser: '@typescript-eslint/parser',
9
-
10
- parserOptions: {
11
- parser: '@typescript-eslint/parser',
12
- },
13
-
14
- env: {
15
- es6: true,
16
- },
17
-
18
7
  plugins: ['@typescript-eslint'],
19
8
 
20
9
  extends: [
@@ -2,7 +2,6 @@
2
2
  // @see https://eslint.vuejs.org/user-guide/
3
3
 
4
4
  module.exports = {
5
-
6
5
  parser: 'vue-eslint-parser',
7
6
 
8
7
  extends: [
@@ -2,7 +2,6 @@
2
2
  // @see https://eslint.vuejs.org/user-guide/
3
3
 
4
4
  module.exports = {
5
-
6
5
  parser: 'vue-eslint-parser',
7
6
 
8
7
  extends: [
package/web-others.js ADDED
@@ -0,0 +1,90 @@
1
+ module.exports = {
2
+ parserOptions: {
3
+ tsconfigRootDir: process.cwd(),
4
+ project : [
5
+ '**/tsconfig.json',
6
+ '!**/node_modules/**',
7
+ ],
8
+ ecmaVersion : 'latest',
9
+ sourceType : 'module',
10
+ ecmaFeatures : {
11
+ globalReturn : true,
12
+ impliedStrict: true,
13
+ },
14
+ },
15
+
16
+ env: {
17
+ es6 : true,
18
+ es2017: true,
19
+ es2020: true,
20
+ es2021: true,
21
+ },
22
+
23
+ extends: [
24
+ './rules/base',
25
+ ],
26
+
27
+ overrides: [
28
+ {
29
+ files : [
30
+ '**/*.ts',
31
+ '**/*.tsx',
32
+ ],
33
+ parser : '@typescript-eslint/parser',
34
+ extends: [
35
+ './rules/ts',
36
+ './rules/ts-types',
37
+ ],
38
+ },
39
+
40
+ {
41
+ files : [
42
+ 'src/**/*.ts',
43
+ 'src/**/*.tsx',
44
+ ],
45
+ excludedFiles: [
46
+ 'src/**/*.spec.ts',
47
+ ],
48
+ extends: [
49
+ './rules/dependencies',
50
+ ],
51
+ },
52
+
53
+ {
54
+ files: [
55
+ 'src/**/*.spec.ts',
56
+ 'tests/**/*.ts',
57
+ ],
58
+ env : {
59
+ jest: true,
60
+ },
61
+ },
62
+
63
+ {
64
+ files : [
65
+ '*.ts',
66
+ '*.cjs',
67
+ '*.js',
68
+ 'dev/*.ts',
69
+ 'dev/*.cjs',
70
+ 'dev/*.js',
71
+ 'scripts/*.ts',
72
+ 'scripts/*.cjs',
73
+ 'scripts/*.js',
74
+ 'stubapi/*.ts',
75
+ 'stubapi/*.cjs',
76
+ 'stubapi/*.js',
77
+ ],
78
+ extends: [
79
+ './rules/node',
80
+ ],
81
+ env : {
82
+ node: true,
83
+ },
84
+ rules : {
85
+ 'no-console' : [0],
86
+ 'node/no-process-exit': [0],
87
+ },
88
+ },
89
+ ],
90
+ }
package/web-react.js ADDED
@@ -0,0 +1,97 @@
1
+ module.exports = {
2
+ parserOptions: {
3
+ tsconfigRootDir: process.cwd(),
4
+ project : [
5
+ '**/tsconfig.json',
6
+ '!**/node_modules/**',
7
+ ],
8
+ ecmaVersion : 'latest',
9
+ sourceType : 'module',
10
+ ecmaFeatures : {
11
+ globalReturn : true,
12
+ impliedStrict: true,
13
+ },
14
+ },
15
+
16
+ settings: {
17
+ react: {
18
+ version: 'detect',
19
+ },
20
+ },
21
+
22
+ env: {
23
+ es6 : true,
24
+ es2017: true,
25
+ es2020: true,
26
+ es2021: true,
27
+ },
28
+
29
+ extends: [
30
+ './rules/base',
31
+ ],
32
+
33
+ overrides: [
34
+ {
35
+ files : [
36
+ '**/*.ts',
37
+ '**/*.tsx',
38
+ ],
39
+ parser : '@typescript-eslint/parser',
40
+ extends: [
41
+ './rules/ts',
42
+ './rules/ts-types',
43
+ ],
44
+ },
45
+
46
+ {
47
+ files : [
48
+ 'src/**/*.ts',
49
+ 'src/**/*.tsx',
50
+ ],
51
+ excludedFiles: [
52
+ 'src/**/*.spec.ts',
53
+ ],
54
+ extends: [
55
+ './rules/react',
56
+ './rules/dependencies',
57
+ ],
58
+ },
59
+
60
+ {
61
+ files: [
62
+ 'src/**/*.spec.ts',
63
+ 'tests/**/*.ts',
64
+ ],
65
+ env : {
66
+ jest: true,
67
+ },
68
+ },
69
+
70
+ {
71
+ files : [
72
+ '*.ts',
73
+ '*.cjs',
74
+ '*.js',
75
+ 'dev/*.ts',
76
+ 'dev/*.cjs',
77
+ 'dev/*.js',
78
+ 'scripts/*.ts',
79
+ 'scripts/*.cjs',
80
+ 'scripts/*.js',
81
+ 'stubapi/*.ts',
82
+ 'stubapi/*.cjs',
83
+ 'stubapi/*.js',
84
+ ],
85
+ extends: [
86
+ './rules/node',
87
+ ],
88
+ env : {
89
+ node: true,
90
+ },
91
+ rules : {
92
+ 'no-console' : [0],
93
+ 'node/no-process-exit': [0],
94
+ },
95
+ },
96
+ ],
97
+ }