@keeex/eslint-config 2.1.2 → 2.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/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Common eslint configuration for KeeeX
2
2
 
3
3
  ## Description
4
+
4
5
  Manage the eslint and prettier configuration used through all KeeeX projects.
5
6
 
6
7
  ### tl;dr
@@ -12,6 +13,7 @@ Manage the eslint and prettier configuration used through all KeeeX projects.
12
13
  - enable eslint and prettier in whatever you use
13
14
 
14
15
  ## Installation
16
+
15
17
  The package is available on npmjs and can be installed with any package manager that supports it.
16
18
 
17
19
  ```bash
@@ -19,9 +21,9 @@ npm install -D @keeex/eslint-config
19
21
  ```
20
22
 
21
23
  ## Usage
24
+
22
25
  To prepare the configuration file, you can run `npx kxeslint-setup` to create a blank config file.
23
- Alternatively, you can create the file yourself.
24
- In both cases, it will be named `eslint.config.js`.
26
+ Alternatively, you can create the file yourself. In both cases, it will be named `eslint.config.js`.
25
27
 
26
28
  Here is all the available options with their default values:
27
29
 
@@ -29,6 +31,7 @@ Here is all the available options with their default values:
29
31
  import eslintConfig from "@keeex/eslint-config";
30
32
 
