@darksheep/eslint 5.3.0 → 5.3.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.
Files changed (37) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/package.json +7 -7
  3. package/src/configs/eslint-base.js +103 -103
  4. package/src/configs/eslint-complexity.js +24 -24
  5. package/src/configs/eslint-ignores.js +32 -32
  6. package/src/configs/eslint-recommended.js +4 -4
  7. package/src/configs/eslint-style.js +12 -12
  8. package/src/custom/index.js +5 -5
  9. package/src/custom/instance-of-array.js +44 -44
  10. package/src/custom/loose-types.js +128 -128
  11. package/src/custom/no-useless-expression.js +19 -19
  12. package/src/custom/sequence-expression.js +15 -15
  13. package/src/index.js +38 -38
  14. package/src/plugins/eslint-comments.js +19 -19
  15. package/src/plugins/jsdoc.js +57 -57
  16. package/src/plugins/json.js +43 -43
  17. package/src/plugins/node.js +108 -108
  18. package/src/plugins/package-json.js +25 -25
  19. package/src/plugins/perfectionist.js +200 -200
  20. package/src/plugins/promise.js +9 -9
  21. package/src/plugins/react.js +111 -111
  22. package/src/plugins/regexp.js +6 -6
  23. package/src/plugins/sca.js +32 -32
  24. package/src/plugins/security.js +14 -14
  25. package/src/plugins/sonarjs.js +11 -11
  26. package/src/plugins/style.js +236 -236
  27. package/src/plugins/typescript.js +65 -65
  28. package/src/plugins/unicorn.js +40 -40
  29. package/src/plugins/unused-imports.js +25 -25
  30. package/src/plugins/yml.js +32 -32
  31. package/src/types.d.ts +80 -80
  32. package/src/utilities/editorconfig.js +150 -150
  33. package/src/utilities/eslint-files.js +20 -20
  34. package/src/utilities/expand-glob.js +33 -33
  35. package/src/utilities/filesystem.js +30 -30
  36. package/src/utilities/make-compat.js +6 -6
  37. package/src/utilities/package.js +29 -29
@@ -23,80 +23,80 @@ import { findUp } from './filesystem.js';
23
23
  * @returns {import('eslint').Linter.RulesRecord}
24
24
  */
