Skip to content

Commit 3f513d4

Browse files
committed
refactor(eslint): organize rules into constants for improved readability
1 parent 44ff0bd commit 3f513d4

File tree

1 file changed

+187
-175
lines changed

1 file changed

+187
-175
lines changed

eslint.config.mjs

Lines changed: 187 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* Dependencies */
12
import globals from "globals";
23
import eslint from "@eslint/js";
34
import tseslint from "typescript-eslint";
@@ -6,6 +7,189 @@ import importPlugin from "eslint-plugin-import";
67
import jsdoc from "eslint-plugin-jsdoc";
78
import eslintPluginUnicorn from "eslint-plugin-unicorn";
89

10+
/* Constants */
11+
const TIME_CONSUMING_RULES = {
12+
"@typescript-eslint/no-misused-promises": 0,
13+
"unicorn/no-unnecessary-polyfills": 0,
14+
};
15+
16+
const TOO_STRICT_RULES = {
17+
"unicorn/prefer-dom-node-remove": 0,
18+
"unicorn/prefer-code-point": 0,
19+
"unicorn/prefer-export-from": 0,
20+
};
21+
22+
const RULES = {
23+
"jsdoc/require-description-complete-sentence": 2,
24+
quotes: [
25+
"error",
26+
"double",
27+
{ avoidEscape: true, allowTemplateLiterals: false },
28+
],
29+
"@typescript-eslint/explicit-member-accessibility": [
30+
"error",
31+
{
32+
accessibility: "explicit",
33+
overrides: {
34+
constructors: "no-public",
35+
},
36+
},
37+
],
38+
"import/named": "error",
39+
"import/namespace": "error",
40+
"import/default": "error",
41+
"import/export": "error",
42+
"import/no-named-as-default": "error",
43+
"import/no-unused-modules": "error",
44+
"import/no-named-as-default-member": "error",
45+
"import/no-mutable-exports": "error",
46+
"import/no-extraneous-dependencies": "error",
47+
"import/no-empty-named-blocks": "error",
48+
"import/no-deprecated": "error",
49+
"import/first": "error",
50+
"import/exports-last": "error",
51+
"import/no-duplicates": "error",
52+
"import/order": [
53+
"error",
54+
{
55+
groups: [["builtin", "external", "internal"]],
56+
"newlines-between": "always",
57+
alphabetize: { order: "asc", caseInsensitive: true },
58+
},
59+
],
60+
"sort-imports": [
61+
"error",
62+
{
63+
ignoreCase: true,
64+
ignoreDeclarationSort: true,
65+
ignoreMemberSort: false,
66+
memberSyntaxSortOrder: ["none", "all", "multiple", "single"],
67+
},
68+
],
69+
"import/newline-after-import": "error",
70+
"import/no-absolute-path": "error",
71+
"import/no-self-import": "error",
72+
"import/no-cycle": "error",
73+
"import/no-useless-path-segments": "error",
74+
"@typescript-eslint/no-unnecessary-condition": "off",
75+
"array-callback-return": "error",
76+
"no-undef": "error",
77+
"prefer-const": "error",
78+
"no-duplicate-case": "error",
79+
"for-direction": "error",
80+
"no-useless-backreference": "error",
81+
"@typescript-eslint/no-explicit-any": "error",
82+
"@typescript-eslint/no-unsafe-return": "error",
83+
"default-case-last": "error",
84+
"require-atomic-updates": "warn",
85+
"use-isnan": "error",
86+
"getter-return": "error",
87+
"no-async-promise-executor": "error",
88+
"no-compare-neg-zero": "error",
89+
"no-cond-assign": "error",
90+
"no-constant-condition": ["error", { checkLoops: false }],
91+
"no-empty-character-class": "error",
92+
"no-misleading-character-class": "error",
93+
"no-sparse-arrays": "error",
94+
"no-template-curly-in-string": "error",
95+
"no-var": "error",
96+
"no-unexpected-multiline": "error",
97+
"no-new-symbol": "error",
98+
eqeqeq: "error",
99+
"no-fallthrough": "error",
100+
"no-implicit-coercion": "error",
101+
radix: "error",
102+
"no-invalid-regexp": "error",
103+
"require-unicode-regexp": "error",
104+
"handle-callback-err": "error",
105+
"no-bitwise": "error",
106+
"no-unmodified-loop-condition": "error",
107+
"no-import-assign": "error",
108+
"no-dupe-else-if": "error",
109+
"consistent-return": "error",
110+
"no-extra-bind": "error",
111+
"no-extra-label": "error",
112+
"no-unused-labels": "error",
113+
"no-unused-vars": "off",
114+
"@typescript-eslint/no-unused-vars": "error",
115+
"no-useless-call": "error",
116+
"no-useless-catch": "error",
117+
"no-useless-concat": "error",
118+
"no-useless-escape": "error",
119+
"prefer-promise-reject-errors": "error",
120+
yoda: "error",
121+
"no-else-return": "error",
122+
"prefer-rest-params": "error",
123+
"prefer-spread": "error",
124+
"prefer-template": "error",
125+
"require-yield": "error",
126+
"no-unsafe-finally": "error",
127+
"object-shorthand": ["error", "methods"],
128+
"prefer-numeric-literals": "error",
129+
"prefer-arrow-callback": "error",
130+
"symbol-description": "error",
131+
"no-extra-boolean-cast": "error",
132+
"no-duplicate-imports": ["error", { includeExports: true }],
133+
"no-useless-computed-key": "error",
134+
"no-useless-rename": "error",
135+
"no-multi-str": "error",
136+
"no-new-wrappers": "error",
137+
"no-useless-return": "error",
138+
"no-label-var": "error",
139+
"no-new-require": "error",
140+
"max-nested-callbacks": ["error", { max: 4 }],
141+
"func-name-matching": "error",
142+
"no-unneeded-ternary": "error",
143+
"operator-assignment": "error",
144+
"prefer-object-spread": "error",
145+
"default-param-last": "error",
146+
"prefer-regex-literals": "error",
147+
"no-constructor-return": "error",
148+
"no-setter-return": "error",
149+
"grouped-accessor-pairs": "error",
150+
"no-plusplus": ["error", { allowForLoopAfterthoughts: true }],
151+
"no-floating-decimal": "error",
152+
"accessor-pairs": "error",
153+
"no-case-declarations": "error",
154+
curly: "error",
155+
"prefer-exponentiation-operator": "error",
156+
"no-undef-init": "error",
157+
"no-func-assign": "error",
158+
"no-console": "error",
159+
"no-debugger": "error",
160+
"no-empty": ["error", { allowEmptyCatch: true }],
161+
"no-ex-assign": "error",
162+
"no-irregular-whitespace": "error",
163+
"no-prototype-builtins": "error",
164+
"no-regex-spaces": "error",
165+
"no-alert": "error",
166+
"no-caller": "error",
167+
"no-empty-pattern": "error",
168+
"no-eval": "error",
169+
"no-implied-eval": "error",
170+
"no-new-func": "error",
171+
"no-shadow-restricted-names": "error",
172+
"no-path-concat": "error",
173+
"no-iterator": "error",
174+
"no-extend-native": "error",
175+
"no-global-assign": "error",
176+
"no-with": "error",
177+
"no-octal": "error",
178+
"no-octal-escape": "error",
179+
"no-proto": "error",
180+
"no-return-assign": "error",
181+
"no-script-url": "error",
182+
"no-self-assign": "error",
183+
"no-self-compare": "error",
184+
"no-throw-literal": "error",
185+
"no-sequences": "error",
186+
"one-var": ["error", "never"],
187+
"func-names": "error",
188+
"new-cap": "error",
189+
"class-methods-use-this": "error",
190+
"no-shadow": ["error", { builtinGlobals: true }],
191+
};
192+
9193
export default tseslint.config(
10194
eslint.configs.recommended,
11195
tseslint.configs.strictTypeCheckedOnly,
@@ -49,181 +233,9 @@ export default tseslint.config(
49233
jsdoc,
50234
},
51235
rules: {
52-
// Stupid rule, doesn't recognize that we're not working with the DOM
53-
"unicorn/prefer-dom-node-remove": 0,
54-
// Stupid rule
55-
"unicorn/prefer-code-point": 0,
56-
// Conflicts with import plugin
57-
"unicorn/prefer-export-from": 0,
58-
59-
"jsdoc/require-description-complete-sentence": 2,
60-
quotes: [
61-
"error",
62-
"double",
63-
{ avoidEscape: true, allowTemplateLiterals: false },
64-
],
65-
"@typescript-eslint/explicit-member-accessibility": [
66-
"error",
67-
{
68-
accessibility: "explicit",
69-
overrides: {
70-
constructors: "no-public",
71-
},
72-
},
73-
],
74-
"import/named": "error",
75-
"import/namespace": "error",
76-
"import/default": "error",
77-
"import/export": "error",
78-
"import/no-named-as-default": "error",
79-
"import/no-unused-modules": "error",
80-
"import/no-named-as-default-member": "error",
81-
"import/no-mutable-exports": "error",
82-
"import/no-extraneous-dependencies": "error",
83-
"import/no-empty-named-blocks": "error",
84-
"import/no-deprecated": "error",
85-
"import/first": "error",
86-
"import/exports-last": "error",
87-
"import/no-duplicates": "error",
88-
"import/order": [
89-
"error",
90-
{
91-
groups: [["builtin", "external", "internal"]],
92-
"newlines-between": "always",
93-
alphabetize: { order: "asc", caseInsensitive: true },
94-
},
95-
],
96-
"sort-imports": [
97-
"error",
98-
{
99-
ignoreCase: true,
100-
ignoreDeclarationSort: true,
101-
ignoreMemberSort: false,
102-
memberSyntaxSortOrder: ["none", "all", "multiple", "single"],
103-
},
104-
],
105-
"import/newline-after-import": "error",
106-
"import/no-absolute-path": "error",
107-
"import/no-self-import": "error",
108-
"import/no-cycle": "error",
109-
"import/no-useless-path-segments": "error",
110-
"@typescript-eslint/no-unnecessary-condition": "off",
111-
"array-callback-return": "error",
112-
"no-undef": "error",
113-
"prefer-const": "error",
114-
"no-duplicate-case": "error",
115-
"for-direction": "error",
116-
"no-useless-backreference": "error",
117-
"@typescript-eslint/no-explicit-any": "error",
118-
"@typescript-eslint/no-unsafe-return": "error",
119-
"default-case-last": "error",
120-
"require-atomic-updates": "warn",
121-
"use-isnan": "error",
122-
"getter-return": "error",
123-
"no-async-promise-executor": "error",
124-
"no-compare-neg-zero": "error",
125-
"no-cond-assign": "error",
126-
"no-constant-condition": ["error", { checkLoops: false }],
127-
"no-empty-character-class": "error",
128-
"no-misleading-character-class": "error",
129-
"no-sparse-arrays": "error",
130-
"no-template-curly-in-string": "error",
131-
"no-var": "error",
132-
"no-unexpected-multiline": "error",
133-
"no-new-symbol": "error",
134-
eqeqeq: "error",
135-
"no-fallthrough": "error",
136-
"no-implicit-coercion": "error",
137-
radix: "error",
138-
"no-invalid-regexp": "error",
139-
"require-unicode-regexp": "error",
140-
"handle-callback-err": "error",
141-
"no-bitwise": "error",
142-
"no-unmodified-loop-condition": "error",
143-
"no-import-assign": "error",
144-
"no-dupe-else-if": "error",
145-
"consistent-return": "error",
146-
"no-extra-bind": "error",
147-
"no-extra-label": "error",
148-
"no-unused-labels": "error",
149-
"no-unused-vars": "off",
150-
"@typescript-eslint/no-unused-vars": "error",
151-
"no-useless-call": "error",
152-
"no-useless-catch": "error",
153-
"no-useless-concat": "error",
154-
"no-useless-escape": "error",
155-
"prefer-promise-reject-errors": "error",
156-
yoda: "error",
157-
"no-else-return": "error",
158-
"prefer-rest-params": "error",
159-
"prefer-spread": "error",
160-
"prefer-template": "error",
161-
"require-yield": "error",
162-
"no-unsafe-finally": "error",
163-
"object-shorthand": ["error", "methods"],
164-
"prefer-numeric-literals": "error",
165-
"prefer-arrow-callback": "error",
166-
"symbol-description": "error",
167-
"no-extra-boolean-cast": "error",
168-
"no-duplicate-imports": ["error", { includeExports: true }],
169-
"no-useless-computed-key": "error",
170-
"no-useless-rename": "error",
171-
"no-multi-str": "error",
172-
"no-new-wrappers": "error",
173-
"no-useless-return": "error",
174-
"no-label-var": "error",
175-
"no-new-require": "error",
176-
"max-nested-callbacks": ["error", { max: 4 }],
177-
"func-name-matching": "error",
178-
"no-unneeded-ternary": "error",
179-
"operator-assignment": "error",
180-
"prefer-object-spread": "error",
181-
"default-param-last": "error",
182-
"prefer-regex-literals": "error",
183-
"no-constructor-return": "error",
184-
"no-setter-return": "error",
185-
"grouped-accessor-pairs": "error",
186-
"no-plusplus": ["error", { allowForLoopAfterthoughts: true }],
187-
"no-floating-decimal": "error",
188-
"accessor-pairs": "error",
189-
"no-case-declarations": "error",
190-
curly: "error",
191-
"prefer-exponentiation-operator": "error",
192-
"no-undef-init": "error",
193-
"no-func-assign": "error",
194-
"no-console": "error",
195-
"no-debugger": "error",
196-
"no-empty": ["error", { allowEmptyCatch: true }],
197-
"no-ex-assign": "error",
198-
"no-irregular-whitespace": "error",
199-
"no-prototype-builtins": "error",
200-
"no-regex-spaces": "error",
201-
"no-alert": "error",
202-
"no-caller": "error",
203-
"no-empty-pattern": "error",
204-
"no-eval": "error",
205-
"no-implied-eval": "error",
206-
"no-new-func": "error",
207-
"no-shadow-restricted-names": "error",
208-
"no-path-concat": "error",
209-
"no-iterator": "error",
210-
"no-extend-native": "error",
211-
"no-global-assign": "error",
212-
"no-with": "error",
213-
"no-octal": "error",
214-
"no-octal-escape": "error",
215-
"no-proto": "error",
216-
"no-return-assign": "error",
217-
"no-script-url": "error",
218-
"no-self-assign": "error",
219-
"no-self-compare": "error",
220-
"no-throw-literal": "error",
221-
"no-sequences": "error",
222-
"one-var": ["error", "never"],
223-
"func-names": "error",
224-
"new-cap": "error",
225-
"class-methods-use-this": "error",
226-
"no-shadow": ["error", { builtinGlobals: true }],
236+
...RULES,
237+
...TIME_CONSUMING_RULES,
238+
...TOO_STRICT_RULES,
227239
},
228240
},
229241
);

0 commit comments

Comments
 (0)