@keeex/eslint-config 2.1.3 → 2.1.4

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/package.json CHANGED
@@ -15,20 +15,20 @@
15
15
  },
16
16
  "description": "Common eslint configuration",
17
17
  "devDependencies": {
18
- "@eslint/compat": "^1.2.1",
18
+ "@eslint/compat": "^1.2.2",
19
19
  "@eslint/js": "^9.12.0",
20
- "eslint": "^9.13.0",
20
+ "eslint": "^9.14.0",
21
21
  "eslint-import-resolver-typescript": "^3.6.3",
22
22
  "eslint-import-resolver-webpack": "^0.13.9",
23
- "eslint-plugin-import-x": "^4.3.1",
23
+ "eslint-plugin-import-x": "^4.4.0",
24
24
  "eslint-plugin-mocha": "^10.5.0",
25
25
  "eslint-plugin-promise": "^7.1.0",
26
26
  "eslint-plugin-react": "^7.37.2",
27
27
  "eslint-plugin-react-hooks": "^5.0.0",
28
28
  "eslint-plugin-tsdoc": "^0.3.0",
29
- "globals": "^15.11.0",
29
+ "globals": "^15.12.0",
30
30
  "prettier": "^3.3.3",
31
- "typescript-eslint": "^8.11.0"
31
+ "typescript-eslint": "^8.13.0"
32
32
  },
33
33
  "files": [
34
34
  "prettier.config.js",
@@ -112,5 +112,5 @@
112
112
  "test": "echo No test for this project"
113
113
  },
114
114
  "type": "module",
115
- "version": "2.1.3"
115
+ "version": "2.1.4"
116
116
  }
@@ -1,26 +1,48 @@
1
1
  import mochaPlugin from "eslint-plugin-mocha";
2
2
 
3
+ import {getFiles} from "../pathutils.js";
3
4
  import * as sections from "../sections.js";
4
5
 
5
6
  export const apply = (configResult, eslintConfig) => {
6
7
  if (!eslintConfig.mocha) return;
7
- const mochaFilter = ["src/tests/**/*", "**/*.test.*"];
8
+ const fileTypes = {
9
+ javascript: true,
10
+ jsx: Boolean(eslintConfig.react),
11
+ typescript: eslintConfig.typescript,
12
+ };
13
+ const mochaFilter = getFiles([
14
+ {
15
+ filePatterns: "*.ext",
16
+ fileTypes,
17
+ recursiveDirectories: "src/tests",
18
+ },
19
+ {
20
+ filePatterns: "*.test.ext",
21
+ fileTypes,
22
+ recursiveDirectories: "src",
23
+ },
24
+ ]);
8
25
  const mochaSection = {
9
26
  ...mochaPlugin.configs.flat.recommended,
10
27
  files: mochaFilter,
11
28
  };
12
- sections.configureRules(mochaSection, "", {
29
+ configResult.push(mochaSection);
30
+ const override = sections.getNamedSection(configResult, "keeex/mocha");
31
+ override.files = mochaFilter;
32
+ sections.configureRules(override, "", {
13
33
  "max-classes-per-file": "off",
14
34
  "max-lines": "off",
15
35
  "max-lines-per-function": "off",
16
36
  "max-params": "off",
37
+ "no-invalid-this": "off",
17
38
  "no-magic-numbers": "off",
39
+ "no-setup-in-describe": "off",
40
+ "prefer-arrow-callback": "off",
18
41
  });
19
42
  if (eslintConfig.typescript) {
20
- sections.configureRules(mochaSection, "@typescript-eslint", {
43
+ sections.configureRules(override, "@typescript-eslint", {
21
44
  "max-params": "off",
22
45
  "no-magic-numbers": "off",
23
46
  });
24
47
  }
25
- configResult.push(mochaSection);
26
48
  };
@@ -69,7 +69,6 @@ export const apply = (configResult, eslintConfig) => {
69
69
  "no-unused-vars",
70
70
  "no-use-before-define",
71
71
  "no-useless-constructor",
72
- "prefer-destructuring",
73
72
  "prefer-promise-reject-errors",
74
73
  "require-await",
75
74
  ]) {
@@ -0,0 +1,76 @@
1
+ const asArray = (value) => {
2
+ if (Array.isArray(value)) return value;
3
+ return [value];
4
+ };
5
+
6
+ export const getExtensions = (fileTypes) => {
7
+ const result = [];
8
+ const esm = fileTypes.esm ?? true;
9
+ const cjs = fileTypes.cjs ?? false;
10
+ if (fileTypes.javascript) {
11
+ if (esm) result.push(".js", ".mjs");
12
+ if (cjs) result.push(".cjs");
13
+ }
14
+ if (fileTypes.typescript) {
15
+ if (esm) result.push(".ts", ".mts");
16
+ if (cjs) result.push(".mts");
17
+ }
18
+ if (fileTypes.jsx) {
19
+ if (esm) result.push(".jsx");
20
+ if (fileTypes.typescript) result.push(".tsx");
21
+ }
22
+ return result;
23
+ };
24
+
25
+ /** Configuration to build a filter list */
26
+ // interface FilesDefinition {
27
+ // /** Directories where the files are; no recursion */
28
+ // exactDirectories?: Array<string>;
29
+ // /** Directories where the files are, will go into subdirectories */
30
+ // recursiveDirectories?: Array<string>;
31
+ // /**
32
+ // * File name pattern. Must have `".ext"` to be substituted by the extension.
33
+ // *
34
+ // * Defaults to `["*.ext"]`.
35
+ // */
36
+ // filesPatterns?: Array<string>;
37
+ // fileTypes: {
38
+ // /** Enable base JavaScript extensions */
39
+ // javascript: boolean;
40
+ // /** Enable base TypeScript extension */
41
+ // typescript: boolean;
42
+ // /** Enable JSX extensions */
43
+ // jsx: boolean;
44
+ // /** Support ESM */
45
+ // esm: boolean;
46
+ // /** Support CommonJS */
47
+ // commonjs: boolean;
48
+ // };
49
+ // }
50
+
51
+ const extPlaceholder = ".ext";
52
+
53
+ export const getFiles = (definitions) => {
54
+ const result = new Set();
55
+ for (const definition of asArray(definitions)) {
56
+ const extensions = getExtensions(definition.fileTypes);
57
+ const directories = new Set();
58
+ if (definition.exactDirectories) directories.add(...asArray(definition.exactDirectories));
59
+ if (definition.recursiveDirectories) {
60
+ directories.add(...asArray(definition.recursiveDirectories).map((c) => `${c}/**`));
61
+ }
62
+ const filePatterns = new Set(asArray(definition.filePatterns) ?? [`*${extPlaceholder}`]);
63
+ for (const directory of directories) {
64
+ for (const filePattern of filePatterns) {
65
+ if (filePattern.includes(extPlaceholder)) {
66
+ for (const extension of extensions) {
67
+ result.add(`${directory}/${filePattern.replace(extPlaceholder, extension)}`);
68
+ }
69
+ } else {
70
+ result.add(`${directory}/${filePattern}`);
71
+ }
72
+ }
73
+ }
74
+ }
75
+ return Array.from(result);
76
+ };