eslint-config-webpack 4.6.1 → 4.6.2

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.
@@ -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",
@@ -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.2",
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",