@keeex/eslint-config 1.7.2 → 1.8.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 +4 -0
- package/package.json +6 -2
- package/src/config/import.js +1 -7
- package/src/config/mocha.js +8 -1
- package/src/config/typescript.js +136 -17
- package/src/index.js +5 -3
package/README.md
CHANGED
|
@@ -138,6 +138,7 @@ the following properties:
|
|
|
138
138
|
"test/**/*.js",
|
|
139
139
|
],
|
|
140
140
|
expectHelper: true,
|
|
141
|
+
chai: true,
|
|
141
142
|
}
|
|
142
143
|
```
|
|
143
144
|
|
|
@@ -157,4 +158,7 @@ If React Hooks is enabled, `eslint-plugin-react-hooks` must be installed.
|
|
|
157
158
|
If React Native is enabled, `eslint-plugin-react-native` must be installed.
|
|
158
159
|
Promise support requires `eslint-plugin-promise`.
|
|
159
160
|
If mocha is used as the testsuite, `eslint-plugin-mocha` must be installed.
|
|
161
|
+
If chai is used with mocha, `eslint-plugin-chai-friendly` must be installed.
|
|
160
162
|
Import support requires `eslint-plugin-import`.
|
|
163
|
+
|
|
164
|
+
If both import and typescript is used, `eslint-import-resolver-typescript` is needed.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keeex/eslint-config",
|
|
3
3
|
"description": "Common eslint configuration",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.8.0",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"src/**/*.js"
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
"eslint-plugin-promise": "6.x",
|
|
33
33
|
"eslint-plugin-react": "7.x",
|
|
34
34
|
"eslint-plugin-react-hooks": "4.x",
|
|
35
|
-
"eslint-plugin-react-native": "4.x"
|
|
35
|
+
"eslint-plugin-react-native": "4.x",
|
|
36
|
+
"eslint-import-resolver-typescript": "2.x"
|
|
36
37
|
},
|
|
37
38
|
"peerDependenciesMeta": {
|
|
38
39
|
"eslint": {
|
|
@@ -61,6 +62,9 @@
|
|
|
61
62
|
},
|
|
62
63
|
"eslint-plugin-mocha": {
|
|
63
64
|
"optional": true
|
|
65
|
+
},
|
|
66
|
+
"eslint-import-resolver-typescript": {
|
|
67
|
+
"optional": true
|
|
64
68
|
}
|
|
65
69
|
},
|
|
66
70
|
"publishConfig": {
|
package/src/config/import.js
CHANGED
|
@@ -27,13 +27,7 @@ const DEFAULT_CYCLE_DEPTH = 3;
|
|
|
27
27
|
|
|
28
28
|
module.exports = {
|
|
29
29
|
plugins: ["import"],
|
|
30
|
-
extendsBase:
|
|
31
|
-
const result = ["plugin:import/recommended"];
|
|
32
|
-
if (allOptions.typescript) {
|
|
33
|
-
result.push("plugin:import/typescript");
|
|
34
|
-
}
|
|
35
|
-
return result;
|
|
36
|
-
},
|
|
30
|
+
extendsBase: ["plugin:import/recommended"],
|
|
37
31
|
rules: presetConfig => {
|
|
38
32
|
let importDepth;
|
|
39
33
|
if (
|
package/src/config/mocha.js
CHANGED
|
@@ -8,8 +8,13 @@ module.exports = {
|
|
|
8
8
|
"tests/**/*.js",
|
|
9
9
|
"test/**/*.ts",
|
|
10
10
|
"test/**/*.js",
|
|
11
|
+
"**/tests/**/*.ts",
|
|
12
|
+
"**/tests/**/*.js",
|
|
13
|
+
"**/test/**/*.ts",
|
|
14
|
+
"**/test/**/*.js",
|
|
11
15
|
],
|
|
12
16
|
expectHelper: true,
|
|
17
|
+
mocha: true,
|
|
13
18
|
};
|
|
14
19
|
if (typeof presetConfig === "object") {
|
|
15
20
|
config = {
|
|
@@ -17,10 +22,12 @@ module.exports = {
|
|
|
17
22
|
...presetConfig,
|
|
18
23
|
};
|
|
19
24
|
}
|
|
25
|
+
const extendsBase = ["plugin:mocha/recommended"];
|
|
26
|
+
if (config.chai) extendsBase.push("plugin:chai-friendly/recommended");
|
|
20
27
|
const mochaOverride = {
|
|
21
28
|
files: config.fileFilter,
|
|
22
29
|
env: {mocha: true},
|
|
23
|
-
extendsBase
|
|
30
|
+
extendsBase,
|
|
24
31
|
rules: {
|
|
25
32
|
"mocha/handle-done-callback": ["error", {"ignoreSkipped": true}],
|
|
26
33
|
"mocha/no-mocha-arrows": "off",
|
package/src/config/typescript.js
CHANGED
|
@@ -44,7 +44,109 @@ const rulesBase = {
|
|
|
44
44
|
"error",
|
|
45
45
|
indentDepth,
|
|
46
46
|
],
|
|
47
|
-
"@typescript-eslint/member-ordering": [
|
|
47
|
+
"@typescript-eslint/member-ordering": [
|
|
48
|
+
"warn",
|
|
49
|
+
{
|
|
50
|
+
"default": [
|
|
51
|
+
// Index signature
|
|
52
|
+
"signature",
|
|
53
|
+
|
|
54
|
+
// Fields
|
|
55
|
+
"public-static-field",
|
|
56
|
+
"protected-static-field",
|
|
57
|
+
"private-static-field",
|
|
58
|
+
|
|
59
|
+
"public-decorated-field",
|
|
60
|
+
"protected-decorated-field",
|
|
61
|
+
"private-decorated-field",
|
|
62
|
+
|
|
63
|
+
"public-instance-field",
|
|
64
|
+
"protected-instance-field",
|
|
65
|
+
"private-instance-field",
|
|
66
|
+
|
|
67
|
+
"public-abstract-field",
|
|
68
|
+
"protected-abstract-field",
|
|
69
|
+
"private-abstract-field",
|
|
70
|
+
|
|
71
|
+
"public-field",
|
|
72
|
+
"protected-field",
|
|
73
|
+
"private-field",
|
|
74
|
+
|
|
75
|
+
"static-field",
|
|
76
|
+
"instance-field",
|
|
77
|
+
"abstract-field",
|
|
78
|
+
|
|
79
|
+
"decorated-field",
|
|
80
|
+
|
|
81
|
+
"field",
|
|
82
|
+
|
|
83
|
+
// Constructors
|
|
84
|
+
"public-constructor",
|
|
85
|
+
"protected-constructor",
|
|
86
|
+
"private-constructor",
|
|
87
|
+
|
|
88
|
+
"constructor",
|
|
89
|
+
|
|
90
|
+
// Getters/Setters
|
|
91
|
+
["public-static-get", "public-static-set"],
|
|
92
|
+
["protected-static-get", "protected-static-set"],
|
|
93
|
+
["private-static-get", "private-static-set"],
|
|
94
|
+
|
|
95
|
+
["public-decorated-get", "public-decorated-set"],
|
|
96
|
+
["protected-decorated-get", "protected-decorated-set"],
|
|
97
|
+
["private-decorated-get", "private-decorated-set"],
|
|
98
|
+
|
|
99
|
+
["public-instance-get", "public-instance-set"],
|
|
100
|
+
["protected-instance-get", "protected-instance-set"],
|
|
101
|
+
["private-instance-get", "private-instance-set"],
|
|
102
|
+
|
|
103
|
+
["public-abstract-get", "public-abstract-set"],
|
|
104
|
+
["protected-abstract-get", "protected-abstract-set"],
|
|
105
|
+
["private-abstract-get", "private-abstract-set"],
|
|
106
|
+
|
|
107
|
+
["public-get", "public-set"],
|
|
108
|
+
["protected-get", "protected-set"],
|
|
109
|
+
["private-get", "private-set"],
|
|
110
|
+
|
|
111
|
+
["static-get", "static-set"],
|
|
112
|
+
["instance-get", "instance-set"],
|
|
113
|
+
["abstract-get", "abstract-set"],
|
|
114
|
+
|
|
115
|
+
["decorated-get", "decorated-set"],
|
|
116
|
+
|
|
117
|
+
["get", "set"],
|
|
118
|
+
|
|
119
|
+
// Methods
|
|
120
|
+
"public-static-method",
|
|
121
|
+
"protected-static-method",
|
|
122
|
+
"private-static-method",
|
|
123
|
+
|
|
124
|
+
"public-decorated-method",
|
|
125
|
+
"protected-decorated-method",
|
|
126
|
+
"private-decorated-method",
|
|
127
|
+
|
|
128
|
+
"public-instance-method",
|
|
129
|
+
"protected-instance-method",
|
|
130
|
+
"private-instance-method",
|
|
131
|
+
|
|
132
|
+
"public-abstract-method",
|
|
133
|
+
"protected-abstract-method",
|
|
134
|
+
"private-abstract-method",
|
|
135
|
+
|
|
136
|
+
"public-method",
|
|
137
|
+
"protected-method",
|
|
138
|
+
"private-method",
|
|
139
|
+
|
|
140
|
+
"static-method",
|
|
141
|
+
"instance-method",
|
|
142
|
+
"abstract-method",
|
|
143
|
+
|
|
144
|
+
"decorated-method",
|
|
145
|
+
|
|
146
|
+
"method",
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
],
|
|
48
150
|
"no-array-constructor": "off",
|
|
49
151
|
"@typescript-eslint/no-array-constructor": ["warn"],
|
|
50
152
|
"@typescript-eslint/no-dupe-class-members": ["error"],
|
|
@@ -154,28 +256,45 @@ module.exports = {
|
|
|
154
256
|
}
|
|
155
257
|
return null;
|
|
156
258
|
},
|
|
157
|
-
extendsBase: presetOptions => {
|
|
259
|
+
extendsBase: (presetOptions, allOptions) => {
|
|
158
260
|
const typescriptBase = [
|
|
159
261
|
"plugin:@typescript-eslint/eslint-recommended",
|
|
160
262
|
"plugin:@typescript-eslint/recommended",
|
|
161
263
|
"plugin:@typescript-eslint/recommended-requiring-type-checking",
|
|
162
264
|
];
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
]
|
|
168
|
-
|
|
169
|
-
return
|
|
265
|
+
const typeExtends = useTypes(presetOptions)
|
|
266
|
+
? extendsBaseType
|
|
267
|
+
: [];
|
|
268
|
+
const importExtends = allOptions["import"]
|
|
269
|
+
? ["plugin:import/typescript"]
|
|
270
|
+
: [];
|
|
271
|
+
return [
|
|
272
|
+
...typescriptBase,
|
|
273
|
+
...typeExtends,
|
|
274
|
+
...importExtends,
|
|
275
|
+
];
|
|
170
276
|
},
|
|
171
|
-
rules: presetOptions => {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
277
|
+
rules: (presetOptions, allOptions) => {
|
|
278
|
+
// There seem to be no way for now to have import understand that ".js" imports should refer
|
|
279
|
+
// to ".ts" files.
|
|
280
|
+
// Either it complains about needing the ".ts" suffix (which is wrong) or it enforces having
|
|
281
|
+
// an extension, but doesn't actually resolve the file (since we disable the ts-specific
|
|
282
|
+
// resolver).
|
|
283
|
+
// If this change in the future, restore full ts-resolver support from import plugin.
|
|
284
|
+
const importOverride = allOptions.import
|
|
285
|
+
? {
|
|
286
|
+
"import/no-unresolved": "off",
|
|
287
|
+
"import/no-cycle": "off",
|
|
288
|
+
}
|
|
289
|
+
: undefined;
|
|
290
|
+
const typesOverride = useTypes(presetOptions)
|
|
291
|
+
? rulesType
|
|
292
|
+
: undefined;
|
|
293
|
+
return {
|
|
294
|
+
...rulesBase,
|
|
295
|
+
...typesOverride,
|
|
296
|
+
...importOverride,
|
|
297
|
+
};
|
|
179
298
|
},
|
|
180
299
|
},
|
|
181
300
|
],
|
package/src/index.js
CHANGED
|
@@ -118,8 +118,9 @@ const addRules = (
|
|
|
118
118
|
config,
|
|
119
119
|
presetRules,
|
|
120
120
|
presetConfig,
|
|
121
|
+
allOptions,
|
|
121
122
|
) => {
|
|
122
|
-
const newRules = applyConfig(presetRules, presetConfig);
|
|
123
|
+
const newRules = applyConfig(presetRules, presetConfig, allOptions);
|
|
123
124
|
if (!newRules) return;
|
|
124
125
|
|
|
125
126
|
if (!config.rules) {
|
|
@@ -158,9 +159,10 @@ const addSettings = (
|
|
|
158
159
|
config,
|
|
159
160
|
presetSettings,
|
|
160
161
|
presetConfig,
|
|
162
|
+
allOptions,
|
|
161
163
|
) => {
|
|
162
164
|
const newSettings = typeof presetSettings === "function"
|
|
163
|
-
? presetSettings(presetConfig)
|
|
165
|
+
? presetSettings(presetConfig, allOptions)
|
|
164
166
|
: presetSettings;
|
|
165
167
|
if (!newSettings) return;
|
|
166
168
|
|
|
@@ -225,7 +227,7 @@ const mergePreset = (
|
|
|
225
227
|
) => {
|
|
226
228
|
setParser(config, presetDef.parser, presetConfig);
|
|
227
229
|
addParserOptions(config, presetDef.parserOptions, presetConfig);
|
|
228
|
-
addSettings(config, presetDef.settings, presetConfig);
|
|
230
|
+
addSettings(config, presetDef.settings, presetConfig, allOptions);
|
|
229
231
|
addEnvs(config, presetDef.env, presetConfig);
|
|
230
232
|
addPlugins(config, presetDef.plugins, presetConfig);
|
|
231
233
|
addExtends(config, presetDef.extendsBase, presetConfig, allOptions);
|