-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheslint.config.js
136 lines (132 loc) · 5.45 KB
/
eslint.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import globals from "globals";
import eslintPluginJs from "@eslint/js";
import eslintConfigPrettier from "eslint-config-prettier";
import stylisticEslintPlugin from "@stylistic/eslint-plugin";
import tseslint from "typescript-eslint";
import eslintPluginErasableSyntaxOnly from "eslint-plugin-erasable-syntax-only";
const stylisticConfigPreferences = {
formatting: {
rules: {
/** Commented rules = Turned off by eslint-config-prettier */
// "@stylistic/no-trailing-spaces": ["error", { skipBlankLines: false, ignoreComments: true }],
// "@stylistic/arrow-spacing": ["error", { before: true, after: true }],
// "@stylistic/brace-style": ["error", "1tbs", { allowSingleLine: true }],
// "@stylistic/comma-dangle": ["error", "always-multiline"],
// "@stylistic/comma-style": ["error", "last"],
// "@stylistic/no-floating-decimal": "error",
// "@stylistic/indent": ["error", 4, { SwitchCase: 1, tabLength: 4 }],
// "@stylistic/no-multiple-empty-lines": ["error", { max: 1, maxEOF: 0, maxBOF: 0 }],
// "@stylistic/multiline-comment-style": ["error", "bare-block"]
},
},
};
const eslintConfigPreferences = {
formatting: {
rules: {
/** Commented rules = Turned off by eslint-config-prettier */
// "curly": ["error", "all"], "no-inline-comments": "error"
"arrow-body-style": ["error", "always"],
},
},
codeQuality: {
rules: {
"func-style": ["error", "declaration", { overrides: { namedExports: "declaration" } }],
"no-console": "off",
"radix": ["error", "always"],
"no-shadow": ["error", { builtinGlobals: true, ignoreOnInitialization: true }],
"no-negated-condition": "error",
"no-unneeded-ternary": ["error", { defaultAssignment: true }],
"no-nested-ternary": "error",
"no-var": "error",
"no-use-before-define": ["error", { functions: false }],
"prefer-const": ["error"],
"require-await": "error",
"strict": ["error", "global"],
"yoda": "error",
},
},
};
const tseslintStrictConfigArr = tseslint.configs.strict;
const tseslintBaseConfig = tseslintStrictConfigArr[0];
const tseslintRecommendedConfig = tseslintStrictConfigArr[1];
const tseslintStrictConfig = tseslintStrictConfigArr[2];
/**
* @see https://eslint.org/docs/latest/rules
* @see https://eslint.org/docs/latest/use/configure
* @type {import('eslint').Linter.Config[]}
*/
export default [
/** Global config object that applies to both JavaScript and TypeScript files and can be overriden */
{ languageOptions: { globals: { ...globals.node, ...globals.es2025, ...globals.browser } } },
/** Global config object with rules that applies to both JavaScript and TypeScript files and can be overriden */
{
plugins: { "@stylistic": stylisticEslintPlugin },
rules: {
...eslintPluginJs.configs.recommended.rules,
...eslintConfigPreferences.formatting.rules,
...eslintConfigPreferences.codeQuality.rules,
},
},
/** Global config object that only applies to JavaScript files and can be overriden */
{
name: "personal/js/stylistic",
files: ["**/*.js", "**/*.mjs", "**/*.cjs"],
rules: {
...stylisticConfigPreferences.formatting.rules,
},
},
/** Global config object that only applies to TypeScript files and can be overriden */
{
...tseslintBaseConfig,
// Override the name from the base config
name: "personal/ts/strict",
files: tseslintRecommendedConfig.files,
rules: {
...tseslintRecommendedConfig.rules,
...tseslintStrictConfig.rules,
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": "error",
},
},
/** Global config object that only applies to Test files and can be overriden */
{
name: "personal/test",
languageOptions: { globals: { ...globals.jest } },
files: ["**/*.spec.*", "**/*.test.*"],
rules: {
"no-shadow": "off",
},
},
/** Global config object with rules that may or may not override specific rules to work well with ESLint */
eslintConfigPrettier,
eslintPluginErasableSyntaxOnly.configs.recommended,
/**
* Global config object with rules I don't want to be overriden no matter what rules are set above
* https://github.com/prettier/eslint-config-prettier?tab=readme-ov-file#forbid-unnecessary-backticks
*/
{ rules: { "@stylistic/quotes": ["error", "double", { avoidEscape: true, allowTemplateLiterals: false }] } },
/**
Global config object with ignores that applies to both JavaScript and TypeScript that I don't want to be overriden
https://eslint.org/docs/latest/use/configure/configuration-files#globally-ignoring-files-with-ignores
https://github.com/eslint/eslint/discussions/18304#discussioncomment-9069706
*/
{
ignores: [
"!**/*.ts",
"!**/*.js",
"!**/*.cjs",
"!**/*.mjs",
"!**/*.mts",
"!**/*.cts",
"**/.git",
"**/node_modules",
"**/build/**",
"**/tmp/**",
"**/temp/**",
"**/coverage/**",
"**/logs",
"**/dist",
"**/sandbox",
],
},
];