@keeex/eslint-config 1.12.6 → 2.0.0

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.
@@ -1,256 +1,170 @@
1
- const {
2
- indentDepth,
3
- maxBlockDepth,
4
- maxNestedCallbacks,
5
- maxStatements,
6
- } = require("./common.js");
1
+ /* eslint-disable no-magic-numbers */
2
+ import js from "@eslint/js";
3
+ import pluginPromise from "eslint-plugin-promise";
7
4
 
8
- module.exports = {
9
- dependencies: ["eslint"],
10
- extendsBase: ["eslint:recommended"],
11
- rules: {
12
- "no-console": ["warn"],
13
- "no-dupe-else-if": ["error"],
14
- "no-empty": ["warn", {"allowEmptyCatch": true}],
15
- "no-extra-parens": ["warn", "functions"],
16
- "no-import-assign": ["error"],
17
- "no-setter-return": ["error"],
18
- "no-sparse-arrays": ["warn"],
19
- "no-template-curly-in-string": ["warn"],
20
- "no-unsafe-negation": ["warn"],
21
- "require-atomic-updates": ["warn"],
22
- "valid-typeof": ["warn", {"requireStringLiterals": false}],
23
- "nonblock-statement-body-position": ["warn"],
24
- "accessor-pairs": ["error"],
25
- "array-callback-return": ["error"],
26
- "class-methods-use-this": ["warn", {exceptMethods: ["render"]}],
27
- "complexity": ["warn"],
28
- "curly": ["warn", "multi-line"],
29
- "default-param-last": ["error"],
30
- "dot-location": ["warn", "property"],
31
- "eqeqeq": ["error", "smart"],
32
- "grouped-accessor-pairs": ["error", "getBeforeSet"],
33
- "guard-for-in": ["warn"],
34
- "max-classes-per-file": ["warn", 1],
35
- "no-alert": ["error"],
36
- "no-caller": ["error"],
37
- "no-constructor-return": ["error"],
38
- "no-div-regex": ["error"],
39
- "no-else-return": ["error"],
40
- "no-empty-function": ["warn", {"allow": ["arrowFunctions"]}],
41
- "no-eq-null": ["error"],
42
- "no-eval": ["error"],
43
- "no-extend-native": ["error"],
44
- "no-extra-bind": ["warn"],
45
- "no-fallthrough": ["error", {"commentPattern": "fallthrough"}],
46
- "no-floating-decimal": ["error"],
47
- "no-implicit-coercion": ["warn"],
48
- "no-implied-eval": ["error"],
49
- "no-invalid-this": ["error"],
50
- "no-iterator": ["error"],
51
- "no-labels": ["error"],
52
- "no-lone-blocks": ["warn"],
53
- "no-loop-func": ["error"],
54
- "no-magic-numbers": [
55
- "error",
56
- {
57
- "ignore": [0, 1, -1],
58
- "ignoreArrayIndexes": true,
59
- "ignoreDefaultValues": true,
60
- "ignoreClassFieldInitialValues": true,
61
- },
62
- ],
63
- "no-multi-spaces": ["error"],
64
- "no-multi-str": ["error"],
65
- "no-new-func": ["error"],
66
- "no-new-wrappers": ["error"],
67
- "no-octal-escape": ["error"],
68
- "no-param-reassign": ["warn"],
69
- "no-proto": ["error"],
70
- "no-return-assign": ["error"],
71
- "no-return-await": ["error"],
72
- "no-script-url": ["error"],
73
- "no-self-compare": ["error"],
74
- "no-throw-literal": ["error"],
75
- "no-unmodified-loop-condition": ["warn"],
76
- "no-unused-expressions": [
77
- "error",
78
- {
79
- "allowShortCircuit": true,
80
- "allowTernary": true,
81
- },
82
- ],
83
- "no-useless-call": ["error"],
84
- "no-useless-catch": ["error"],
85
- "no-useless-concat": ["error"],
86
- "no-useless-escape": ["error"],
87
- "no-useless-return": ["error"],
88
- "no-void": ["error"],
89
- "no-warning-comments": ["warn"],
90
- "prefer-named-capture-group": ["warn"],
91
- "prefer-promise-reject-errors": ["warn", {"allowEmptyReject": true}],
92
- "prefer-regex-literals": ["error"],
93
- "radix": ["warn"],
94
- "require-await": ["warn"],
95
- "require-unicode-regexp": ["warn"],
96
- "wrap-iife": ["error", "outside"],
97
- "strict": ["error", "never"],
98
- "no-shadow": ["error", {"builtinGlobals": true}],
99
- "no-undef-init": ["error"],
100
- "no-unused-vars": ["warn", {"argsIgnorePattern": "^_.*"}],
101
- "no-use-before-define": ["error"],
102
- "callback-return": ["warn"],
103
- "global-require": ["warn"],
104
- "handle-callback-err": ["warn"],
105
- "no-buffer-constructor": ["error"],
106
- "no-mixed-requires": ["warn"],
107
- "no-new-require": ["error"],
108
- "no-process-env": ["warn"],
109
- "no-process-exit": ["error"],
110
- "array-bracket-newline": ["error", "consistent"],
111
- "array-bracket-spacing": ["error"],
112
- "array-element-newline": ["error", "consistent"],
113
- "block-spacing": ["error", "never"],
114
- "brace-style": ["error"],
115
- "camelcase": ["error"],
116
- "comma-dangle": ["error", "always-multiline"],
117
- "comma-spacing": ["error"],
118
- "comma-style": ["error"],
119
- "computed-property-spacing": ["error"],
120
- "eol-last": ["error"],
121
- "func-call-spacing": ["error"],
122
- "func-name-matching": ["warn"],
123
- "func-names": ["error", "as-needed"],
124
- "func-style": ["error"],
125
- "function-call-argument-newline": ["warn", "consistent"],
126
- "function-paren-newline": ["warn", "multiline-arguments"],
127
- "id-length": [
128
- "warn",
129
- {
130
- "min": 1,
131
- "max": 32,
132
- },
133
- ],
134
- "implicit-arrow-linebreak": ["error"],
135
- "indent": [
136
- "error",
137
- indentDepth,
138
- {
139
- "FunctionDeclaration": {"parameters": "first"},
140
- "FunctionExpression": {"parameters": "first"},
141
- "CallExpression": {"arguments": "first"},
142
- "ArrayExpression": "first",
143
- "ignoreComments": true,
144
- },
145
- ],
146
- "jsx-quotes": ["error"],
147
- "key-spacing": ["error"],
148
- "keyword-spacing": ["error"],
149
- "linebreak-style": ["error"],
150
- "lines-between-class-members": [
151
- "error",
152
- "always",
153
- {exceptAfterSingleLine: true},
154
- ],
155
- "max-depth": ["warn", maxBlockDepth],
156
- "max-len": [
157
- "warn",
158
- {
159
- "code": 100,
160
- "ignoreComments": true,
161
- "ignoreUrls": true,
162
- "ignoreStrings": true,
163
- },
164
- ],
165
- "max-lines": [
166
- "warn",
167
- {
168
- "max": 1000,
169
- "skipBlankLines": true,
170
- },
171
- ],
172
- "max-lines-per-function": [
173
- "warn",
174
- {
175
- "skipBlankLines": true,
176
- "skipComments": true,
177
- "IIFEs": true,
178
- },
179
- ],
180
- "max-nested-callbacks": ["warn", maxNestedCallbacks],
181
- "max-statements": ["warn", maxStatements],
182
- "max-statements-per-line": ["warn"],
183
- "new-parens": ["error"],
184
- "newline-per-chained-call": ["error"],
185
- "no-array-constructor": ["warn"],
186
- "no-lonely-if": ["warn"],
187
- "no-mixed-operators": ["warn"],
188
- "no-multi-assign": ["error"],
189
- "no-multiple-empty-lines": ["error", {max: 1, maxBOF: 0, maxEOF: 0}],
190
- "no-negated-condition": ["warn"],
191
- "no-nested-ternary": ["error"],
192
- "no-new-object": ["error"],
193
- "no-tabs": ["error"],
194
- "no-trailing-spaces": ["error"],
195
- "no-unneeded-ternary": ["warn"],
196
- "no-whitespace-before-property": ["error"],
197
- "object-curly-newline": [
198
- "error",
199
- {"multiline": true},
200
- ],
201
- "object-curly-spacing": ["error"],
202
- "object-property-newline": ["error", {allowAllPropertiesOnSameLine: true}],
203
- "operator-assignment": ["warn"],
204
- "operator-linebreak": ["error", "before"],
205
- "padded-blocks": ["error", "never"],
206
- "prefer-exponentiation-operator": ["error"],
207
- "prefer-object-spread": ["error"],
208
- "quote-props": ["error", "consistent"],
209
- "quotes": ["error"],
210
- "semi": ["error"],
211
- "semi-spacing": ["error"],
212
- "semi-style": ["error"],
213
- "space-before-blocks": ["error"],
214
- "space-before-function-paren": [
215
- "error",
216
- {
217
- "anonymous": "never",
218
- "named": "never",
219
- "asyncArrow": "always",
220
- },
221
- ],
222
- "space-in-parens": ["error"],
223
- "space-infix-ops": ["error"],
224
- "space-unary-ops": [
225
- "error",
226
- {
227
- "words": true,
228
- "nonwords": false,
229
- },
230
- ],
231
- "spaced-comment": ["error"],
232
- "switch-colon-spacing": ["error"],
233
- "template-tag-spacing": ["error"],
234
- "unicode-bom": ["error"],
235
- "arrow-body-style": ["error"],
236
- "arrow-parens": ["error", "as-needed"],
237
- "arrow-spacing": ["error"],
238
- "generator-star-spacing": ["error", "after"],
239
- "no-duplicate-imports": ["error"],
240
- "no-useless-computed-key": ["error"],
241
- "no-useless-constructor": ["warn"],
242
- "no-useless-rename": ["error"],
243
- "no-var": ["error"],
244
- "object-shorthand": ["error"],
245
- "prefer-arrow-callback": ["warn"],
246
- "prefer-const": ["warn"],
247
- "prefer-numeric-literals": ["error"],
248
- "prefer-rest-params": ["warn"],
249
- "prefer-spread": ["error"],
250
- "prefer-template": ["error"],
251
- "rest-spread-spacing": ["error"],
252
- "symbol-description": ["warn"],
253
- "template-curly-spacing": ["error"],
254
- "yield-star-spacing": ["error"],
255
- },
5
+ import * as sections from "../sections.js";
6
+
7
+ /**
8
+ * Apply the recommended eslint configuration plus KeeeX tweaks.
9
+ *
10
+ * @param configResult - The eslint configuration object currently being built.
11
+ */
12
+ // eslint-disable-next-line max-lines-per-function
13
+ export const apply = (configResult, eslintConfig) => {
14
+ // Basic options
15
+ const sharedSection = sections.getNamedSection(configResult, "keeex/shared");
16
+ sections.sectionAddOption(sharedSection, "linterOptions", "reportUnusedDisableDirectives", true);
17
+ sections.sectionAddOption(sharedSection, "languageOptions", "ecmaVersion", "latest");
18
+ sections.sectionAddOption(sharedSection, "languageOptions", "sourceType", "module");
19
+ sections.sectionAddOption(
20
+ sharedSection,
21
+ "languageOptions",
22
+ "parserOptions",
23
+ {
24
+ ecmaFeatures: eslintConfig.react ? {jsx: true} : undefined,
25
+ ecmaVersion: "latest",
26
+ sourceType: "module",
27
+ },
28
+ );
29
+ // Global ignores
30
+ if (eslintConfig.ignores.length > 0) {
31
+ const globalIgnores = sections.getNamedSection(configResult, "keeex/ignores");
32
+ globalIgnores.ignores = [...eslintConfig.ignores];
33
+ }
34
+ // Base eslint
35
+ configResult.push(js.configs.recommended);
36
+ const eslintCustom = sections.getNamedSection(configResult, "keeex/eslint-override");
37
+ sections.configureRules(
38
+ eslintCustom,
39
+ "",
40
+ {
41
+ "array-callback-return": "error",
42
+ "arrow-body-style": ["error", "as-needed"],
43
+ "block-scoped-var": "warn",
44
+ "camelcase": "warn",
45
+ "class-methods-use-this": ["warn", {exceptMethods: ["render"]}],
46
+ "complexity": ["warn", {max: 25, variant: "modified"}],
47
+ "curly": ["error", "multi-line"],
48
+ "eqeqeq": "warn",
49
+ "func-style": "error",
50
+ "guard-for-in": "warn",
51
+ "max-classes-per-file": "error",
52
+ "max-depth": ["warn", 5],
53
+ "max-lines": ["warn", {max: 1000, skipBlankLines: true, skipComments: true}],
54
+ "max-lines-per-function": [
55
+ "warn",
56
+ {IIFEs: true, max: 60, skipBlankLines: true, skipComments: true},
57
+ ],
58
+ "max-nested-callbacks": ["warn", 6],
59
+ "max-params": ["warn", {max: 5}],
60
+ "no-alert": "error",
61
+ "no-array-constructor": "error",
62
+ "no-await-in-loop": "warn",
63
+ "no-caller": "error",
64
+ "no-console": "warn",
65
+ "no-constant-condition": "warn",
66
+ "no-constructor-return": "error",
67
+ "no-delete-var": "error",
68
+ "no-div-regex": "warn",
69
+ "no-duplicate-imports": "error",
70
+ "no-else-return": "warn",
71
+ "no-eq-null": "error",
72
+ "no-eval": "error",
73
+ "no-extend-native": "error",
74
+ "no-extra-bind": "error",
75
+ "no-extra-label": "warn",
76
+ "no-global-assign": "error",
77
+ "no-implicit-coercion": "warn",
78
+ "no-implied-eval": "error",
79
+ "no-invalid-this": "error",
80
+ "no-irregular-whitespace": [
81
+ "error",
82
+ {
83
+ skipComments: true,
84
+ skipJSXText: true,
85
+ skipRegExps: true,
86
+ skipStrings: true,
87
+ skipTemplates: true,
88
+ },
89
+ ],
90
+ "no-iterator": "error",
91
+ "no-label-var": "error",
92
+ "no-lonely-if": "warn",
93
+ "no-loop-func": "warn",
94
+ "no-magic-numbers": [
95
+ "warn",
96
+ {
97
+ ignore: [1, -1, "1n", "-1n", 0, "0n"],
98
+ ignoreClassFieldInitialValues: true,
99
+ ignoreDefaultValues: true,
100
+ },
101
+ ],
102
+ "no-multi-assign": "error",
103
+ "no-negated-condition": "warn",
104
+ "no-nested-ternary": "error",
105
+ "no-new-func": "error",
106
+ "no-new-wrappers": "error",
107
+ "no-object-constructor": "error",
108
+ "no-param-reassign": "warn",
109
+ "no-promise-executor-return": "error",
110
+ "no-proto": "error",
111
+ "no-return-assign": "error",
112
+ "no-script-url": "error",
113
+ "no-self-compare": "warn",
114
+ "no-sequences": "warn",
115
+ "no-shadow": "warn",
116
+ "no-shadow-restricted-names": "error",
117
+ "no-throw-literal": "error",
118
+ "no-undef-init": "warn",
119
+ "no-unmodified-loop-condition": "warn",
120
+ "no-unneeded-ternary": "warn",
121
+ "no-unreachable-loop": "warn",
122
+ "no-unused-expressions": "warn",
123
+ "no-use-before-define": "warn",
124
+ "no-useless-assignment": "warn",
125
+ "no-useless-call": "error",
126
+ "no-useless-computed-key": "warn",
127
+ "no-useless-concat": "warn",
128
+ "no-useless-constructor": "warn",
129
+ "no-useless-rename": "warn",
130
+ "no-useless-return": "warn",
131
+ "no-var": "error",
132
+ "no-void": ["error", {allowAsStatement: true}],
133
+ "one-var": ["warn", "never"],
134
+ "prefer-arrow-callback": "warn",
135
+ "prefer-const": ["warn", {ignoreReadBeforeAssign: true}],
136
+ "prefer-exponentiation-operator": "warn",
137
+ "prefer-named-capture-group": "warn",
138
+ "prefer-numeric-literals": "warn",
139
+ "prefer-object-has-own": "warn",
140
+ "prefer-object-spread": "warn",
141
+ "prefer-promise-reject-errors": "error",
142
+ "prefer-regex-literals": "warn",
143
+ "prefer-rest-params": "error",
144
+ "prefer-spread": "error",
145
+ "prefer-template": "warn",
146
+ "radix": ["warn", "as-needed"],
147
+ "require-atomic-updates": "warn",
148
+ "require-await": "warn",
149
+ "require-unicode-regexp": "warn",
150
+ "sort-imports": ["warn", {ignoreCase: true, allowSeparatedGroups: true}],
151
+ "sort-keys": ["warn", "asc", {caseSensitive: false, minKeys: 3, natural: true}],
152
+ "symbol-description": "error",
153
+ },
154
+ );
155
+ // Promises
156
+ configResult.push(pluginPromise.configs["flat/recommended"]);
157
+ const promiseCustom = sections.getNamedSection(configResult, "keeex/promise-override");
158
+ sections.configureRules(
159
+ promiseCustom,
160
+ "promise",
161
+ {
162
+ "avoid-new": "warn",
163
+ "no-multiple-resolved": "error",
164
+ "no-promise-in-callback": "warn",
165
+ "prefer-await-to-callbacks": "warn",
166
+ "prefer-await-to-then": "warn",
167
+ "spec-only": "error",
168
+ },
169
+ );
256
170
  };
@@ -0,0 +1,42 @@
1
+ import globals from "globals";
2
+
3
+ import * as sections from "../sections.js";
4
+
5
+ const base = {builtin: true, es2025: true};
6
+
7
+ /** Create the actual eslint globals object from user input */
8
+ const getGlobalsFromConfig = configGlobals => {
9
+ const res = {};
10
+ if (configGlobals?.builtin) Object.assign(res, globals.builtin);
11
+ if (configGlobals?.browser) Object.assign(res, globals.browser);
12
+ if (configGlobals?.commonjs) Object.assign(res, globals.commonjs);
13
+ if (configGlobals?.es2025) Object.assign(res, globals.es2025);
14
+ if (configGlobals?.mocha) Object.assign(res, globals.mocha);
15
+ if (configGlobals?.node) Object.assign(res, globals.nodeBuiltin);
16
+ if (configGlobals?.serviceworker) Object.assign(res, globals.serviceworker);
17
+ if (configGlobals?.worker) Object.assign(res, globals.worker);
18
+ if (configGlobals?.custom) Object.assign(res, configGlobals.custom);
19
+ return res;
20
+ };
21
+
22
+ export const apply = (configResult, eslintConfig) => {
23
+ const sharedGlobals = eslintConfig.globals.find(c => c.files === undefined);
24
+ const sharedSection = sections.getNamedSection(configResult, "keeex/shared");
25
+ sections.sectionAddOption(
26
+ sharedSection,
27
+ "languageOptions",
28
+ "globals",
29
+ getGlobalsFromConfig({...base, ...sharedGlobals.globals}),
30
+ );
31
+ for (const globalConfig of eslintConfig.globals) {
32
+ if (!globalConfig.files) continue;
33
+ const overrideSection = sections.getNamedSection(configResult, `keeex/globals-${globalConfig.files.join(",")}`);
34
+ overrideSection.files = [...globalConfig.files];
35
+ sections.sectionAddOption(
36
+ overrideSection,
37
+ "languageOptions",
38
+ "globals",
39
+ getGlobalsFromConfig(globalConfig.globals),
40
+ );
41
+ }
42
+ };
@@ -0,0 +1,104 @@
1
+ import eslintPluginImportX from "eslint-plugin-import-x";
2
+
3
+ import * as sections from "../sections.js";
4
+
5
+ /**
6
+ * Apply the import-x configs
7
+ *
8
+ * @param configResult - The eslint configuration object currently being built.
9
+ */
10
+ // eslint-disable-next-line max-lines-per-function
11
+ export const apply = (configResult, eslintConfig) => {
12
+ if (eslintConfig.import === false) return;
13
+ configResult.push({
14
+ ...eslintPluginImportX.flatConfigs.recommended,
15
+ languageOptions: {},
16
+ });
17
+ if (eslintConfig.typescript) configResult.push(eslintPluginImportX.flatConfigs.typescript);
18
+ const override = sections.getNamedSection(configResult, "keeex/importx-override");
19
+ sections.configureRules(
20
+ override,
21
+ "import-x",
22
+ {
23
+ "first": "error",
24
+ "newline-after-import": "warn",
25
+ "no-amd": "error",
26
+ "no-anonymous-default-export": "warn",
27
+ "no-commonjs": "error",
28
+ "no-empty-named-blocks": "warn",
29
+ "no-named-default": "error",
30
+ "no-self-import": "error",
31
+ "no-unresolved": "warn",
32
+ "no-useless-path-segments": "warn",
33
+ "order": [
34
+ "warn",
35
+ {
36
+ alphabetize: {
37
+ order: "asc",
38
+ caseInsensitive: true,
39
+ },
40
+ groups: [
41
+ "builtin",
42
+ "external",
43
+ "internal",
44
+ "parent",
45
+ "sibling",
46
+ "index",
47
+ "object",
48
+ "type",
49
+ "unknown",
50
+ ],
51
+ "newlines-between": "always-and-inside-groups",
52
+ },
53
+ ],
54
+ },
55
+ );
56
+ if (!eslintConfig.noBase) {
57
+ const baseSection = sections.getNamedSection(configResult, "keeex/eslint-override");
58
+ sections.configureRules(baseSection, "", {"sort-imports": "off"});
59
+ }
60
+ if (typeof eslintConfig.import === "number") {
61
+ sections.configureRules(
62
+ override,
63
+ "import-x",
64
+ {
65
+ "no-cycle": ["error", {maxDepth: eslintConfig.import}],
66
+ },
67
+ );
68
+ } else {
69
+ sections.configureRules(override, "import-x", {"no-cycle": "error"});
70
+ }
71
+ if (eslintConfig.typescript) {
72
+ sections.configureRules(
73
+ override,
74
+ "import-x",
75
+ {"no-extraneous-dependencies": ["error", {includeTypes: true}]},
76
+ );
77
+ if (eslintConfig.react) {
78
+ sections.sectionAddOption(override, "settings", "import-x/extensions", [".ts", ".tsx"]);
79
+ } else {
80
+ sections.sectionAddOption(override, "settings", "import-x/extensions", [".ts"]);
81
+ }
82
+ } else {
83
+ sections.configureRules(
84
+ override,
85
+ "import-x",
86
+ {
87
+ "extensions": ["error", "ignorePackages"],
88
+ "no-deprecated": "warn",
89
+ "no-extraneous-dependencies": "error",
90
+ },
91
+ );
92
+ if (eslintConfig.react) {
93
+ sections.sectionAddOption(override, "settings", "import-x/extensions", [".js", ".jsx"]);
94
+ }
95
+ }
96
+ if (eslintConfig.typescript) {
97
+ sections.sectionAddOption(override, "settings", "import-x/resolver", "typescript");
98
+ }
99
+ if (eslintConfig.react) {
100
+ const webOverride = sections.getNamedSection(configResult, "keeex/importx-override-webapp");
101
+ webOverride.files = ["src/webapp"];
102
+ sections.sectionAddOption(webOverride, "settings", "import-x/resolver", "webpack");
103
+ }
104
+ };
@@ -0,0 +1,8 @@
1
+ export const base = () => import("./base.js");
2
+ export const globals = () => import("./globals.js");
3
+ export const importx = () => import("./importx.js");
4
+ export const mocha = () => import("./mocha.js");
5
+ export const react = () => import("./react.js");
6
+ export const reactHooks = () => import("./react/reacthooks.js");
7
+ export const reactNative = () => import("./react/reactnative.js");
8
+ export const typescript = () => import("./typescript.js");