31
33
  export default await eslintConfig({
34
+ full: false,
32
35
  globals: [
33
36
  {globals: {builtin: true, es2025: true}},
34
37
  {
@@ -56,21 +59,27 @@ export default await eslintConfig({
56
59
  import: 3,
57
60
  mocha: true,
58
61
  noBase: false,
59
- react: {react: false, reactHooks: false, reactNative: false},
62
+ react: false,
60
63
  typescript: true,
61
64
  });
62
65
  ```
63
66
 
64
- If any of the top-level property is not defined, it will be set to its default value.
65
- If you want to customize the output, instead of directly exporting the return value of the function
66
- you can edit it by hand.
67
- Good luck with that.
67
+ If any of the top-level property is not defined, it will be set to its default value. If you want to
68
+ customize the output, instead of directly exporting the return value of the function you can edit it
69
+ by hand. Good luck with that.
68
70
 
69
71
  ## Configuration
70
72
 
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
+
71
79
  ### `globals`
72
- The `globals` property is an array of object to define which globals are available in the code.
73
- Each of these objects can have two properties: `files`, which is an array of globs to match the files to
80
+
81
+ The `globals` property is an array of object to define which globals are available in the code. Each
82
+ of these objects can have two properties: `files`, which is an array of globs to match the files to
74
83
  be considered, and `globals`, which is an object that can have the following properties:
75
84
 
76
85
  - "builtin": generic JS built-in globals
@@ -86,43 +95,46 @@ be considered, and `globals`, which is an object that can have the following pro
86
95
  the values are boolean indicating if these identifiers are read-only (false) or not (true)
87
96
 
88
97
  ### `ignores`
98
+
89
99
  Array of globs to globally ignore for eslint.
90
100
 
91
101
  ### `import`
92
- Some extra rules for formatting and ordering imports can be used by setting
93
- `import` to true (enabled by default with a depth of 3).
94
- It is possible to pass a number instead of a boolean to limit the depth of circular imports check.
95
- This greatly improves performances, at the risk of missing a dependency cycle.
102
+
103
+ Some extra rules for formatting and ordering imports can be used by setting `import` to true
104
+ (enabled by default with a depth of 3). It is possible to pass a number instead of a boolean to
105
+ limit the depth of circular imports check. This greatly improves performances, at the risk of
106
+ missing a dependency cycle.
96
107
 
97
108
  ### `mocha`
98
- To enable mocha-specific rules, as well as loosen some regular rules for
99
- testing, set `mocha` to true.
109
+
110
+ To enable mocha-specific rules, as well as loosen some regular rules for testing, set `mocha` to
111
+ true.
100
112
 
101
113
  ### `noBase`
102
- The base configuration imports all eslint recommendeds rules and promises handling rules.
103
- Setting `noBase` to true removes that.
104
- There is absolutely no reason to do so.
114
+
115
+ The base configuration imports all eslint recommendeds rules and promises handling rules. Setting
116
+ `noBase` to true removes that. There is absolutely no reason to do so.
105
117
 
106
118
  ### `react`
107
- To improve handling of React/JSX, set `react` to true.
108
- You can also pass an object with the following boolean properties:
109
119
 
110
- - `react`: enable/disable react rules
120
+ To improve handling of React/JSX, set `react` to true. You can also pass an object with the
121
+ following boolean properties:
122
+
111
123
  - `reactHooks`: enable/disable React hooks rules
112
- - `reactNative`: enable/disable React Native rules
113
124
 
114
- You can't enable the hooks or React Native rules without enabling React.
125
+ You can't enable the hooks rules without enabling React, so if an object is provided React support
126
+ is automatically enabled.
115
127
 
116
128
  ### `typescript`
117
- Set to `true` (the default value) to enable all TypeScript rules.
118
- This includes tsdoc rules.
129
+
130
+ Set to `true` (the default value) to enable all TypeScript rules. This includes tsdoc rules.
119
131
 
120
132
  ## Dependencies
133
+
121
134
  This configuration depends on various packages to be available depending on the user settings for
122
- each individual projects.
123
- You can list the required dependencies for the current configuration by running
124
- `npx kxeslint-setup`.
125
- You can also automatically install missing dependencies by adding the "auto" flag to the command.
135
+ each individual projects. You can list the required dependencies for the current configuration by
136
+ running `npx kxeslint-setup`. You can also automatically install missing dependencies by adding the
137
+ "auto" flag to the command.
126
138
 
127
139
  All dependencies are set as peer dependencies, as they are almost all optional depending on local
128
140
  settings.
@@ -130,10 +142,12 @@ settings.
130
142
  The tool will also uninstall older dependencies that we used to have but are not used anymore.
131
143
 
132
144
  ## Migration from .eslintrc.cjs
145
+
133
146
  When running `npx kxeslint-setup`, the tool will automatically detect an existing `.eslintrc.cjs`
134
- file and provides instructions for the migration.
135
- The migration process is manual; you have to update the new `eslint.config.js` file by hand.
147
+ file and provides instructions for the migration. The migration process is manual; you have to
148
+ update the new `eslint.config.js` file by hand.
136
149
 
137
150
  ## Debugging config issues
151
+
138
152
  Running `npx eslint --inspect-config` will launch a debugger interface that allows checking all the
139
153
  rules and individual file rules.
package/package.json CHANGED
@@ -17,15 +17,14 @@
17
17
  "devDependencies": {
18
18
  "@eslint/compat": "^1.2.1",
19
19
  "@eslint/js": "^9.12.0",
20
- "eslint": "9.x",
20
+ "eslint": "^9.13.0",
21
21
  "eslint-import-resolver-typescript": "^3.6.3",
22
22
  "eslint-import-resolver-webpack": "^0.13.9",
23
23
  "eslint-plugin-import-x": "^4.3.1",
24
24
  "eslint-plugin-mocha": "^10.5.0",
25
25
  "eslint-plugin-promise": "^7.1.0",
26
- "eslint-plugin-react": "^7.37.1",
27
- "eslint-plugin-react-hooks": "^5.1.0-rc-83825814-20241015",
28
- "eslint-plugin-react-native": "^4.1.0",
26
+ "eslint-plugin-react": "^7.37.2",
27
+ "eslint-plugin-react-hooks": "^5.0.0",
29
28
  "eslint-plugin-tsdoc": "^0.3.0",
30
29
  "globals": "^15.11.0",
31
30
  "prettier": "^3.3.3",
@@ -38,10 +37,6 @@
38
37
  "license": "MIT",
39
38
  "main": "src/index.js",
40
39
  "name": "@keeex/eslint-config",
41
- "overrides": {
42
- "eslint": "9.x",
43
- "eslint-plugin-react-native": "^4.1.0"
44
- },
45
40
  "peerDependencies": {
46
41
  "@eslint/compat": "^1.2.0",
47
42
  "@eslint/js": "9.x",
@@ -53,7 +48,6 @@
53
48
  "eslint-plugin-promise": "7.x",
54
49
  "eslint-plugin-react": "7.x",
55
50
  "eslint-plugin-react-hooks": "5.x",
56
- "eslint-plugin-react-native": "4.x",
57
51
  "eslint-plugin-tsdoc": "0.x",
58
52
  "globals": "15.x",
59
53
  "prettier": "3.x",
@@ -90,9 +84,6 @@
90
84
  "eslint-plugin-react-hooks": {
91
85
  "optional": true
92
86
  },
93
- "eslint-plugin-react-native": {
94
- "optional": true
95
- },
96
87
  "eslint-plugin-tsdoc": {
97
88
  "optional": true
98
89
  },
@@ -121,5 +112,5 @@
121
112
  "test": "echo No test for this project"
122
113
  },
123
114
  "type": "module",
124
- "version": "2.1.2"
115
+ "version": "2.1.3"
125
116
  }
@@ -21,7 +21,7 @@ const getGlobalsFromConfig = (configGlobals) => {
21
21
  };
22
22
 
23
23
  export const apply = (configResult, eslintConfig) => {
24
- const sharedGlobals = eslintConfig.globals.find((c) => c.files === undefined);
24
+ const sharedGlobals = eslintConfig.globals.find((c) => c.files === undefined) ?? {globals: {}};
25
25
  const sharedSection = sections.getNamedSection(configResult, "keeex/shared");
26
26
  sections.sectionAddOption(
27
27
  sharedSection,
@@ -4,5 +4,4 @@ export const importx = () => import("./importx.js");
4
4
  export const mocha = () => import("./mocha.js");
5
5
  export const react = () => import("./react.js");
6
6
  export const reactHooks = () => import("./react/reacthooks.js");
7
- export const reactNative = () => import("./react/reactnative.js");
8
7
  export const typescript = () => import("./typescript.js");
@@ -1,3 +1,4 @@
1
+ import {fixupPluginRules} from "@eslint/compat";
1
2
  import eslintPluginReactHooks from "eslint-plugin-react-hooks";
2
3
 
3
4
  import {getReactFullConfig} from "../reactfullconfig.js";
@@ -6,8 +7,12 @@ export const apply = (configResult, eslintConfig) => {
6
7
  const reactCfg = getReactFullConfig(eslintConfig.react);
7
8
  if (!reactCfg.reactHooks) return;
8
9
  configResult.push({
9
- ...eslintPluginReactHooks.configs.recommended,
10
10
  files: ["src/webapp/**/*.js", "**/*.jsx", "**/*.tsx"],
11
11
  name: "react-hooks/recommended",
12
+ plugins: {"react-hooks": fixupPluginRules(eslintPluginReactHooks)},
13
+ rules: {
14
+ "react-hooks/rules-of-hooks": "error",
15
+ "react-hooks/exhaustive-deps": "warn",
16
+ },
12
17
  });
13
18
  };
@@ -5,14 +5,9 @@ export const getReactFullConfig = (configEntry) => {
5
5
  return {react: false, reactHooks: false, reactNative: false};
6
6
  }
7
7
  const cfg = {
8
- react: configEntry?.react ?? false,
8
+ react: true,
9
9
  reactHooks: configEntry?.reactHooks ?? false,
10
10
  reactNative: configEntry?.reactNative ?? false,
11
11
  };
12
- if (!cfg.react && (cfg.reactHooks || cfg.reactNative)) {
13
- throw new Error(
14
- "Invalid react config; react must be enabled for react-native and react-hooks to be enabled too.",
15
- );
16
- }
17
12
  return cfg;
18
13
  };
@@ -18,6 +18,7 @@ const removedDependencies = [
18
18
  "eslint-plugin-deprecation",
19
19
  "eslint-plugin-i",
20
20
  "eslint-plugin-import",
21
+ "eslint-plugin-react-native",
21
22
  ];
22
23
 
23
24
  let pkgJson;
@@ -166,7 +167,7 @@ export const configToDependencies = (eslintConfig) => {
166
167
  addDependency("eslint", "9.x");
167
168
  addDependency("prettier", "3.x");
168
169
  if (eslintConfig.globals) addDependency("globals", "15.x");
169
- if (eslintConfig.import) {
170
+ if (eslintConfig.import !== false) {
170
171
  addDependency("eslint-plugin-import-x", "4.x");
171
172
  if (eslintConfig.typescript) addDependency("eslint-import-resolver-typescript", "3.x");
172
173
  }
@@ -187,7 +188,6 @@ export const configToDependencies = (eslintConfig) => {
187
188
  }
188
189
  if (eslintConfig.typescript) {
189
190
  addDependency("typescript-eslint", "8.x");
190
- addDependency("@typescript-eslint/parser", "8.x");
191
191
  addDependency("eslint-plugin-tsdoc", "0.x");
192
192
  }
193
193
  };
package/src/environ.js CHANGED
@@ -6,6 +6,11 @@ export const setDepCheck = () => {
6
6
  /** Check the depcheck flag */
7
7
  export const isDepCheck = () => process.env.KEEEX_DEPCHECK === "true";
8
8
 
9
- /** Enable deeper checks */
9
+ /** Enable the full check */
10
+ export const setFullCheck = () => {
11
+ process.env.KXESLINT = "full";
12
+ };
13
+
14
+ /** Check deeper checks flag */
10
15
  export const isFullCheck = () =>
11
16
  process.env.KXESLINT === "full" || process.env.GIT_HOOK_NAME === "pre-push";
package/src/index.js CHANGED
@@ -3,11 +3,12 @@ import {getReactFullConfig} from "./config/reactfullconfig.js";
3
3
  import * as defaults from "./defaults.js";
4
4
 
5
5
  import {configToDependencies} from "./dependencies.js";
6
- import {isDepCheck} from "./environ.js";
6
+ import * as environ from "./environ.js";
7
7
  import {clearConfig} from "./sections.js";
8
8
 
9
9
  /** Setup all defaults in the eslintParams config */
10
10
  const configDefaults = (eslintParams) => ({
11
+ full: eslintParams?.full ?? false,
11
12
  globals: eslintParams?.globals ?? defaults.globals,
12
13
  ignores: eslintParams?.ignores ?? defaults.ignores,
13
14
  import: eslintParams?.import ?? defaults.cycleMaxDepth,
@@ -43,17 +44,19 @@ const configDefaults = (eslintParams) => ({
43
44
  *
44
45
  * @param [eslintParams.react] {object|false} - If trueish, enable React support.
45
46
  * @param [eslintParams.react.reactHooks] {boolean} - Enable react-hooks stuff.
46
- * @param [eslintParams.react.reactNative] {boolean} - Enable react-native stuff.
47
47
  *
48
48
  * @param [eslintParams.mocha] {boolean} - Enable mocha plugins
49
49
  *
50
+ * @param [eslintParams.full] {boolean} - Enable full check mode
51
+ *
50
52
  * @returns
51
53
  * The eslint config object
52
54
  */
53
55
  const eslintConfig = async (eslintParams) => {
54
56
  const fullConfig = configDefaults(eslintParams);
55
57
  const res = [];
56
- if (isDepCheck()) {
58
+ if (fullConfig.full) environ.setFullCheck();
59
+ if (environ.isDepCheck()) {
57
60
  configToDependencies(fullConfig);
58
61
  } else {
59
62
  if (!fullConfig.noBase) (await lazy.base()).apply(res, fullConfig);
@@ -62,7 +65,6 @@ const eslintConfig = async (eslintParams) => {
62
65
  if (fullConfig.import !== false) (await lazy.importx()).apply(res, fullConfig);
63
66
  const reactCfg = getReactFullConfig(fullConfig.react);
64
67
  if (reactCfg.react) (await lazy.react()).apply(res, fullConfig);
65
- if (reactCfg.reactNative) (await lazy.reactNative()).apply(res, fullConfig);
66
68
  if (reactCfg.reactHooks) (await lazy.reactHooks()).apply(res, fullConfig);
67
69
  if (fullConfig.mocha) (await lazy.mocha()).apply(res, fullConfig);
68
70
  clearConfig(res);
@@ -1,22 +0,0 @@
1
- import {fixupPluginRules} from "@eslint/compat";
2
-
3
- import reactNative from "eslint-plugin-react-native";
4
-
5
- import * as sections from "../../sections.js";
6
- import {getReactFullConfig} from "../reactfullconfig.js";
7
-
8
- export const apply = (configResult, eslintConfig) => {
9
- const reactCfg = getReactFullConfig(eslintConfig.react);
10
- if (!reactCfg.reactNative) return;
11
- const reactNativeSection = sections.getNamedSection(configResult, "keeex/react-native");
12
- reactNativeSection.plugins = {"react-native": fixupPluginRules(reactNative)};
13
- sections.configureRules(reactNativeSection, "react-native", {
14
- "no-color-literals": "warn",
15
- "no-inline-styles": "warn",
16
- "no-raw-text": "error",
17
- "no-single-element-style-arrays": "error",
18
- "no-unused-styles": "warn",
19
- "sort-styles": "warn",
20
- "split-platform-components": "warn",
21
- });
22
- };