25
25
  function convert(input, RULES) {
26
- /** @type {import('eslint').Linter.RulesRecord} */
27
- const output = {};
28
-
29
- if (input?.end_of_line === 'lf') {
30
- output[RULES.LF] = [ 'error', 'unix' ];
31
- }
32
-
33
- if (input?.end_of_line === 'crlf') {
34
- output[RULES.LF] = [ 'error', 'windows' ];
35
- }
36
-
37
- if (input?.trim_trailing_whitespace === 'true') {
38
- output[RULES.TRAIL] = 'error';
39
- }
40
-
41
- if (input?.trim_trailing_whitespace === 'false') {
42
- output[RULES.TRAIL] = 'off';
26
+ /** @type {import('eslint').Linter.RulesRecord} */
27
+ const output = {};
28
+
29
+ if (input?.end_of_line === 'lf') {
30
+ output[RULES.LF] = [ 'error', 'unix' ];
31
+ }
32
+
33
+ if (input?.end_of_line === 'crlf') {
34
+ output[RULES.LF] = [ 'error', 'windows' ];
35
+ }
36
+
37
+ if (input?.trim_trailing_whitespace === 'true') {
38
+ output[RULES.TRAIL] = 'error';
39
+ }
40
+
41
+ if (input?.trim_trailing_whitespace === 'false') {
42
+ output[RULES.TRAIL] = 'off';
43
+ }
44
+
45
+ if (input?.insert_final_newline === 'true') {
46
+ output[RULES.EOL] = [ 'error', 'always' ];
47
+ }
48
+
49
+ if (input?.insert_final_newline === 'false') {
50
+ output[RULES.EOL] = [ 'error', 'never' ];
51
+ }
52
+
53
+ if (input?.indent_style === 'space') {
54
+ const size = Number.parseInt(input?.indent_size ?? 4, 10);
55
+ output[RULES.INDENT] = [ 'error', size, RULES.INDENT_OPTIONS ?? {} ];
56
+ if (RULES.INDENT_BINARY != null) {
57
+ output[RULES.INDENT_BINARY] = [ 'error', size ];
43
58
  }
59
+ }
44
60
 
45
- if (input?.insert_final_newline === 'true') {
46
- output[RULES.EOL] = [ 'error', 'always' ];
61
+ if (input?.indent_style === 'tab') {
62
+ output[RULES.INDENT] = [ 'error', 'tab', RULES.INDENT_OPTIONS ?? {} ];
63
+ if (RULES.INDENT_BINARY != null) {
64
+ output[RULES.INDENT_BINARY] = [ 'error', 'tab' ];
47
65
  }
66
+ }
48
67
 
49
- if (input?.insert_final_newline === 'false') {
50
- output[RULES.EOL] = [ 'error', 'never' ];
51
- }
52
-
53
- if (input?.indent_style === 'space') {
54
- const size = Number.parseInt(input?.indent_size ?? 4, 10);
55
- output[RULES.INDENT] = [ 'error', size, RULES.INDENT_OPTIONS ?? {} ];
56
- if (RULES.INDENT_BINARY != null) {
57
- output[RULES.INDENT_BINARY] = [ 'error', size ];
58
- }
59
- }
60
-
61
- if (input?.indent_style === 'tab') {
62
- output[RULES.INDENT] = [ 'error', 'tab', RULES.INDENT_OPTIONS ?? {} ];
63
- if (RULES.INDENT_BINARY != null) {
64
- output[RULES.INDENT_BINARY] = [ 'error', 'tab' ];
65
- }
66
- }
67
-
68
- return output;
68
+ return output;
69
69
  }
70
70
 
71
71
  /** @type {[string[], RuleSet][]} */
72
72
  const extToRules = [
73
- [
74
- [ '.js', '.cjs', '.mjs', '.ts', '.cts', '.mts', '.jsx', '.tsx' ],
75
- {
76
- EOL: 'style/eol-last',
77
- LF: 'style/linebreak-style',
78
- TRAIL: 'style/no-trailing-spaces',
79
- INDENT: 'style/indent',
80
- INDENT_BINARY: 'style/indent-binary-ops',
81
- INDENT_OPTIONS: { SwitchCase: 1 },
82
- },
83
- ],
84
- [
85
- [ '.json', '.jsonc', '.json5' ], {
86
- EOL: 'style/eol-last',
87
- LF: 'style/linebreak-style',
88
- TRAIL: 'style/no-trailing-spaces',
89
- INDENT: 'jsonc/indent',
90
- },
91
- ],
92
- [
93
- [ '.yml', '.yaml' ], {
94
- EOL: 'style/eol-last',
95
- LF: 'style/linebreak-style',
96
- TRAIL: 'style/no-trailing-spaces',
97
- INDENT: 'yml/indent',
98
- },
99
- ],
73
+ [
74
+ [ '.js', '.cjs', '.mjs', '.ts', '.cts', '.mts', '.jsx', '.tsx' ],
75
+ {
76
+ EOL: 'style/eol-last',
77
+ LF: 'style/linebreak-style',
78
+ TRAIL: 'style/no-trailing-spaces',
79
+ INDENT: 'style/indent',
80
+ INDENT_BINARY: 'style/indent-binary-ops',
81
+ INDENT_OPTIONS: { SwitchCase: 1 },
82
+ },
83
+ ],
84
+ [
85
+ [ '.json', '.jsonc', '.json5' ], {
86
+ EOL: 'style/eol-last',
87
+ LF: 'style/linebreak-style',
88
+ TRAIL: 'style/no-trailing-spaces',
89
+ INDENT: 'jsonc/indent',
90
+ },
91
+ ],
92
+ [
93
+ [ '.yml', '.yaml' ], {
94
+ EOL: 'style/eol-last',
95
+ LF: 'style/linebreak-style',
96
+ TRAIL: 'style/no-trailing-spaces',
97
+ INDENT: 'yml/indent',
98
+ },
99
+ ],
100
100
  ];
101
101
 
102
102
  /**
@@ -106,18 +106,18 @@ const extToRules = [
106
106
  * @returns {string[]}
107
107
  */
108
108
  function filterMatchingFiles(files, extensions) {
109
- return files.filter((file) => {
110
- if (file.endsWith('*')) {
111
- return true;
112
- }
113
-
114
- for (const extension of extensions) {
115
- if (file.endsWith(extension)) {
116
- return true;
117
- }
118
- }
119
- return false;
120
- });
109
+ return files.filter((file) => {
110
+ if (file.endsWith('*')) {
111
+ return true;
112
+ }
113
+
114
+ for (const extension of extensions) {
115
+ if (file.endsWith(extension)) {
116
+ return true;
117
+ }
118
+ }
119
+ return false;
120
+ });
121
121
  }
122
122
 
123
123
  /**
@@ -127,28 +127,28 @@ function filterMatchingFiles(files, extensions) {
127
127
  * @returns {boolean}
128
128
  */
129
129
  function equal(one, two) {
130
- if (one == null && two == null) {
131
- return true;
132
- }
133
- if (one == null || two == null) {
134
- return false;
135
- }
136
-
137
- if (
138
- Array.isArray(one) === false ||
139
- Array.isArray(two) === false ||
140
- one.length !== two.length
141
- ) {
142
- return false;
143
- }
144
-
145
- for (const element of one) {
146
- if (two.includes(element) === false) {
147
- return false;
148
- }
130
+ if (one == null && two == null) {
131
+ return true;
132
+ }
133
+ if (one == null || two == null) {
134
+ return false;
135
+ }
136
+
137
+ if (
138
+ Array.isArray(one) === false ||
139
+ Array.isArray(two) === false ||
140
+ one.length !== two.length
141
+ ) {
142
+ return false;
143
+ }
144
+
145
+ for (const element of one) {
146
+ if (two.includes(element) === false) {
147
+ return false;
149
148
  }
149
+ }
150
150
 
151
- return true;
151
+ return true;
152
152
  }
153
153
 
154
154
  /**
@@ -156,20 +156,20 @@ function equal(one, two) {
156
156
  * @param {import('eslint').Linter.FlatConfig} config [description]
157
157
  */
158
158
  function addOrMergeConfig(configs, config) {
159
- for (const previous of configs) {
160
- if (equal(
161
- /** @type {string[]} */ (previous.files),
162
- /** @type {string[]} */ (config.files),
163
- )) {
164
- previous.rules = {
165
- ...previous.rules,
166
- ...config.rules,
167
- };
168
-
169
- return;
170
- }
159
+ for (const previous of configs) {
160
+ if (equal(
161
+ /** @type {string[]} */ (previous.files),
162
+ /** @type {string[]} */ (config.files),
163
+ )) {
164
+ previous.rules = {
165
+ ...previous.rules,
166
+ ...config.rules,
167
+ };
168
+
169
+ return;
171
170
  }
172
- configs.push(config);
171
+ }
172
+ configs.push(config);
173
173
  }
174
174
 
175
175
  /**
@@ -177,47 +177,47 @@ function addOrMergeConfig(configs, config) {
177
177
  * @returns {Promise<import('eslint').Linter.FlatConfig[]>}
178
178
  */
179
179
  export async function createEditorOverrides(root) {
180
- const eslintConfigPath = resolve(fileURLToPath(root), 'eslint.config.js');
181
- const path = await findUp(eslintConfigPath, '.editorconfig');
182
- if (path == null) {
183
- return [];
180
+ const eslintConfigPath = resolve(fileURLToPath(root), 'eslint.config.js');
181
+ const path = await findUp(eslintConfigPath, '.editorconfig');
182
+ if (path == null) {
183
+ return [];
184
+ }
185
+
186
+ const editorconfig = parseBuffer(await readFile(path));
187
+
188
+ /** @type {import('eslint').Linter.FlatConfig[]} */
189
+ const configs = [];
190
+ for (const [ name, body ] of editorconfig) {
191
+ if (name === null) {
192
+ continue;
193
+ }
194
+
195
+ const allFiles = expandGlob(name);
196
+ if (allFiles == null) {
197
+ continue;
184
198
  }
185
199
 
186
- const editorconfig = parseBuffer(await readFile(path));
187
-
188
- /** @type {import('eslint').Linter.FlatConfig[]} */
189
- const configs = [];
190
- for (const [ name, body ] of editorconfig) {
191
- if (name === null) {
192
- continue;
193
- }
194
-
195
- const allFiles = expandGlob(name);
196
- if (allFiles == null) {
197
- continue;
198
- }
199
-
200
- for (const [ extensions, rules ] of extToRules) {
201
- const files = filterMatchingFiles(allFiles, extensions);
202
- if (files.length === 0) {
203
- continue;
204
- }
205
-
206
- if (files.includes('*')) {
207
- addOrMergeConfig(configs, {
208
- name: `editor-config/${extensions.join(', ')}`,
209
- files: extensions.map((extension) => `**/*${extension}`),
210
- rules: convert(body, rules),
211
- });
212
- } else {
213
- addOrMergeConfig(configs, {
214
- name: `editor-config/${files.join(', ')}`,
215
- files: files.map((file) => `**/${file}`),
216
- rules: convert(body, rules),
217
- });
218
- }
219
- }
200
+ for (const [ extensions, rules ] of extToRules) {
201
+ const files = filterMatchingFiles(allFiles, extensions);
202
+ if (files.length === 0) {
203
+ continue;
204
+ }
205
+
206
+ if (files.includes('*')) {
207
+ addOrMergeConfig(configs, {
208
+ name: `editor-config/${extensions.join(', ')}`,
209
+ files: extensions.map((extension) => `**/*${extension}`),
210
+ rules: convert(body, rules),
211
+ });
212
+ } else {
213
+ addOrMergeConfig(configs, {
214
+ name: `editor-config/${files.join(', ')}`,
215
+ files: files.map((file) => `**/${file}`),
216
+ rules: convert(body, rules),
217
+ });
218
+ }
220
219
  }
220
+ }
221
221
 
222
- return configs;
222
+ return configs;
223
223
  }
@@ -8,11 +8,11 @@ import { getPackageJson } from './package.js';
8
8
  * @returns {string[]}
9
9
  */
10
10
  function getFiles(files, type, target) {
11
- if (type === target) {
12
- return [ '**/*.js', '**/*.jsx', ...files ];
13
- }
11
+ if (type === target) {
12
+ return [ '**/*.js', '**/*.jsx', ...files ];
13
+ }
14
14
 
15
- return files;
15
+ return files;
16
16
  }
17
17
 
18
18
  /**
@@ -21,9 +21,9 @@ function getFiles(files, type, target) {
21
21
  * @returns {Promise<string[]>}
22
22
  */
23
23
  export async function getCommonFiles(root) {
24
- const { type = 'commonjs' } = await getPackageJson(root) ?? {};
24
+ const { type = 'commonjs' } = await getPackageJson(root) ?? {};
25
25
 
26
- return getFiles([ '**/*.cjs' ], type, 'commonjs');
26
+ return getFiles([ '**/*.cjs' ], type, 'commonjs');
27
27
  }
28
28
 
29
29
  /**
@@ -32,8 +32,8 @@ export async function getCommonFiles(root) {
32
32
  * @returns {Promise<string[]>}
33
33
  */
34
34
  export async function getModuleFiles(root) {
35
- const { type = 'commonjs' } = await getPackageJson(root) ?? {};
36
- return getFiles([ '**/*.mjs' ], type, 'module');
35
+ const { type = 'commonjs' } = await getPackageJson(root) ?? {};
36
+ return getFiles([ '**/*.mjs' ], type, 'module');
37
37
  }
38
38
 
39
39
  /**
@@ -41,7 +41,7 @@ export async function getModuleFiles(root) {
41
41
  * @returns {string[]}
42
42
  */
43
43
  export function getTypescriptFiles() {
44
- return [ '**/*.ts', '**/*.tsx' ];
44
+ return [ '**/*.ts', '**/*.tsx' ];
45
45
  }
46
46
 
47
47
  /**
@@ -49,12 +49,12 @@ export function getTypescriptFiles() {
49
49
  * @returns {string[]}
50
50
  */
51
51
  export function getTestFiles() {
52
- return [
53
- ...expandGlob('**/test.*'),
54
- ...expandGlob('**/*.test.*'),
55
- ...expandGlob('**/{test,tests}/*'),
56
- ...expandGlob('**/{test,tests}/**/*'),
57
- ];
52
+ return [
53
+ ...expandGlob('**/test.*'),
54
+ ...expandGlob('**/*.test.*'),
55
+ ...expandGlob('**/{test,tests}/*'),
56
+ ...expandGlob('**/{test,tests}/**/*'),
57
+ ];
58
58
  }
59
59
 
60
60
  /**
@@ -62,9 +62,9 @@ export function getTestFiles() {
62
62
  * @returns {string[]}
63
63
  */
64
64
  export function getExampleFiles() {
65
- return [
66
- ...expandGlob('**/example.{ts,js,tsx,jsx,mts,cts,mjs,cjs}'),
67
- ...expandGlob('**/{example,examples}/*'),
68
- ...expandGlob('**/{example,examples}/**/*'),
69
- ];
65
+ return [
66
+ ...expandGlob('**/example.{ts,js,tsx,jsx,mts,cts,mjs,cjs}'),
67
+ ...expandGlob('**/{example,examples}/*'),
68
+ ...expandGlob('**/{example,examples}/**/*'),
69
+ ];
70
70
  }
@@ -6,44 +6,44 @@ const globEachRegex = /\{[\w.-]+(?:,[\w.-]+)*\}/;
6
6
  * @returns {string[]}
7
7
  */
8
8
  export function expandGlob(input) {
9
- const globNumMatch = input.match(globNumRegex);
10
- if (typeof globNumMatch?.index === 'number') {
11
- const first = input.slice(0, globNumMatch.index);
12
- const each = globNumMatch[0];
13
- const last = input.slice(globNumMatch.index + each.length);
14
-
15
- const [ a, b ] = each
16
- .slice(1, -1)
17
- .split('..')
18
- .map((number) => Number.parseInt(number, 10));
19
-
20
- const start = a > b ? b : a;
21
- const end = a < b ? b : a;
22
-
23
- const output = [];
24
- for (let i = start; i <= end; i++) {
25
- output.push(`${first}${i}${last}`);
26
- }
27
-
28
- return output.map(expandGlob).flat();
9
+ const globNumMatch = input.match(globNumRegex);
10
+ if (typeof globNumMatch?.index === 'number') {
11
+ const first = input.slice(0, globNumMatch.index);
12
+ const each = globNumMatch[0];
13
+ const last = input.slice(globNumMatch.index + each.length);
14
+
15
+ const [ a, b ] = each
16
+ .slice(1, -1)
17
+ .split('..')
18
+ .map((number) => Number.parseInt(number, 10));
19
+
20
+ const start = a > b ? b : a;
21
+ const end = a < b ? b : a;
22
+
23
+ const output = [];
24
+ for (let i = start; i <= end; i++) {
25
+ output.push(`${first}${i}${last}`);
29
26
  }
30
27
 
31
- const globEachMatch = input.match(globEachRegex);
32
- if (typeof globEachMatch?.index === 'number') {
33
- const first = input.slice(0, globEachMatch.index);
34
- const each = globEachMatch[0];
35
- const last = input.slice(globEachMatch.index + each.length);
28
+ return output.map(expandGlob).flat();
29
+ }
36
30
 
37
- const output = each
38
- .slice(1, -1).split(',')
39
- .map((part) => `${first}${part}${last}`);
31
+ const globEachMatch = input.match(globEachRegex);
32
+ if (typeof globEachMatch?.index === 'number') {
33
+ const first = input.slice(0, globEachMatch.index);
34
+ const each = globEachMatch[0];
35
+ const last = input.slice(globEachMatch.index + each.length);
40
36
 
41
- if (output.length > 1) {
42
- return output.map(expandGlob).flat();
43
- }
37
+ const output = each
38
+ .slice(1, -1).split(',')
39
+ .map((part) => `${first}${part}${last}`);
44
40
 
45
- return output;
41
+ if (output.length > 1) {
42
+ return output.map(expandGlob).flat();
46
43
  }
47
44
 
48
- return [ input ];
45
+ return output;
46
+ }
47
+
48
+ return [ input ];
49
49
  }
@@ -6,12 +6,12 @@ import * as Path from 'node:path';
6
6
  * @returns {Promise<boolean>}
7
7
  */
8
8
  export async function exists(path) {
9
- try {
10
- await stat(path);
11
- return true;
12
- } catch {
13
- return false;
14
- }
9
+ try {
10
+ await stat(path);
11
+ return true;
12
+ } catch {
13
+ return false;
14
+ }
15
15
  }
16
16
 
17
17
  /**
@@ -21,14 +21,14 @@ export async function exists(path) {
21
21
  * @returns {boolean}
22
22
  */
23
23
  export function descendsFrom(filePath, projectPath) {
24
- if (
25
- typeof filePath !== 'string' ||
26
- typeof projectPath !== 'string'
27
- ) {
28
- return false;
29
- }
24
+ if (
25
+ typeof filePath !== 'string' ||
26
+ typeof projectPath !== 'string'
27
+ ) {
28
+ return false;
29
+ }
30
30
 
31
- return Path.relative(projectPath, filePath).startsWith('..') === false;
31
+ return Path.relative(projectPath, filePath).startsWith('..') === false;
32
32
  }
33
33
 
34
34
  /**
@@ -38,19 +38,19 @@ export function descendsFrom(filePath, projectPath) {
38
38
  * @returns {string[]}
39
39
  */
40
40
  export function listParents(filepath, stopDirectory = '/') {
41
- // The file is not from within the stopDirectory
42
- if (descendsFrom(filepath, stopDirectory) === false) {
43
- return [];
44
- }
41
+ // The file is not from within the stopDirectory
42
+ if (descendsFrom(filepath, stopDirectory) === false) {
43
+ return [];
44
+ }
45
45
 
46
- const output = [];
47
- const end = Path.resolve(stopDirectory);
48
- do {
49
- filepath = Path.dirname(filepath);
50
- output.push(filepath);
51
- } while (end !== filepath);
46
+ const output = [];
47
+ const end = Path.resolve(stopDirectory);
48
+ do {
49
+ filepath = Path.dirname(filepath);
50
+ output.push(filepath);
51
+ } while (end !== filepath);
52
52
 
53
- return output;
53
+ return output;
54
54
  }
55
55
 
56
56
  /**
@@ -61,13 +61,13 @@ export function listParents(filepath, stopDirectory = '/') {
61
61
  * @returns {Promise<string|null>} Returns absolute path to the closest {filename} if found
62
62
  */
63
63
  export async function findUp(rootFilePath, filename, stopDirectory = Path.resolve('/')) {
64
- for (const directory of listParents(rootFilePath, stopDirectory)) {
65
- const target = Path.join(directory, filename);
64
+ for (const directory of listParents(rootFilePath, stopDirectory)) {
65
+ const target = Path.join(directory, filename);
66
66
 
67
- if (await exists(target)) {
68
- return target;
69
- }
67
+ if (await exists(target)) {
68
+ return target;
70
69
  }
70
+ }
71
71
 
72
- return null;
72
+ return null;
73
73
  }
@@ -8,10 +8,10 @@ import { FlatCompat } from '@eslint/eslintrc';
8
8
  * @returns {import('@eslint/eslintrc').FlatCompat}
9
9
  */
10
10
  export function makeCompat(root) {
11
- return new FlatCompat({
12
- // The root of the importing project
13
- baseDirectory: fileURLToPath(root),
14
- // The root of our project
15
- resolvePluginsRelativeTo: resolve(fileURLToPath(import.meta.url), '..', '..', '..'),
16
- });
11
+ return new FlatCompat({
12
+ // The root of the importing project
13
+ baseDirectory: fileURLToPath(root),
14
+ // The root of our project
15
+ resolvePluginsRelativeTo: resolve(fileURLToPath(import.meta.url), '..', '..', '..'),
16
+ });
17
17
  }