eslint-config-webpack 4.2.2 → 4.3.1
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/configs/index.js +4 -0
- package/configs/markdown.js +2 -0
- package/configs/react.js +26 -0
- package/configs/typescript.js +17 -0
- package/configs/utils/extensions.js +2 -2
- package/configs/webpack-special.js +9 -0
- package/configs.js +21 -14
- package/package.json +8 -1
- package/plugins/webpack/index.js +45 -0
- package/plugins/webpack/rules/require-license-comment.js +59 -0
package/configs/index.js
CHANGED
|
@@ -4,8 +4,10 @@ import jestConfig from "./jest.js";
|
|
|
4
4
|
import markdownConfig from "./markdown.js";
|
|
5
5
|
import nodeConfig from "./node.js";
|
|
6
6
|
import packageJSON from "./package-json.js";
|
|
7
|
+
import reactConfig from "./react.js";
|
|
7
8
|
import stylisticConfig from "./stylistic.js";
|
|
8
9
|
import typescriptConfig from "./typescript.js";
|
|
10
|
+
import webpackSpecial from "./webpack-special.js";
|
|
9
11
|
|
|
10
12
|
const configs = {
|
|
11
13
|
...browserConfig,
|
|
@@ -15,7 +17,9 @@ const configs = {
|
|
|
15
17
|
...nodeConfig,
|
|
16
18
|
...stylisticConfig,
|
|
17
19
|
...typescriptConfig,
|
|
20
|
+
...reactConfig,
|
|
18
21
|
...packageJSON,
|
|
22
|
+
...webpackSpecial,
|
|
19
23
|
};
|
|
20
24
|
|
|
21
25
|
export default configs;
|
package/configs/markdown.js
CHANGED
package/configs/react.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import reactPlugin from "eslint-plugin-react";
|
|
2
|
+
|
|
3
|
+
const { recommended, "jsx-runtime": jsxRuntime } = reactPlugin.configs.flat;
|
|
4
|
+
|
|
5
|
+
const recommendedReactConfig = {
|
|
6
|
+
...reactPlugin.configs.flat.recommended,
|
|
7
|
+
files: ["**/*.{jsx,tsx}"],
|
|
8
|
+
settings: {
|
|
9
|
+
react: {
|
|
10
|
+
version: "detect",
|
|
11
|
+
defaultVersion: "19",
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
languageOptions: {
|
|
15
|
+
...recommended.languageOptions,
|
|
16
|
+
...jsxRuntime.languageOptions,
|
|
17
|
+
},
|
|
18
|
+
rules: {
|
|
19
|
+
...recommended.rules,
|
|
20
|
+
...jsxRuntime.rules,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default {
|
|
25
|
+
"react/recommended": recommendedReactConfig,
|
|
26
|
+
};
|
package/configs/typescript.js
CHANGED
|
@@ -274,6 +274,8 @@ async function getTypescriptJSDocRecommendedConfig() {
|
|
|
274
274
|
};
|
|
275
275
|
}
|
|
276
276
|
|
|
277
|
+
const allExtensions = [...typescriptExtensions, ...javascriptExtensions];
|
|
278
|
+
|
|
277
279
|
/**
|
|
278
280
|
* @returns {Promise<Record<string, string>>} config
|
|
279
281
|
*/
|
|
@@ -317,6 +319,18 @@ async function getTypescriptRecommendedConfig() {
|
|
|
317
319
|
plugins: {
|
|
318
320
|
...baseConfig.plugins,
|
|
319
321
|
},
|
|
322
|
+
settings: {
|
|
323
|
+
"import/extensions": allExtensions,
|
|
324
|
+
"import/external-module-folders": ["node_modules", "node_modules/@types"],
|
|
325
|
+
"import/parsers": {
|
|
326
|
+
"@typescript-eslint/parser": typescriptExtensions,
|
|
327
|
+
},
|
|
328
|
+
"import/resolver": {
|
|
329
|
+
node: {
|
|
330
|
+
extensions: allExtensions,
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
},
|
|
320
334
|
rules: {
|
|
321
335
|
...eslintRecommendedConfig.rules,
|
|
322
336
|
...recommendedConfig.rules,
|
|
@@ -721,6 +735,9 @@ async function getTypescriptRecommendedConfig() {
|
|
|
721
735
|
// No need
|
|
722
736
|
// "use-unknown-in-catch-callback-variable": "error",
|
|
723
737
|
|
|
738
|
+
// TypeScript compilation already ensures that named imports exist in the referenced module
|
|
739
|
+
"import/named": "off",
|
|
740
|
+
|
|
724
741
|
// TypeScript handles this for us
|
|
725
742
|
"import/no-unresolved": "off",
|
|
726
743
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const javascriptExtensions = [".js", ".
|
|
2
|
-
const typescriptExtensions = [".ts", ".
|
|
1
|
+
const javascriptExtensions = [".js", ".jsx", ".cjs", ".mjs"];
|
|
2
|
+
const typescriptExtensions = [".ts", ".tsx", ".cts", ".mts"];
|
|
3
3
|
const allExtensions = [...javascriptExtensions, ...typescriptExtensions];
|
|
4
4
|
|
|
5
5
|
export { allExtensions, javascriptExtensions, typescriptExtensions };
|
package/configs.js
CHANGED
|
@@ -216,20 +216,6 @@ function getTypescriptJSdocConfig() {
|
|
|
216
216
|
* @returns {Promise<Record<string, string>>} config
|
|
217
217
|
*/
|
|
218
218
|
function getTypescriptConfig() {
|
|
219
|
-
if (packageJson === null) {
|
|
220
|
-
return [];
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const dependencies = packageJson.dependencies || [];
|
|
224
|
-
const devDependencies = packageJson.devDependencies || [];
|
|
225
|
-
|
|
226
|
-
if (
|
|
227
|
-
typeof dependencies.typescript === "undefined" &&
|
|
228
|
-
typeof devDependencies.typescript === "undefined"
|
|
229
|
-
) {
|
|
230
|
-
return [];
|
|
231
|
-
}
|
|
232
|
-
|
|
233
219
|
const tsconfigJson = getJsonFile("tsconfig.json");
|
|
234
220
|
|
|
235
221
|
const isNoEmitEnabled =
|
|
@@ -262,6 +248,23 @@ function getTypescriptConfig() {
|
|
|
262
248
|
];
|
|
263
249
|
}
|
|
264
250
|
|
|
251
|
+
/**
|
|
252
|
+
* @returns {Promise<Record<string, string>>} config
|
|
253
|
+
*/
|
|
254
|
+
function getReactConfig() {
|
|
255
|
+
if (packageJson === null) {
|
|
256
|
+
return [];
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const dependencies = packageJson.dependencies || [];
|
|
260
|
+
const devDependencies = packageJson.devDependencies || [];
|
|
261
|
+
|
|
262
|
+
return typeof dependencies.react !== "undefined" ||
|
|
263
|
+
typeof devDependencies.react !== "undefined"
|
|
264
|
+
? configs["react/recommended"]
|
|
265
|
+
: [];
|
|
266
|
+
}
|
|
267
|
+
|
|
265
268
|
/**
|
|
266
269
|
* @returns {Promise<Record<string, string>>} config
|
|
267
270
|
*/
|
|
@@ -282,6 +285,7 @@ function getJestConfig() {
|
|
|
282
285
|
const javascriptConfig = getJavascriptConfig();
|
|
283
286
|
const typescriptJSDocConfig = getTypescriptJSdocConfig();
|
|
284
287
|
const typescriptConfig = getTypescriptConfig();
|
|
288
|
+
const reactConfig = getReactConfig();
|
|
285
289
|
const jestConfig = getJestConfig();
|
|
286
290
|
|
|
287
291
|
configs.recommended = [
|
|
@@ -292,6 +296,7 @@ configs.recommended = [
|
|
|
292
296
|
javascriptConfig,
|
|
293
297
|
typescriptJSDocConfig,
|
|
294
298
|
typescriptConfig,
|
|
299
|
+
reactConfig,
|
|
295
300
|
jestConfig,
|
|
296
301
|
configs["markdown/recommended"],
|
|
297
302
|
configs["stylistic/recommended"],
|
|
@@ -304,6 +309,7 @@ configs["recommended-module"] = [
|
|
|
304
309
|
javascriptConfig,
|
|
305
310
|
typescriptJSDocConfig,
|
|
306
311
|
typescriptConfig,
|
|
312
|
+
reactConfig,
|
|
307
313
|
jestConfig,
|
|
308
314
|
configs["markdown/recommended"],
|
|
309
315
|
configs["stylistic/recommended"],
|
|
@@ -316,6 +322,7 @@ configs["recommended-commonjs"] = [
|
|
|
316
322
|
javascriptConfig,
|
|
317
323
|
typescriptJSDocConfig,
|
|
318
324
|
typescriptConfig,
|
|
325
|
+
reactConfig,
|
|
319
326
|
jestConfig,
|
|
320
327
|
configs["markdown/recommended"],
|
|
321
328
|
configs["stylistic/recommended"],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-config-webpack",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.1",
|
|
4
4
|
"description": "Provides Webpack's eslint rules as an extensible shared config",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -53,10 +53,13 @@
|
|
|
53
53
|
"eslint-plugin-jsdoc": "^51.2.3",
|
|
54
54
|
"eslint-plugin-n": "^17.20.0",
|
|
55
55
|
"eslint-plugin-prettier": "^5.5.0",
|
|
56
|
+
"eslint-plugin-react": "^7.37.5",
|
|
56
57
|
"eslint-plugin-unicorn": "^59.0.1",
|
|
57
58
|
"globals": "^16.2.0",
|
|
58
59
|
"jest": "^30.0.2",
|
|
59
60
|
"prettier": "^3.6.0",
|
|
61
|
+
"react": "^19.1.0",
|
|
62
|
+
"react-dom": "^19.1.0",
|
|
60
63
|
"standard-version": "^9.5.0",
|
|
61
64
|
"typescript": "^5.8.3",
|
|
62
65
|
"typescript-eslint": "^8.35.0"
|
|
@@ -72,6 +75,7 @@
|
|
|
72
75
|
"eslint-plugin-jsdoc": ">= 50.7.1",
|
|
73
76
|
"eslint-plugin-n": ">= 17.19.0",
|
|
74
77
|
"eslint-plugin-prettier": ">= 5.4.1",
|
|
78
|
+
"eslint-plugin-react": ">= 7.37.5",
|
|
75
79
|
"eslint-plugin-unicorn": ">= 59.0.1",
|
|
76
80
|
"globals": ">= 16.2.0",
|
|
77
81
|
"prettier": ">= 3.5.3",
|
|
@@ -88,6 +92,9 @@
|
|
|
88
92
|
"eslint-plugin-jsdoc": {
|
|
89
93
|
"optional": true
|
|
90
94
|
},
|
|
95
|
+
"eslint-plugin-react": {
|
|
96
|
+
"optional": true
|
|
97
|
+
},
|
|
91
98
|
"eslint-plugin-n": {
|
|
92
99
|
"optional": true
|
|
93
100
|
},
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { allExtensions } from "../../configs/utils/extensions.js";
|
|
3
|
+
import { rule as requireLicenseComment } from "./rules/require-license-comment.js";
|
|
4
|
+
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
|
|
7
|
+
const { version } = require("../../package.json");
|
|
8
|
+
|
|
9
|
+
const rules = {
|
|
10
|
+
"require-license-comment": requireLicenseComment,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const recommendedRules = {
|
|
14
|
+
...Object.fromEntries(
|
|
15
|
+
Object.entries(rules)
|
|
16
|
+
.filter(([, rule]) => rule.meta.docs?.recommended)
|
|
17
|
+
.map(([name]) => [`webpack/${name}`, "error"]),
|
|
18
|
+
),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const configs = {
|
|
22
|
+
recommended: {
|
|
23
|
+
name: "webpack/recommended",
|
|
24
|
+
files: [`**/*.{${allExtensions.map((item) => item.slice(1)).join(",")}}`],
|
|
25
|
+
plugins: {
|
|
26
|
+
get webpack() {
|
|
27
|
+
// eslint-disable-next-line no-use-before-define
|
|
28
|
+
return plugin;
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
rules: recommendedRules,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const plugin = {
|
|
36
|
+
configs,
|
|
37
|
+
meta: {
|
|
38
|
+
version,
|
|
39
|
+
},
|
|
40
|
+
rules,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export { configs, rules };
|
|
44
|
+
|
|
45
|
+
export default plugin;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @type {import("eslint").Rule} rule
|
|
3
|
+
*/
|
|
4
|
+
export const rule = {
|
|
5
|
+
create(context) {
|
|
6
|
+
const sourceCode = context.getSourceCode();
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
"Program:exit"(program) {
|
|
10
|
+
const comments = sourceCode.getAllComments();
|
|
11
|
+
const licenseComment = comments.find(
|
|
12
|
+
(comment) =>
|
|
13
|
+
comment.type === "Block" &&
|
|
14
|
+
/\n\s*MIT License http:\/\/www\.opensource\.org\/licenses\/mit-license\.php\n\s*(?:(Authors? .+)\n)?\s*/g.test(
|
|
15
|
+
comment.value,
|
|
16
|
+
),
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
if (!licenseComment) {
|
|
20
|
+
context.report({
|
|
21
|
+
loc: program.loc,
|
|
22
|
+
message: "Expected license comment.",
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const afterComment = sourceCode.text[licenseComment.end];
|
|
29
|
+
|
|
30
|
+
if (afterComment !== "\n") {
|
|
31
|
+
context.report({
|
|
32
|
+
loc: licenseComment.loc,
|
|
33
|
+
message: "Expected newline after license comment.",
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const afterAfterComment = sourceCode.text[licenseComment.end + 1];
|
|
40
|
+
|
|
41
|
+
if (afterAfterComment !== "\n") {
|
|
42
|
+
context.report({
|
|
43
|
+
loc: licenseComment.loc,
|
|
44
|
+
message: "Expected newline after license comment.",
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
meta: {
|
|
51
|
+
docs: {
|
|
52
|
+
category: "Best Practices",
|
|
53
|
+
description: "Require license comment",
|
|
54
|
+
recommended: true,
|
|
55
|
+
},
|
|
56
|
+
fixable: "code",
|
|
57
|
+
type: "layout",
|
|
58
|
+
},
|
|
59
|
+
};
|