@keeex/eslint-config 2.1.4 → 2.2.1

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/LICENSE CHANGED
@@ -2,8 +2,17 @@ MIT License
2
2
 
3
3
  Copyright (c) 2024 KeeeX SAS
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6
+ associated documentation files (the "Software"), to deal in the Software without restriction,
7
+ including without limitation the rights to use, copy, modify, merge, publish, distribute,
8
+ sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
6
10
 
7
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+ The above copyright notice and this permission notice shall be included in all copies or substantial
12
+ portions of the Software.
8
13
 
9
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
15
+ NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
17
+ OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -31,7 +31,6 @@ Here is all the available options with their default values:
31
31
  import eslintConfig from "@keeex/eslint-config";
32
32
 
33
33
  export default await eslintConfig({
34
- full: false,
35
34
  globals: [
36
35
  {globals: {builtin: true, es2025: true}},
37
36
  {
@@ -55,6 +54,10 @@ export default await eslintConfig({
55
54
  globals: {mocha: true},
56
55
  },
57
56
  ],
57
+ environments: {
58
+ node: ["", "src/**"],
59
+ mocha: "src/tests/**",
60
+ },
58
61
  ignores: ["lib", "web", "gen", "src/gen"],
59
62
  import: 3,
60
63
  mocha: true,
@@ -70,12 +73,6 @@ by hand. Good luck with that.
70
73
 
71
74
  ## Configuration
72
75
 
73
- ### `full`
74
-
75
- Enable some deeper, more costly checks. This is enabled automatically if the environment variable
76
- "KXESLINT" is set to "full", or if "GIT_HOOK_NAME" is set to "pre-push". You can enable it manually
77
- by passing `full: true` to the eslint config function.
78
-
79
76
  ### `globals`
80
77
 
81
78
  The `globals` property is an array of object to define which globals are available in the code. Each
@@ -94,6 +91,64 @@ be considered, and `globals`, which is an object that can have the following pro
94
91
  - "custom": an object of custom identifiers to be made available, whose keys are the identifiers and
95
92
  the values are boolean indicating if these identifiers are read-only (false) or not (true)
96
93
 
94
+ ### `environments`
95
+
96
+ Allows you to define general environments for specific directory. The full configuration is:
97
+
98
+ ```javascript
99
+ {
100
+ environments: {
101
+ node: ["", "src/bin/**", "src/server/**"],
102
+ webapp: ["src/webapp/**", "webres/*/js/**"],
103
+ mobile: ["src/mobile/**"],
104
+ mocha: ["src/tests/**"],
105
+ },
106
+ }
107
+ ```
108
+
109
+ The four type of environments are: "node", "webapp", "mobile" and "mocha". They set-up some globals
110
+ for the source files in the given directories, as well as restrict some rules (for example, if
111
+ "webapp" or "mobile" are defined, react will only apply to these directories).
112
+
113
+ As a shorthand, it is possible to set the `environments` property to a string, matching the
114
+ following options:
115
+
116
+ ```javascript
117
+ // "environments": "webservice"
118
+ {
119
+ "environments": {
120
+ "node": ["", "src/bin/**", "src/server/**"],
121
+ "webapp": ["src/webapp/**", "webres/*/js/**"],
122
+ "mocha": "src/tests/**"
123
+ }
124
+ }
125
+ // "environments": "webapp"
126
+ {
127
+ "environments": {
128
+ "webapp": ["src/**", "webres/*/js/**"]
129
+ }
130
+ }
131
+ // "environments": "mobile"
132
+ {
133
+ "environments": {
134
+ "mobile": "src/**"
135
+ }
136
+ }
137
+ // "environments": "library"
138
+ {
139
+ "environments": {
140
+ "mocha": "src/tests/**"
141
+ }
142
+ }
143
+ // "environments": "node"
144
+ {
145
+ "environments": {
146
+ "node": ["", "src/**"],
147
+ "mocha": "src/tests/**"
148
+ }
149
+ }
150
+ ```
151
+
97
152
  ### `ignores`
98
153
 
99
154
  Array of globs to globally ignore for eslint.
package/package.json CHANGED
@@ -15,12 +15,12 @@
15
15
  },
16
16
  "description": "Common eslint configuration",
17
17
  "devDependencies": {
18
- "@eslint/compat": "^1.2.2",
18
+ "@eslint/compat": "^1.2.3",
19
19
  "@eslint/js": "^9.12.0",
20
- "eslint": "^9.14.0",
20
+ "eslint": "^9.15.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.4.0",
23
+ "eslint-plugin-import-x": "^4.4.3",
24
24
  "eslint-plugin-mocha": "^10.5.0",
25
25
  "eslint-plugin-promise": "^7.1.0",
26
26
  "eslint-plugin-react": "^7.37.2",
@@ -28,7 +28,7 @@
28
28
  "eslint-plugin-tsdoc": "^0.3.0",
29
29
  "globals": "^15.12.0",
30
30
  "prettier": "^3.3.3",
31
- "typescript-eslint": "^8.13.0"
31
+ "typescript-eslint": "^8.15.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.4"
115
+ "version": "2.2.1"
116
116
  }
@@ -10,7 +10,6 @@ if (!fs.existsSync(eslintFile)) {
10
10
  "This command must be run in the root of the project and contain an eslint.config.js file.",
11
11
  );
12
12
  }
13
-
14
13
  const eslintConfig = (await import(eslintFile)).default;
15
14
  const JSON_INDENT = 2;
16
15
  console.log(JSON.stringify(eslintConfig, null, JSON_INDENT));
@@ -8,7 +8,6 @@ import * as deps from "../dependencies.js";
8
8
  import {setDepCheck} from "../environ.js";
9
9
 
10
10
  const getEslintConfig = () => path.resolve(process.cwd(), "eslint.config.js");
11
-
12
11
  const depsCheck = async () => {
13
12
  console.group("eslint dependencies checking…");
14
13
  try {
@@ -44,25 +43,20 @@ const depsCheck = async () => {
44
43
  console.groupEnd();
45
44
  }
46
45
  };
47
-
48
46
  const eslintRcCandidates = [".js", ".cjs", ".json"];
49
-
50
47
  const getEslintrcPath = () => {
51
48
  for (const candidate of eslintRcCandidates) {
52
49
  const eslintrcPath = path.join(process.cwd(), `.eslintrc${candidate}`);
53
50
  if (fs.existsSync(eslintrcPath)) return eslintrcPath;
54
51
  }
55
52
  };
56
-
57
53
  const deleteLine = "DELETE THIS LINE WHEN CONFIGURED";
58
-
59
54
  const defaultConfig = `
60
55
  // ${deleteLine}
61
56
  import eslintConfig from "@keeex/eslint-config";
62
57
 
63
58
  export default await eslintConfig({});
64
59
  `.trim();
65
-
66
60
  /** Return true if the flat config system is ok */
67
61
  const checkEslintConfig = () => {
68
62
  console.group("Checking eslint config file…");
@@ -105,9 +99,7 @@ const checkEslintConfig = () => {
105
99
  console.groupEnd();
106
100
  }
107
101
  };
108
-
109
102
  const PRETTIER_CONFIG = "prettier.config.js";
110
-
111
103
  const prettierSetup = () => {
112
104
  console.group("Checking prettier config");
113
105
  try {
@@ -128,7 +120,6 @@ export default config;
128
120
  console.groupEnd();
129
121
  }
130
122
  };
131
-
132
123
  const checkTsConfig = () => {
133
124
  const needTsConfig = deps.needDependencies("typescript-eslint");
134
125
  if (!needTsConfig) return;
@@ -141,7 +132,6 @@ const checkTsConfig = () => {
141
132
  console.groupEnd();
142
133
  }
143
134
  };
144
-
145
135
  const main = async () => {
146
136
  console.group("KeeeX eslint and prettier configuration setup");
147
137
  try {
@@ -154,5 +144,4 @@ const main = async () => {
154
144
  console.groupEnd();
155
145
  }
156
146
  };
157
-
158
147
  await main();
@@ -2,8 +2,8 @@
2
2
  import js from "@eslint/js";
3
3
  import pluginPromise from "eslint-plugin-promise";
4
4
 
5
+ import {getFiles} from "../pathutils.js";
5
6
  import * as sections from "../sections.js";
6
-
7
7
  /**
8
8
  * Apply the recommended eslint configuration plus KeeeX tweaks.
9
9
  *
@@ -27,10 +27,7 @@ export const apply = (configResult, eslintConfig) => {
27
27
  globalIgnores.ignores = [...eslintConfig.ignores];
28
28
  }
29
29
  // Base eslint
30
- configResult.push({
31
- name: "eslint/recommended",
32
- ...js.configs.recommended,
33
- });
30
+ configResult.push({name: "eslint/recommended", ...js.configs.recommended});
34
31
  const eslintCustom = sections.getNamedSection(configResult, "keeex/eslint-override");
35
32
  sections.configureRules(eslintCustom, "", {
36
33
  "array-callback-return": "error",
@@ -158,6 +155,9 @@ export const apply = (configResult, eslintConfig) => {
158
155
  "spec-only": "error",
159
156
  });
160
157
  const cjsOverride = sections.getNamedSection(configResult, "keeex/files-cjs");
161
- cjsOverride.files = ["**/*.cjs"];
158
+ cjsOverride.files = getFiles({
159
+ recursiveDirectories: "",
160
+ fileTypes: {cjs: true, esm: false, javascript: true},
161
+ });
162
162
  sections.sectionAddOption(cjsOverride, "languageOptions", "sourceType", "commonjs");
163
163
  };
@@ -1,9 +1,9 @@
1
1
  import globals from "globals";
2
2
 
3
+ import * as pathutils from "../pathutils.js";
3
4
  import * as sections from "../sections.js";
4
5
 
5
6
  const base = {builtin: true, es2025: true};
6
-
7
7
  /** Create the actual eslint globals object from user input */
8
8
  const getGlobalsFromConfig = (configGlobals) => {
9
9
  const res = {};
@@ -19,7 +19,62 @@ const getGlobalsFromConfig = (configGlobals) => {
19
19
  if (configGlobals?.custom) Object.assign(res, configGlobals.custom);
20
20
  return res;
21
21
  };
22
-
22
+ const addEnv = ({configResult, eslintConfig}, name, fileTypes, globalsEsm, globalsCjs) => {
23
+ const envDirs = pathutils.getEnvDirectories(name, eslintConfig.environments);
24
+ if (envDirs.length === 0) return;
25
+ const esmSection = sections.getNamedSection(configResult, `keeex/${name}-env-esm`);
26
+ esmSection.files = pathutils.getFiles({
27
+ exactDirectories: envDirs,
28
+ fileTypes: {
29
+ javascript: true,
30
+ typescript: eslintConfig.typescript,
31
+ ...fileTypes,
32
+ cjs: false,
33
+ esm: true,
34
+ },
35
+ });
36
+ const cjsSection = sections.getNamedSection(configResult, `keeex/${name}-env-cjs`);
37
+ cjsSection.files = pathutils.getFiles({
38
+ exactDirectories: envDirs,
39
+ fileTypes: {
40
+ javascript: true,
41
+ typescript: eslintConfig.typescript,
42
+ ...fileTypes,
43
+ cjs: true,
44
+ esm: false,
45
+ },
46
+ });
47
+ sections.sectionAddOption(
48
+ esmSection,
49
+ "languageOptions",
50
+ "globals",
51
+ getGlobalsFromConfig(globalsEsm),
52
+ );
53
+ sections.sectionAddOption(
54
+ cjsSection,
55
+ "languageOptions",
56
+ "globals",
57
+ getGlobalsFromConfig({...(globalsCjs ?? globalsEsm), commonjs: true}),
58
+ );
59
+ };
60
+ const addNodeEnv = (configResult, eslintConfig) => {
61
+ addEnv(
62
+ {configResult, eslintConfig},
63
+ "node",
64
+ {},
65
+ {node: true, worker: true},
66
+ {nodeCjs: true, worker: true},
67
+ );
68
+ };
69
+ const addWebappEnv = (configResult, eslintConfig) => {
70
+ addEnv({configResult, eslintConfig}, "webapp", {jsx: true}, {browser: true, serviceworker: true});
71
+ };
72
+ const addMobileEnv = (configResult, eslintConfig) => {
73
+ addEnv({configResult, eslintConfig}, "mobile", {jsx: true}, {browser: true});
74
+ };
75
+ const addMochaEnv = (configResult, eslintConfig) => {
76
+ addEnv({configResult, eslintConfig}, "mocha", {}, {mocha: true});
77
+ };
23
78
  export const apply = (configResult, eslintConfig) => {
24
79
  const sharedGlobals = eslintConfig.globals.find((c) => c.files === undefined) ?? {globals: {}};
25
80
  const sharedSection = sections.getNamedSection(configResult, "keeex/shared");
@@ -43,4 +98,8 @@ export const apply = (configResult, eslintConfig) => {
43
98
  getGlobalsFromConfig(globalConfig.globals),
44
99
  );
45
100
  }
101
+ addNodeEnv(configResult, eslintConfig);
102
+ addWebappEnv(configResult, eslintConfig);
103
+ addMobileEnv(configResult, eslintConfig);
104
+ addMochaEnv(configResult, eslintConfig);
46
105
  };
@@ -1,8 +1,7 @@
1
1
  import eslintPluginImportX from "eslint-plugin-import-x";
2
2
 
3
- import {isFullCheck} from "../environ.js";
3
+ import * as pathutils from "../pathutils.js";
4
4
  import * as sections from "../sections.js";
5
-
6
5
  /**
7
6
  * Apply the import-x configs
8
7
  *
@@ -11,10 +10,7 @@ import * as sections from "../sections.js";
11
10
  // eslint-disable-next-line max-lines-per-function
12
11
  export const apply = (configResult, eslintConfig) => {
13
12
  if (eslintConfig.import === false) return;
14
- configResult.push({
15
- ...eslintPluginImportX.flatConfigs.recommended,
16
- languageOptions: {},
17
- });
13
+ configResult.push({...eslintPluginImportX.flatConfigs.recommended, languageOptions: {}});
18
14
  if (eslintConfig.typescript) {
19
15
  configResult.push({
20
16
  ...eslintPluginImportX.flatConfigs.typescript,
@@ -36,10 +32,7 @@ export const apply = (configResult, eslintConfig) => {
36
32
  "order": [
37
33
  "warn",
38
34
  {
39
- "alphabetize": {
40
- order: "asc",
41
- caseInsensitive: true,
42
- },
35
+ "alphabetize": {order: "asc", caseInsensitive: true},
43
36
  "groups": [
44
37
  "builtin",
45
38
  "external",
@@ -75,11 +68,6 @@ export const apply = (configResult, eslintConfig) => {
75
68
  "no-named-as-default-member": "off",
76
69
  "no-unresolved": "off",
77
70
  });
78
- if (!isFullCheck()) {
79
- sections.configureRules(tsOverride, "import-x", {
80
- "no-named-as-default": "off",
81
- });
82
- }
83
71
  if (eslintConfig.react) {
84
72
  sections.sectionAddOption(tsOverride, "settings", "import-x/extensions", [".ts", ".tsx"]);
85
73
  } else {
@@ -88,7 +76,7 @@ export const apply = (configResult, eslintConfig) => {
88
76
  } else {
89
77
  sections.configureRules(override, "import-x", {
90
78
  "extensions": ["error", "ignorePackages"],
91
- "no-deprecated": isFullCheck() ? "warn" : "off",
79
+ "no-deprecated": "warn",
92
80
  "no-extraneous-dependencies": "error",
93
81
  });
94
82
  if (eslintConfig.react) {
@@ -100,10 +88,31 @@ export const apply = (configResult, eslintConfig) => {
100
88
  }
101
89
  if (eslintConfig.react) {
102
90
  const webOverride = sections.getNamedSection(configResult, "keeex/importx-override-webapp");
103
- webOverride.files = ["src/webapp"];
91
+ webOverride.files = pathutils.getFilesEnv(
92
+ eslintConfig,
93
+ ["webapp", "mobile"],
94
+ undefined,
95
+ {
96
+ cjs: true,
97
+ esm: true,
98
+ javascript: true,
99
+ jsx: true,
100
+ typescript: Boolean(eslintConfig.typescript),
101
+ },
102
+ "src/webapp",
103
+ );
104
104
  sections.sectionAddOption(webOverride, "settings", "import-x/resolver", "webpack");
105
105
  }
106
106
  const overrideCjs = sections.getNamedSection(configResult, "keeex/importx-override-cjs");
107
- overrideCjs.files = ["**/*.cjs"];
107
+ overrideCjs.files = pathutils.getFiles({
108
+ recursiveDirectories: "",
109
+ fileTypes: {
110
+ cjs: true,
111
+ esm: false,
112
+ javascript: true,
113
+ jsx: Boolean(eslintConfig.react),
114
+ typescript: Boolean(eslintConfig.typescript),
115
+ },
116
+ });
108
117
  sections.configureRules(overrideCjs, "import-x", {"no-commonjs": "off"});
109
118
  };
@@ -1,34 +1,24 @@
1
1
  import mochaPlugin from "eslint-plugin-mocha";
2
2
 
3
- import {getFiles} from "../pathutils.js";
3
+ import {getFilesEnv} from "../pathutils.js";
4
4
  import * as sections from "../sections.js";
5
5
 
6
6
  export const apply = (configResult, eslintConfig) => {
7
7
  if (!eslintConfig.mocha) return;
8
8
  const fileTypes = {
9
+ cjs: true,
10
+ esm: true,
9
11
  javascript: true,
10
12
  jsx: Boolean(eslintConfig.react),
11
13
  typescript: eslintConfig.typescript,
12
14
  };
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
- ]);
25
- const mochaSection = {
26
- ...mochaPlugin.configs.flat.recommended,
27
- files: mochaFilter,
28
- };
15
+ const mochaFilter1 = getFilesEnv(eslintConfig, "mocha", undefined, fileTypes, "src/tests");
16
+ const mochaFilter2 = getFilesEnv(eslintConfig, "mocha", "*.test.ext", fileTypes, "src");
17
+ const files = [...mochaFilter1, ...mochaFilter2];
18
+ const mochaSection = {...mochaPlugin.configs.flat.recommended, files};
29
19
  configResult.push(mochaSection);
30
20
  const override = sections.getNamedSection(configResult, "keeex/mocha");
31
- override.files = mochaFilter;
21
+ override.files = files;
32
22
  sections.configureRules(override, "", {
33
23
  "max-classes-per-file": "off",
34
24
  "max-lines": "off",
@@ -10,9 +10,6 @@ export const apply = (configResult, eslintConfig) => {
10
10
  files: ["src/webapp/**/*.js", "**/*.jsx", "**/*.tsx"],
11
11
  name: "react-hooks/recommended",
12
12
  plugins: {"react-hooks": fixupPluginRules(eslintPluginReactHooks)},
13
- rules: {
14
- "react-hooks/rules-of-hooks": "error",
15
- "react-hooks/exhaustive-deps": "warn",
16
- },
13
+ rules: {"react-hooks/rules-of-hooks": "error", "react-hooks/exhaustive-deps": "warn"},
17
14
  });
18
15
  };
@@ -1,25 +1,27 @@
1
1
  /* eslint-disable no-magic-numbers */
2
2
  import reactPlugin from "eslint-plugin-react";
3
3
 
4
+ import {getFilesEnv} from "../pathutils.js";
4
5
  import * as sections from "../sections.js";
5
6
 
6
7
  import {getReactFullConfig} from "./reactfullconfig.js";
7
-
8
8
  // eslint-disable-next-line max-lines-per-function
9
9
  export const apply = (configResult, eslintConfig) => {
10
10
  const reactCfg = getReactFullConfig(eslintConfig.react);
11
11
  if (!reactCfg.react) return;
12
+ const files = getFilesEnv(eslintConfig, ["webapp", "mobile"], undefined, {
13
+ cjs: true,
14
+ esm: true,
15
+ javascript: true,
16
+ jsx: true,
17
+ typescript: Boolean(eslintConfig.typescript),
18
+ });
12
19
  configResult.push(
13
- {
14
- ...reactPlugin.configs.flat.recommended,
15
- name: "react/recommended",
16
- },
17
- {
18
- ...reactPlugin.configs.flat["jsx-runtime"],
19
- name: "react/jsx-runtime",
20
- },
20
+ {...reactPlugin.configs.flat.recommended, files, name: "react/recommended"},
21
+ {...reactPlugin.configs.flat["jsx-runtime"], files, name: "react/jsx-runtime"},
21
22
  );
22
23
  const override = sections.getNamedSection(configResult, "keeex/react");
24
+ override.files = files;
23
25
  sections.sectionAddOption(override, "settings", "react", {version: "detect"});
24
26
  sections.configureRules(override, "react", {
25
27
  "button-has-type": "warn",
@@ -31,11 +33,7 @@ export const apply = (configResult, eslintConfig) => {
31
33
  "jsx-child-element-spacing": "warn",
32
34
  "jsx-curly-brace-presence": [
33
35
  "error",
34
- {
35
- children: "never",
36
- propElementValues: "always",
37
- props: "never",
38
- },
36
+ {children: "never", propElementValues: "always", props: "never"},
39
37
  ],
40
38
  "jsx-curly-newline": "warn",
41
39
  "jsx-curly-spacing": "warn",
@@ -48,7 +46,7 @@ export const apply = (configResult, eslintConfig) => {
48
46
  "jsx-max-depth": ["warn", {max: 8}],
49
47
  "jsx-no-bind": "error",
50
48
  "jsx-no-constructed-context-values": "error",
51
- "jsx-no-leaked-render": "warn",
49
+ "jsx-no-leaked-render": ["warn", {validStrategies: ["coerce"]}],
52
50
  "jsx-no-script-url": "error",
53
51
  "jsx-no-useless-fragment": "warn",
54
52
  "jsx-pascal-case": ["warn", {allowNamespace: true}],
@@ -6,7 +6,6 @@ import tseslint from "typescript-eslint";
6
6
  import * as sections from "../sections.js";
7
7
 
8
8
  const filterForFiles = (rules, files) => rules.map((c) => ({...c, files}));
9
-
10
9
  /**
11
10
  * Apply the recommended typescript-eslint configuration plus KeeeX tweaks.
12
11
  *
package/src/defaults.js CHANGED
@@ -1,40 +1,13 @@
1
- import {isFullCheck} from "./environ.js";
2
-
3
1
  /** List of ignored patterns by default */
4
2
  export const ignores = ["lib", "web", "gen", "src/gen"];
5
-
6
3
  /** Default globals affected to all projects */
7
4
  export const globals = [
8
- {
9
- globals: {
10
- builtin: true,
11
- es2025: true,
12
- },
13
- },
14
- {
15
- files: ["**/*.cjs"],
16
- globals: {commonjs: true},
17
- },
18
- {
19
- files: ["src/webapp/**/*"],
20
- globals: {
21
- browser: true,
22
- serviceworker: true,
23
- },
24
- },
25
- {
26
- files: ["src/bin/**/*", "src/server/**/*", "*"],
27
- globals: {node: true},
28
- },
29
- {
30
- files: ["*.cjs"],
31
- globals: {nodeCjs: true},
32
- },
33
- {
34
- files: ["src/tests/**/*", "src/**/*.test.*"],
35
- globals: {mocha: true},
36
- },
5
+ {globals: {builtin: true, es2025: true}},
6
+ {files: ["**/*.cjs"], globals: {commonjs: true}},
7
+ {files: ["src/webapp/**/*"], globals: {browser: true, serviceworker: true}},
8
+ {files: ["src/bin/**/*", "src/server/**/*", "*"], globals: {node: true}},
9
+ {files: ["*.cjs"], globals: {nodeCjs: true}},
10
+ {files: ["src/tests/**/*", "src/**/*.test.*"], globals: {mocha: true}},
37
11
  ];
38
-
39
12
  /** Import cycle max depth */
40
- export const cycleMaxDepth = isFullCheck() ? true : 0;
13
+ export const cycleMaxDepth = true;
@@ -6,10 +6,8 @@ import * as path from "node:path";
6
6
  import {satisfies} from "semver";
7
7
 
8
8
  import {getReactFullConfig} from "./config/reactfullconfig.js";
9
-
10
9
  /** name => {version: string, force: boolean} */
11
10
  const requiredDependencies = {};
12
-
13
11
  /** List of dependencies no longer used and that should be removed */
14
12
  const removedDependencies = [
15
13
  "@typescript-eslint/eslint-plugin",
@@ -20,11 +18,8 @@ const removedDependencies = [
20
18
  "eslint-plugin-import",
21
19
  "eslint-plugin-react-native",
22
20
  ];
23
-
24
21
  let pkgJson;
25
-
26
22
  export const needDependencies = (name) => name in requiredDependencies;
27
-
28
23
  /**
29
24
  * Retrieve the current project's "package.json".
30
25
  *
@@ -41,7 +36,6 @@ export const getPkgJson = () => {
41
36
  }
42
37
  return pkgJson;
43
38
  };
44
-
45
39
  /** Get installed package version */
46
40
  const getInstalledVersion = (name) => {
47
41
  try {
@@ -53,7 +47,6 @@ const getInstalledVersion = (name) => {
53
47
  return "<unknown>";
54
48
  }
55
49
  };
56
-
57
50
  /**
58
51
  * Check if a particular dependency is installed in the project.
59
52
  *
@@ -67,7 +60,6 @@ const dependencyStatus = (name) => {
67
60
  const version = installed === "missing" ? undefined : getInstalledVersion(name);
68
61
  return {installed, version};
69
62
  };
70
-
71
63
  /**
72
64
  * Add an NPM dependency to the list
73
65
  *
@@ -78,7 +70,6 @@ const dependencyStatus = (name) => {
78
70
  export const addDependency = (depName, version) => {
79
71
  requiredDependencies[depName] = {version: version ?? true, force: false};
80
72
  };
81
-
82
73
  /**
83
74
  * Run a process, and display the output if an error occured.
84
75
  *
@@ -99,7 +90,6 @@ const runProcess = (cmd, ...args) => {
99
90
  }
100
91
  return true;
101
92
  };
102
-
103
93
  /**
104
94
  * List all missing/extra dependencies.
105
95
  *
@@ -129,7 +119,6 @@ export const listDependencies = () => {
129
119
  console.groupEnd();
130
120
  }
131
121
  };
132
-
133
122
  /**
134
123
  * Run the required installation/removal.
135
124
  *
@@ -161,7 +150,6 @@ export const installAndRemoveDeps = () => {
161
150
  }
162
151
  return true;
163
152
  };
164
-
165
153
  /** Add all dependencies needed by the provided config */
166
154
  export const configToDependencies = (eslintConfig) => {
167
155
  addDependency("eslint", "9.x");
package/src/environ.js CHANGED
@@ -2,15 +2,5 @@
2
2
  export const setDepCheck = () => {
3
3
  process.env.KEEEX_DEPCHECK = "true";
4
4
  };
5
-
6
5
  /** Check the depcheck flag */
7
6
  export const isDepCheck = () => process.env.KEEEX_DEPCHECK === "true";
8
-
9
- /** Enable the full check */
10
- export const setFullCheck = () => {
11
- process.env.KXESLINT = "full";
12
- };
13
-
14
- /** Check deeper checks flag */
15
- export const isFullCheck = () =>
16
- process.env.KXESLINT === "full" || process.env.GIT_HOOK_NAME === "pre-push";
package/src/index.js CHANGED
@@ -1,14 +1,12 @@
1
1
  import * as lazy from "./config/lazy.js";
2
2
  import {getReactFullConfig} from "./config/reactfullconfig.js";
3
3
  import * as defaults from "./defaults.js";
4
-
5
4
  import {configToDependencies} from "./dependencies.js";
6
5
  import * as environ from "./environ.js";
7
6
  import {clearConfig} from "./sections.js";
8
-
9
7
  /** Setup all defaults in the eslintParams config */
10
8
  const configDefaults = (eslintParams) => ({
11
- full: eslintParams?.full ?? false,
9
+ environments: eslintParams?.environments ?? "node",
12
10
  globals: eslintParams?.globals ?? defaults.globals,
13
11
  ignores: eslintParams?.ignores ?? defaults.ignores,
14
12
  import: eslintParams?.import ?? defaults.cycleMaxDepth,
@@ -17,7 +15,6 @@ const configDefaults = (eslintParams) => ({
17
15
  react: eslintParams?.react ?? false,
18
16
  typescript: eslintParams?.typescript ?? true,
19
17
  });
20
-
21
18
  /**
22
19
  * Build the eslint configuration from the provided settings.
23
20
  *
@@ -47,7 +44,8 @@ const configDefaults = (eslintParams) => ({
47
44
  *
48
45
  * @param [eslintParams.mocha] {boolean} - Enable mocha plugins
49
46
  *
50
- * @param [eslintParams.full] {boolean} - Enable full check mode
47
+ * @param [eslintParams.environments] {object} - Directory for various environments.
48
+ * Known environments are "node", "webapp", "mobile", "library", "mocha".
51
49
  *
52
50
  * @returns
53
51
  * The eslint config object
@@ -55,7 +53,6 @@ const configDefaults = (eslintParams) => ({
55
53
  const eslintConfig = async (eslintParams) => {
56
54
  const fullConfig = configDefaults(eslintParams);
57
55
  const res = [];
58
- if (fullConfig.full) environ.setFullCheck();
59
56
  if (environ.isDepCheck()) {
60
57
  configToDependencies(fullConfig);
61
58
  } else {
@@ -71,5 +68,4 @@ const eslintConfig = async (eslintParams) => {
71
68
  }
72
69
  return res;
73
70
  };
74
-
75
71
  export default eslintConfig;
package/src/pathutils.js CHANGED
@@ -2,7 +2,34 @@ const asArray = (value) => {
2
2
  if (Array.isArray(value)) return value;
3
3
  return [value];
4
4
  };
5
-
5
+ const envShorthands = {
6
+ library: {mocha: "src/tests/**", node: ""},
7
+ mobile: {mobile: "src/**"},
8
+ node: {node: ["", "src/**"], mocha: "src/tests/**"},
9
+ webapp: {webapp: ["src/**", "webres/*/js/**"]},
10
+ webservice: {
11
+ mocha: "src/tests/**",
12
+ node: ["", "bin/**", "src/bin/**", "src/server/**"],
13
+ webapp: ["src/webapp/**", "webres/*/js/**"],
14
+ },
15
+ };
16
+ const getEffectiveEnv = (configEnv) => {
17
+ if (typeof configEnv !== "string") return configEnv;
18
+ return envShorthands[configEnv];
19
+ };
20
+ /**
21
+ * @param {Array<string>|string} environments - List of environments to pull
22
+ * @param {Array<string>|string} configEnv - List of configured environments
23
+ */
24
+ export const getEnvDirectories = (environments, configEnv, defaultDir) => {
25
+ const effectiveEnv = getEffectiveEnv(configEnv);
26
+ const dirs = [];
27
+ for (const env of asArray(environments)) {
28
+ if (env in effectiveEnv) dirs.push(...asArray(effectiveEnv[env]));
29
+ }
30
+ if (dirs.length === 0 && defaultDir) return [defaultDir];
31
+ return dirs;
32
+ };
6
33
  export const getExtensions = (fileTypes) => {
7
34
  const result = [];
8
35
  const esm = fileTypes.esm ?? true;
@@ -13,7 +40,7 @@ export const getExtensions = (fileTypes) => {
13
40
  }
14
41
  if (fileTypes.typescript) {
15
42
  if (esm) result.push(".ts", ".mts");
16
- if (cjs) result.push(".mts");
43
+ if (cjs) result.push(".cts");
17
44
  }
18
45
  if (fileTypes.jsx) {
19
46
  if (esm) result.push(".jsx");
@@ -21,7 +48,6 @@ export const getExtensions = (fileTypes) => {
21
48
  }
22
49
  return result;
23
50
  };
24
-
25
51
  /** Configuration to build a filter list */
26
52
  // interface FilesDefinition {
27
53
  // /** Directories where the files are; no recursion */
@@ -44,22 +70,26 @@ export const getExtensions = (fileTypes) => {
44
70
  // /** Support ESM */
45
71
  // esm: boolean;
46
72
  // /** Support CommonJS */
47
- // commonjs: boolean;
73
+ // cjs: boolean;
48
74
  // };
49
75
  // }
50
-
51
76
  const extPlaceholder = ".ext";
52
-
53
77
  export const getFiles = (definitions) => {
54
78
  const result = new Set();
55
79
  for (const definition of asArray(definitions)) {
56
80
  const extensions = getExtensions(definition.fileTypes);
57
81
  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}/**`));
82
+ if (definition.exactDirectories !== undefined) {
83
+ directories.add(...asArray(definition.exactDirectories));
84
+ }
85
+ if (definition.recursiveDirectories !== undefined) {
86
+ directories.add(
87
+ ...asArray(definition.recursiveDirectories).map((c) => (c === "" ? "**" : `${c}/**`)),
88
+ );
61
89
  }
62
- const filePatterns = new Set(asArray(definition.filePatterns) ?? [`*${extPlaceholder}`]);
90
+ const filePatterns = new Set(
91
+ definition.filePatterns ? asArray(definition.filePatterns) : [`*${extPlaceholder}`],
92
+ );
63
93
  for (const directory of directories) {
64
94
  for (const filePattern of filePatterns) {
65
95
  if (filePattern.includes(extPlaceholder)) {
@@ -74,3 +104,14 @@ export const getFiles = (definitions) => {
74
104
  }
75
105
  return Array.from(result);
76
106
  };
107
+ /** Get a list of file glob depending on config and requested file types */
108
+ export const getFilesEnv = (eslintConfig, environments, filePatterns, fileTypes, defaultDir) => {
109
+ const effectiveFileTypes = fileTypes
110
+ ? {...fileTypes}
111
+ : {cjs: true, esm: true, javascript: true, typescript: Boolean(eslintConfig.typescript)};
112
+ return getFiles({
113
+ exactDirectories: getEnvDirectories(environments, eslintConfig.environments, defaultDir),
114
+ filePatterns,
115
+ fileTypes: effectiveFileTypes,
116
+ });
117
+ };
package/src/sections.js CHANGED
@@ -15,7 +15,6 @@ export const getNamedSection = (configResult, name) => {
15
15
  configResult.push(newSection);
16
16
  return newSection;
17
17
  };
18
-
19
18
  /**
20
19
  * Add a property in an object on the provided section.
21
20
  *
@@ -38,7 +37,6 @@ export const sectionAddOption = (configSection, optionGroup, optionName, value)
38
37
  configSection[optionGroup][optionName] = value;
39
38
  }
40
39
  };
41
-
42
40
  /** Merge/create the rules property */
43
41
  export const configureRules = (configSection, prefix, rules) => {
44
42
  let prefixed = {};
@@ -49,7 +47,6 @@ export const configureRules = (configSection, prefix, rules) => {
49
47
  }
50
48
  configSection.rules = {...configSection.rules, ...prefixed};
51
49
  };
52
-
53
50
  /** Remove the `_kxconfig` property from all sections and return a suitable object. */
54
51
  export const clearConfig = (configResult) => {
55
52
  const emptySectionsId = [];