-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy patheslint.config.mjs
More file actions
236 lines (217 loc) · 5.71 KB
/
eslint.config.mjs
File metadata and controls
236 lines (217 loc) · 5.71 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import path from "node:path";
import { includeIgnoreFile } from "@eslint/compat";
import js from "@eslint/js";
import { configs, plugins } from "eslint-config-airbnb-extended";
import { rules as prettierConfigRules } from "eslint-config-prettier";
import prettierPlugin from "eslint-plugin-prettier";
const gitignorePath = path.resolve(".", ".gitignore");
const jsConfig = [
// ESLint Recommended Rules
{
name: "js/config",
...js.configs.recommended,
},
// Stylistic Plugin
plugins.stylistic,
// Import X Plugin
plugins.importX,
// Airbnb Base Recommended Config
...configs.base.recommended,
];
const nextConfig = [
// React Plugin
plugins.react,
// React Hooks Plugin
plugins.reactHooks,
// React JSX A11y Plugin
plugins.reactA11y,
// Next Plugin
plugins.next,
// Airbnb Next Recommended Config
...configs.next.recommended,
];
const typescriptConfig = [
// TypeScript ESLint Plugin
plugins.typescriptEslint,
// Airbnb Base TypeScript Config
...configs.base.typescript,
// Airbnb Next TypeScript Config
...configs.next.typescript,
];
const prettierConfig = [
// Prettier Plugin
{
name: "prettier/plugin/config",
plugins: {
prettier: prettierPlugin,
},
},
// Prettier Config
{
name: "prettier/config",
rules: {
...prettierConfigRules,
"prettier/prettier": "error",
},
},
];
// Next.js App Router - default export allowed
const appRouterConfig = {
files: [
"**/app/**/{page,layout,loading,error,not-found,global-error}.{ts,tsx}",
"**/app/**/{template,default}.{ts,tsx}",
"**/app/**/route.{ts,tsx}",
],
rules: {
"import-x/no-default-export": "off",
"import-x/prefer-default-export": "off",
},
};
// Next.js Pages Router - default export allowed
const pagesRouterConfig = {
files: ["**/pages/**/*.{ts,tsx}", "**/pages/api/**/*.{ts,tsx}"],
rules: {
"import-x/no-default-export": "off",
"import-x/prefer-default-export": "off",
},
};
// Config files - default export allowed
const configFilesConfig = {
files: [
"**/*.config.{js,ts,mjs,cjs,mts}",
"**/middleware.ts",
"**/instrumentation.ts",
],
rules: {
"import-x/no-default-export": "off",
"import-x/no-extraneous-dependencies": "off",
},
};
// OpenAPI TypeScript
const openApiGeneratedConfig = {
files: ["src/shared/api/schema.d.ts"],
rules: {
"@typescript-eslint/naming-convention": "off",
},
};
// Custom Rules Configuration
const customConfig = {
files: ["**/*.{ts,tsx}"],
languageOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
settings: {
react: {
version: "detect",
},
// import-x settings for TypeScript and Next.js
"import-x/resolver": {
typescript: {
project: ["./tsconfig.json"],
alwaysTryTypes: true,
},
node: {
extensions: [".js", ".jsx", ".ts", ".tsx"],
},
},
"import-x/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"],
},
"import-x/internal-regex": "^@/",
},
rules: {
// Console
"no-console": ["warn", { allow: ["error", "warn"] }],
// General
"consistent-return": "off",
"no-use-before-define": "off",
"no-plusplus": "off",
"no-param-reassign": ["error", { props: false }],
// React
"react/react-in-jsx-scope": "off",
"react/jsx-uses-react": "off",
"react/require-default-props": "off",
"react/jsx-props-no-spreading": "off",
"react/function-component-definition": "off",
"react/jsx-no-useless-fragment": ["error", { allowExpressions: true }],
"react/prop-types": "off",
// TypeScript
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
},
],
// Import-X
"import-x/no-unresolved": "off",
"import-x/extensions": "off",
"import-x/prefer-default-export": "off",
"import-x/no-extraneous-dependencies": "off",
"import-x/first": "error",
"import-x/no-duplicates": "error",
"import-x/newline-after-import": ["error", { count: 1 }],
"import-x/order": [
"error",
{
groups: [
"builtin",
"external",
"internal",
["parent", "sibling", "index"],
"type",
],
"newlines-between": "always",
alphabetize: { order: "asc", caseInsensitive: true },
pathGroups: [
{ pattern: "react", group: "external", position: "before" },
{ pattern: "react-dom", group: "external", position: "before" },
{ pattern: "next", group: "external", position: "before" },
{ pattern: "next/**", group: "external", position: "before" },
{ pattern: "@/**", group: "internal", position: "before" },
],
pathGroupsExcludedImportTypes: ["react", "react-dom", "next"],
warnOnUnassignedImports: true,
},
],
// JSX A11y
"jsx-a11y/label-has-associated-control": [
"error",
{
assert: "either",
controlComponents: ["Input"],
depth: 3,
},
],
"jsx-a11y/anchor-is-valid": [
"error",
{
components: ["Link"],
specialLink: ["hrefLeft", "hrefRight"],
aspects: ["invalidHref", "preferButton"],
},
],
},
};
export default [
// Ignore .gitignore files/folder in eslint
includeIgnoreFile(gitignorePath),
// Javascript Config
...jsConfig,
// Next Config
...nextConfig,
// TypeScript Config
...typescriptConfig,
// Prettier Config
...prettierConfig,
// Custom Rules
customConfig,
// Next.js Specific Configs
openApiGeneratedConfig,
appRouterConfig,
pagesRouterConfig,
configFilesConfig,
];