eslint-config-webpack 4.6.1 → 4.6.3

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.
@@ -2,7 +2,8 @@ import javascriptConfig from "@eslint/js";
2
2
  import importPlugin from "eslint-plugin-import";
3
3
  import unicornPlugin from "eslint-plugin-unicorn";
4
4
  import globals from "globals";
5
- import { allExtensions } from "./utils/extensions.js";
5
+ import { allExtensions, javascriptExtensions } from "./utils/extensions.js";
6
+ import isTypescriptInstalled from "./utils/is-typescript-installed.js";
6
7
 
7
8
  const possibleProblems = {
8
9
  "array-callback-return": [
@@ -1182,20 +1183,23 @@ const importRules = {
1182
1183
  * @returns {Record<string, string | number>} config
1183
1184
  */
1184
1185
  function getConfig(esVersion) {
1186
+ const extensions = isTypescriptInstalled()
1187
+ ? allExtensions
1188
+ : javascriptExtensions;
1185
1189
  const config = {
1186
1190
  ...javascriptConfig.configs.recommended,
1187
1191
  name: `javascript/es${esVersion}`,
1188
- files: [`**/*.{${allExtensions.map((item) => item.slice(1)).join(",")}}`],
1192
+ files: [`**/*.{${extensions.map((item) => item.slice(1)).join(",")}}`],
1189
1193
  ignores: ["**/*.d.ts"],
1190
1194
  settings: {
1191
- "import/extensions": allExtensions,
1195
+ "import/extensions": extensions,
1192
1196
  "import/ignore": [
1193
1197
  "eslint-plugin-.*",
1194
1198
  "\\.(coffee|scss|css|less|hbs|svg|md|jpg|jpeg|png|gif|webp|avif)$",
1195
1199
  ],
1196
1200
  "import/resolver": {
1197
1201
  node: {
1198
- extensions: [...allExtensions],
1202
+ extensions: [...extensions],
1199
1203
  },
1200
1204
  },
1201
1205
  },
@@ -1,3 +1,5 @@
1
+ import isTypescriptInstalled from "./utils/is-typescript-installed.js";
2
+
1
3
  /**
2
4
  * @returns {Promise<Record<string, string>>} config
3
5
  */
@@ -22,7 +24,9 @@ async function getMarkdownRecommendedConfig() {
22
24
  },
23
25
  {
24
26
  name: "markdown/code-blocks/js",
25
- files: ["**/*.md/*.js", "**/*.md/*.ts"],
27
+ files: isTypescriptInstalled()
28
+ ? ["**/*.md/*.js", "**/*.md/*.ts"]
29
+ : ["**/*.md/*.js"],
26
30
  languageOptions: {
27
31
  sourceType: "module",
28
32
  ecmaVersion: "latest",
package/configs/node.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import importPlugin from "eslint-plugin-import";
2
2
  import globals from "globals";
3
+ import isTypescriptInstalled from "./utils/is-typescript-installed.js";
3
4
 
4
5
  const commonRules = {
5
6
  // No need
@@ -263,6 +264,16 @@ async function getDirtyConfig() {
263
264
 
264
265
  const dirtyConfig = await getDirtyConfig();
265
266
 
267
+ const jsExtensions = isTypescriptInstalled()
268
+ ? ["**/*.{js,jsx,ts,tsx}"]
269
+ : ["**/*.{js,jsx}"];
270
+ const cjsExtensions = isTypescriptInstalled()
271
+ ? ["**/*.{cjs,cts}"]
272
+ : ["**/*.{cjs}"];
273
+ const mjsExtensions = isTypescriptInstalled()
274
+ ? ["**/*.{mjs,mts}"]
275
+ : ["**/*.{mjs}"];
276
+
266
277
  export default {
267
278
  "node/dirty": dirtyConfig,
268
279
  "node/commonjs": commonjsConfig,
@@ -270,43 +281,43 @@ export default {
270
281
  "node/recommended": moduleConfig,
271
282
  "node/mixed-dirty": [
272
283
  {
273
- files: ["**/*.{js,jsx,ts,tsx}"],
284
+ files: jsExtensions,
274
285
  ...dirtyConfig,
275
286
  },
276
287
  {
277
- files: ["**/*.{cjs,cts}"],
288
+ files: cjsExtensions,
278
289
  ...commonjsConfig,
279
290
  },
280
291
  {
281
- files: ["**/*.{mjs,mts}"],
292
+ files: mjsExtensions,
282
293
  ...moduleConfig,
283
294
  },
284
295
  ],
285
296
  "node/mixed-module-and-commonjs": [
286
297
  {
287
- files: ["**/*.{js,jsx,ts,tsx}"],
298
+ files: jsExtensions,
288
299
  ...moduleConfig,
289
300
  },
290
301
  {
291
- files: ["**/*.{cjs,cts}"],
302
+ files: cjsExtensions,
292
303
  ...commonjsConfig,
293
304
  },
294
305
  {
295
- files: ["**/*.{mjs,mts}"],
306
+ files: mjsExtensions,
296
307
  ...moduleConfig,
297
308
  },
298
309
  ],
299
310
  "node/mixed-commonjs-and-module": [
300
311
  {
301
- files: ["**/*.{js,jsx,ts,tsx}"],
312
+ files: jsExtensions,
302
313
  ...commonjsConfig,
303
314
  },
304
315
  {
305
- files: ["**/*.{cjs,cts}"],
316
+ files: cjsExtensions,
306
317
  ...commonjsConfig,
307
318
  },
308
319
  {
309
- files: ["**/*.{mjs,mts}"],
320
+ files: mjsExtensions,
310
321
  ...moduleConfig,
311
322
  },
312
323
  ],
@@ -279,8 +279,6 @@ async function getTypescriptJSDocRecommendedConfig() {
279
279
  };
280
280
  }
281
281
 
282
- const allExtensions = [...typescriptExtensions, ...javascriptExtensions];
283
-
284
282
  /**
285
283
  * @returns {Promise<Record<string, string>>} config
286
284
  */
@@ -311,6 +309,8 @@ async function getTypescriptRecommendedConfig() {
311
309
  (item) => item.name === "typescript-eslint/stylistic",
312
310
  );
313
311
 
312
+ const allExtensions = [...typescriptExtensions, ...javascriptExtensions];
313
+
314
314
  return {
315
315
  ...baseConfig,
316
316
  name: "typescript/recommended",
@@ -0,0 +1,123 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+
4
+ const SKIP_TIME = 5000;
5
+
6
+ class Cache {
7
+ /**
8
+ * Initialize this cache instance.
9
+ */
10
+ constructor() {
11
+ this.map = new Map();
12
+ }
13
+
14
+ /**
15
+ * Get the cached value of the given key.
16
+ * @param {string} key The key to get.
17
+ * @returns {import('type-fest').JsonObject} The cached value or null.
18
+ */
19
+ get(key) {
20
+ const entry = this.map.get(key);
21
+ const now = Date.now();
22
+
23
+ if (entry) {
24
+ if (entry.expire > now) {
25
+ entry.expire = now + SKIP_TIME;
26
+ return entry.value;
27
+ }
28
+ this.map.delete(key);
29
+ }
30
+ return null;
31
+ }
32
+
33
+ /**
34
+ * Set the value of the given key.
35
+ * @param {string} key The key to set.
36
+ * @param {import('type-fest').JsonObject} value The value to set.
37
+ * @returns {void}
38
+ */
39
+ set(key, value) {
40
+ const entry = this.map.get(key);
41
+ const expire = Date.now() + SKIP_TIME;
42
+
43
+ if (entry) {
44
+ entry.value = value;
45
+ entry.expire = expire;
46
+ } else {
47
+ this.map.set(key, { value, expire });
48
+ }
49
+ }
50
+ }
51
+
52
+ const cache = new Cache();
53
+
54
+ /**
55
+ * Reads the `package.json` data in a given path.
56
+ *
57
+ * Don't cache the data.
58
+ * @param {string} dir The path to a directory to read.
59
+ * @param {string} filename The filename.
60
+ * @returns {import('type-fest').JsonObject|null} The read `package.json` data, or null.
61
+ */
62
+ function readJsonFile(dir, filename) {
63
+ const filePath = path.join(dir, filename);
64
+ try {
65
+ const text = fs.readFileSync(filePath, "utf8");
66
+ const data = JSON.parse(text);
67
+
68
+ if (
69
+ data !== null &&
70
+ typeof data === "object" &&
71
+ Array.isArray(data) === false
72
+ ) {
73
+ data.filePath = filePath;
74
+ return data;
75
+ }
76
+ // eslint-disable-next-line unicorn/prefer-optional-catch-binding
77
+ } catch (_err) {
78
+ // do nothing.
79
+ }
80
+
81
+ return null;
82
+ }
83
+
84
+ /**
85
+ * Gets a `package.json` data.
86
+ * The data is cached if found, then it's used after.
87
+ * @param {string} filename The filename.
88
+ * @param {string=} startPath A file path to lookup.
89
+ * @returns {import('type-fest').JsonObject | null} A found `package.json` data or `null`.
90
+ * This object have additional property `filePath`.
91
+ */
92
+ function getJsonFile(filename, startPath = "a.js") {
93
+ const startDir = path.dirname(path.resolve(startPath));
94
+ let dir = startDir;
95
+ let prevDir = "";
96
+ let data = null;
97
+
98
+ do {
99
+ data = cache.get(dir + filename);
100
+ if (data) {
101
+ if (dir !== startDir) {
102
+ cache.set(startDir + filename, data);
103
+ }
104
+ return data;
105
+ }
106
+
107
+ data = readJsonFile(dir, filename);
108
+ if (data) {
109
+ cache.set(dir + filename, data);
110
+ cache.set(startDir + filename, data);
111
+ return data;
112
+ }
113
+
114
+ // Go to next.
115
+ prevDir = dir;
116
+ dir = path.resolve(dir, "..");
117
+ } while (dir !== prevDir);
118
+
119
+ cache.set(startDir + filename, null);
120
+ return null;
121
+ }
122
+
123
+ export default getJsonFile;
@@ -0,0 +1,22 @@
1
+ import getJsonFile from "./get-json-file.js";
2
+
3
+ /**
4
+ * @returns {boolean} true when typescript is supported by project, otherwise false
5
+ */
6
+ function isTypescriptInstalled() {
7
+ const packageJson = getJsonFile("package.json");
8
+
9
+ if (packageJson === null) {
10
+ return [];
11
+ }
12
+
13
+ const dependencies = packageJson.dependencies || [];
14
+ const devDependencies = packageJson.devDependencies || [];
15
+
16
+ return Boolean(
17
+ typeof dependencies.typescript !== "undefined" ||
18
+ typeof devDependencies.typescript !== "undefined",
19
+ );
20
+ }
21
+
22
+ export default isTypescriptInstalled;
package/configs.js CHANGED
@@ -1,130 +1,11 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
1
  import { globalIgnores } from "eslint/config";
4
2
  import semver from "semver";
5
3
  import configs from "./configs/index.js";
6
4
  import { typescriptExtensions } from "./configs/utils/extensions.js";
5
+ import getJsonFile from "./configs/utils/get-json-file.js";
6
+ import isTypescriptInstalled from "./configs/utils/is-typescript-installed.js";
7
7
  import ignorePaths from "./ignore-paths.js";
8
8
 
9
- const SKIP_TIME = 5000;
10
-
11
- class Cache {
12
- /**
13
- * Initialize this cache instance.
14
- */
15
- constructor() {
16
- this.map = new Map();
17
- }
18
-
19
- /**
20
- * Get the cached value of the given key.
21
- * @param {string} key The key to get.
22
- * @returns {import('type-fest').JsonObject} The cached value or null.
23
- */
24
- get(key) {
25
- const entry = this.map.get(key);
26
- const now = Date.now();
27
-
28
- if (entry) {
29
- if (entry.expire > now) {
30
- entry.expire = now + SKIP_TIME;
31
- return entry.value;
32
- }
33
- this.map.delete(key);
34
- }
35
- return null;
36
- }
37
-
38
- /**
39
- * Set the value of the given key.
40
- * @param {string} key The key to set.
41
- * @param {import('type-fest').JsonObject} value The value to set.
42
- * @returns {void}
43
- */
44
- set(key, value) {
45
- const entry = this.map.get(key);
46
- const expire = Date.now() + SKIP_TIME;
47
-
48
- if (entry) {
49
- entry.value = value;
50
- entry.expire = expire;
51
- } else {
52
- this.map.set(key, { value, expire });
53
- }
54
- }
55
- }
56
-
57
- const cache = new Cache();
58
-
59
- /**
60
- * Reads the `package.json` data in a given path.
61
- *
62
- * Don't cache the data.
63
- * @param {string} dir The path to a directory to read.
64
- * @param {string} filename The filename.
65
- * @returns {import('type-fest').JsonObject|null} The read `package.json` data, or null.
66
- */
67
- function readJsonFile(dir, filename) {
68
- const filePath = path.join(dir, filename);
69
- try {
70
- const text = fs.readFileSync(filePath, "utf8");
71
- const data = JSON.parse(text);
72
-
73
- if (
74
- data !== null &&
75
- typeof data === "object" &&
76
- Array.isArray(data) === false
77
- ) {
78
- data.filePath = filePath;
79
- return data;
80
- }
81
- // eslint-disable-next-line unicorn/prefer-optional-catch-binding
82
- } catch (_err) {
83
- // do nothing.
84
- }
85
-
86
- return null;
87
- }
88
-
89
- /**
90
- * Gets a `package.json` data.
91
- * The data is cached if found, then it's used after.
92
- * @param {string} filename The filename.
93
- * @param {string=} startPath A file path to lookup.
94
- * @returns {import('type-fest').JsonObject | null} A found `package.json` data or `null`.
95
- * This object have additional property `filePath`.
96
- */
97
- function getJsonFile(filename, startPath = "a.js") {
98
- const startDir = path.dirname(path.resolve(startPath));
99
- let dir = startDir;
100
- let prevDir = "";
101
- let data = null;
102
-
103
- do {
104
- data = cache.get(dir + filename);
105
- if (data) {
106
- if (dir !== startDir) {
107
- cache.set(startDir + filename, data);
108
- }
109
- return data;
110
- }
111
-
112
- data = readJsonFile(dir, filename);
113
- if (data) {
114
- cache.set(dir + filename, data);
115
- cache.set(startDir + filename, data);
116
- return data;
117
- }
118
-
119
- // Go to next.
120
- prevDir = dir;
121
- dir = path.resolve(dir, "..");
122
- } while (dir !== prevDir);
123
-
124
- cache.set(startDir + filename, null);
125
- return null;
126
- }
127
-
128
9
  const packageJson = getJsonFile("package.json");
129
10
  const isModule =
130
11
  packageJson !== null &&
@@ -199,23 +80,17 @@ function getJavascriptConfig() {
199
80
  * @returns {Promise<Record<string, string>>} config
200
81
  */
201
82
  function getTypescriptJSdocConfig() {
202
- if (packageJson === null) {
203
- return [];
204
- }
205
-
206
- const dependencies = packageJson.dependencies || [];
207
- const devDependencies = packageJson.devDependencies || [];
208
-
209
- return typeof dependencies.typescript !== "undefined" ||
210
- typeof devDependencies.typescript !== "undefined"
211
- ? configs["typescript/jsdoc"]
212
- : [];
83
+ return isTypescriptInstalled() ? configs["typescript/jsdoc"] : [];
213
84
  }
214
85
 
215
86
  /**
216
87
  * @returns {Promise<Record<string, string>>} config
217
88
  */
218
89
  function getTypescriptConfig() {
90
+ if (!isTypescriptInstalled()) {
91
+ return {};
92
+ }
93
+
219
94
  const tsconfigJson = getJsonFile("tsconfig.json");
220
95
 
221
96
  const isNoEmitEnabled =
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-config-webpack",
3
- "version": "4.6.1",
3
+ "version": "4.6.3",
4
4
  "description": "Provides Webpack's eslint rules as an extensible shared config",
5
5
  "keywords": [
6
6
  "eslint",
@@ -50,7 +50,7 @@
50
50
  "eslint-find-rules": "^5.0.0",
51
51
  "eslint-plugin-import": "^2.32.0",
52
52
  "eslint-plugin-jest": "^29.0.1",
53
- "eslint-plugin-jsdoc": "^51.4.1",
53
+ "eslint-plugin-jsdoc": "^54.1.1",
54
54
  "eslint-plugin-n": "^17.21.0",
55
55
  "eslint-plugin-prettier": "^5.5.3",
56
56
  "eslint-plugin-react": "^7.37.5",