@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.
Files changed (40) hide show
  1. package/CHANGELOG.md +737 -0
  2. package/LICENSE +24 -0
  3. package/README.md +34 -0
  4. package/package.json +62 -0
  5. package/src/bin/eslint.cjs +11 -0
  6. package/src/configs/eslint-base.js +124 -0
  7. package/src/configs/eslint-complexity.js +28 -0
  8. package/src/configs/eslint-ignores.js +51 -0
  9. package/src/configs/eslint-recommended.js +9 -0
  10. package/src/configs/eslint-style.js +23 -0
  11. package/src/custom/index.js +11 -0
  12. package/src/custom/instance-of-array.js +72 -0
  13. package/src/custom/loose-types.js +204 -0
  14. package/src/custom/no-useless-expression.js +28 -0
  15. package/src/custom/sequence-expression.js +21 -0
  16. package/src/index.js +86 -0
  17. package/src/plugins/eslint-comments.js +27 -0
  18. package/src/plugins/import.js +139 -0
  19. package/src/plugins/jest.js +124 -0
  20. package/src/plugins/jsdoc.js +70 -0
  21. package/src/plugins/json.js +37 -0
  22. package/src/plugins/jsx-a11y.js +100 -0
  23. package/src/plugins/node.js +129 -0
  24. package/src/plugins/promise.js +16 -0
  25. package/src/plugins/react.js +128 -0
  26. package/src/plugins/regexp.js +13 -0
  27. package/src/plugins/sca.js +41 -0
  28. package/src/plugins/security.js +15 -0
  29. package/src/plugins/sonarjs.js +28 -0
  30. package/src/plugins/style.js +249 -0
  31. package/src/plugins/typescript.js +87 -0
  32. package/src/plugins/unicorn.js +58 -0
  33. package/src/plugins/unused-imports.js +52 -0
  34. package/src/types.d.ts +118 -0
  35. package/src/utilities/editorconfig.js +210 -0
  36. package/src/utilities/eslint-files.js +65 -0
  37. package/src/utilities/expand-glob.js +49 -0
  38. package/src/utilities/filesystem.js +73 -0
  39. package/src/utilities/make-compat.js +17 -0
  40. 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
+ }