@darksheep/eslint 4.1.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.
- package/CHANGELOG.md +737 -0
- package/LICENSE +24 -0
- package/README.md +34 -0
- package/package.json +62 -0
- package/src/bin/eslint.cjs +11 -0
- package/src/configs/eslint-base.js +124 -0
- package/src/configs/eslint-complexity.js +28 -0
- package/src/configs/eslint-ignores.js +51 -0
- package/src/configs/eslint-recommended.js +9 -0
- package/src/configs/eslint-style.js +23 -0
- package/src/custom/index.js +11 -0
- package/src/custom/instance-of-array.js +72 -0
- package/src/custom/loose-types.js +204 -0
- package/src/custom/no-useless-expression.js +28 -0
- package/src/custom/sequence-expression.js +21 -0
- package/src/index.js +86 -0
- package/src/plugins/eslint-comments.js +27 -0
- package/src/plugins/import.js +139 -0
- package/src/plugins/jest.js +124 -0
- package/src/plugins/jsdoc.js +70 -0
- package/src/plugins/json.js +37 -0
- package/src/plugins/jsx-a11y.js +100 -0
- package/src/plugins/node.js +129 -0
- package/src/plugins/promise.js +16 -0
- package/src/plugins/react.js +128 -0
- package/src/plugins/regexp.js +13 -0
- package/src/plugins/sca.js +41 -0
- package/src/plugins/security.js +15 -0
- package/src/plugins/sonarjs.js +28 -0
- package/src/plugins/style.js +249 -0
- package/src/plugins/typescript.js +87 -0
- package/src/plugins/unicorn.js +58 -0
- package/src/plugins/unused-imports.js +52 -0
- package/src/types.d.ts +118 -0
- package/src/utilities/editorconfig.js +210 -0
- package/src/utilities/eslint-files.js +65 -0
- package/src/utilities/expand-glob.js +49 -0
- package/src/utilities/filesystem.js +73 -0
- package/src/utilities/make-compat.js +17 -0
- package/src/utilities/package.js +49 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as Path from 'node:path';
|
|
2
|
+
import { stat } from 'node:fs/promises';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {string} path The absolute path to the file to check
|
|
6
|
+
* @returns {Promise<boolean>}
|
|
7
|
+
*/
|
|
8
|
+
export async function exists(path) {
|
|
9
|
+
try {
|
|
10
|
+
await stat(path);
|
|
11
|
+
return true;
|
|
12
|
+
} catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Does {filePath} exist in {projectPath}
|
|
19
|
+
* @param {string} [filePath] The path of the file to check
|
|
20
|
+
* @param {string} [projectPath] The path to the project root
|
|
21
|
+
* @returns {boolean}
|
|
22
|
+
*/
|
|
23
|
+
export function descendsFrom(filePath, projectPath) {
|
|
24
|
+
if (
|
|
25
|
+
typeof filePath !== 'string' ||
|
|
26
|
+
typeof projectPath !== 'string'
|
|
27
|
+
) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return Path.relative(projectPath, filePath).startsWith('..') === false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Create a list of parent directories from {filepath} to {stopDirectory}
|
|
36
|
+
* @param {string} filepath The file to start from
|
|
37
|
+
* @param {string} [stopDirectory] The directory to stop at
|
|
38
|
+
* @returns {string[]}
|
|
39
|
+
*/
|
|
40
|
+
export function listParents(filepath, stopDirectory = '/') {
|
|
41
|
+
// The file is not from within the stopDirectory
|
|
42
|
+
if (descendsFrom(filepath, stopDirectory) === false) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
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);
|
|
52
|
+
|
|
53
|
+
return output;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Find the closest {filename} starting from {rootFilePath}
|
|
58
|
+
* @param {string} rootFilePath The file to start the search from
|
|
59
|
+
* @param {string} filename The filename to find
|
|
60
|
+
* @param {string} [stopDirectory] The directory to stop searching at
|
|
61
|
+
* @returns {Promise<string|null>} Returns absolute path to the closest {filename} if found
|
|
62
|
+
*/
|
|
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);
|
|
66
|
+
|
|
67
|
+
if (await exists(target)) {
|
|
68
|
+
return target;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
|
|
4
|
+
import { FlatCompat } from '@eslint/eslintrc';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {import('node:url').URL} root root url
|
|
8
|
+
* @returns {import('@eslint/eslintrc').FlatCompat}
|
|
9
|
+
*/
|
|
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
|
+
});
|
|
17
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { findUp } from './filesystem.js';
|
|
5
|
+
|
|
6
|
+
const errorCodesToSkip = new Set([
|
|
7
|
+
'ENOENT',
|
|
8
|
+
'MODULE_NOT_FOUND',
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
const cache = new Map();
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Get the path of the eslint package json
|
|
15
|
+
* @param {import('node:url').URL} root root url
|
|
16
|
+
* @param {string} [packageName] The name of the npm package
|
|
17
|
+
* @returns {Promise<import('type-fest').PackageJson | null>}
|
|
18
|
+
*/
|
|
19
|
+
export async function getPackageJson(root, packageName) {
|
|
20
|
+
const rootPath = fileURLToPath(root);
|
|
21
|
+
if (cache.has(`${root}::${packageName}`)) {
|
|
22
|
+
return cache.get(`${root}::${packageName}`);
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const require = createRequire(root);
|
|
26
|
+
const path = typeof packageName === 'string'
|
|
27
|
+
? require.resolve(packageName)
|
|
28
|
+
: rootPath;
|
|
29
|
+
const jsonPath = await findUp(path, 'package.json');
|
|
30
|
+
|
|
31
|
+
if (jsonPath == null) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const result = JSON.parse(await readFile(jsonPath, 'utf8'));
|
|
36
|
+
cache.set(`${root}::${packageName}`, result);
|
|
37
|
+
return result;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
const shouldSkip = errorCodesToSkip.has(
|
|
40
|
+
/** @type {Error & {code: string}} */ (error).code,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
if (shouldSkip === false) {
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|