forked from medusajs/medusa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.eslintrc.js
More file actions
320 lines (311 loc) · 10.3 KB
/
Copy path.eslintrc.js
File metadata and controls
320 lines (311 loc) · 10.3 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
const path = require("path")
const medusa = require("@medusajs/eslint-plugin")
// ---------------------------------------------------------------------------
// Scope definitions
// ---------------------------------------------------------------------------
// The repo's style lint (eslint:recommended + google + prettier + the
// @typescript-eslint formatting rules) historically ran only on a curated set
// of packages (the `.eslintignore` allowlist) plus root/integration-tests.
//
// We now also run `@medusajs/eslint-plugin` (Medusa convention rules) over all
// of the framework's own packages. Those packages must get the Medusa rules
// WITHOUT suddenly being subjected to the full style/prettier lint.
//
// NOTE: of the Medusa target packages, only `packages/medusa` was ever actually
// reached by the style lint. The `.eslintignore` allowlist negations for
// `packages/modules/*`, `packages/modules/providers/*`, and `packages/core/*`
// were no-ops — `packages/*` excludes the `packages/modules`/`packages/core`
// directories, and gitignore cannot re-include a grandchild whose parent dir is
// excluded. So to keep the style scope exactly as it was, style is excluded from
// every Medusa target except `packages/medusa`, plus data-model files (which the
// historical `**/models/*` ignore already kept out of style).
const STYLE_EXCLUDED = [
"packages/plugins/**",
"packages/modules/**",
"packages/core/core-flows/**",
"**/models/**",
]
const MEDUSA_EXCLUDED = [
"**/__tests__/**",
"**/__mocks__/**",
"**/__fixtures__/**",
"**/*.spec.*",
"**/*.test.*",
"**/integration-tests/**",
"**/migrations/**",
"packages/modules/**",
"packages/core/framework/**",
"packages/admin/**"
]
// Turn a flat preset's rule blocks into eslintrc `overrides`, scoping each
// block's `files` globs to the given package directories. The plugin presets
// remain the single source of truth for which rules run; this only decides
// where. (No `project`/type info is involved — these rules are AST-only.)
function medusaOverrides(presetName, dirs) {
return medusa.configs[presetName]
.filter((b) => b.files && b.rules && Object.keys(b.rules).length > 0)
.map((b) => ({
files: dirs.flatMap((d) => b.files.map((f) => `${d}/${f}`)),
excludedFiles: [
...MEDUSA_EXCLUDED,
...(b.ignores
? dirs.flatMap((d) => b.ignores.map((i) => `${d}/${i}`))
: []),
],
rules: b.rules,
}))
}
module.exports = {
root: true,
parserOptions: {
requireConfigFile: false,
ecmaFeatures: {
experimentalDecorators: true,
},
},
// Registered so rule references and `eslint-disable` directives resolve. The
// style rules come from the scoped overrides below; the Medusa rules from the
// generated overrides. `react-hooks`/`@typescript-eslint` are registered (not
// enabled globally) so their disable-directives in now-linted packages don't
// error "rule not found".
plugins: ["prettier", "@medusajs", "@typescript-eslint", "react-hooks"],
env: {
es6: true,
node: true,
jest: true,
},
overrides: [
// --- TypeScript parser (syntactic, no `project`) for ALL .ts/.tsx ---
// No rule in this repo needs type information anymore (the type-aware
// @typescript-eslint rules were disabled to avoid OOM), so a single
// program-free parser block covers every TypeScript file.
{
files: ["*.ts", "*.tsx"],
parser: "@typescript-eslint/parser",
parserOptions: {
sourceType: "module",
ecmaVersion: 2021,
},
},
// --- Base style rules — historical scope only (Medusa-only pkgs excluded) ---
{
files: ["**/*.{js,jsx,ts,tsx,cjs,mjs}"],
excludedFiles: STYLE_EXCLUDED,
plugins: ["prettier"],
extends: ["eslint:recommended", "google", "plugin:prettier/recommended"],
rules: {
curly: ["error", "all"],
"new-cap": "off",
"require-jsdoc": "off",
"no-unused-expressions": "off",
"no-unused-vars": "off",
camelcase: "off",
"no-invalid-this": "off",
"max-len": [
"error",
{
code: 80,
ignoreStrings: true,
ignoreRegExpLiterals: true,
ignoreComments: true,
ignoreTrailingComments: true,
ignoreUrls: true,
ignoreTemplateLiterals: true,
},
],
semi: ["error", "never"],
quotes: [
"error",
"double",
{
allowTemplateLiterals: true,
},
],
"comma-dangle": [
"error",
{
arrays: "always-multiline",
objects: "always-multiline",
imports: "always-multiline",
exports: "always-multiline",
functions: "never",
},
],
"object-curly-spacing": ["error", "always"],
"arrow-parens": ["error", "always"],
"linebreak-style": 0,
"no-confusing-arrow": [
"error",
{
allowParens: false,
},
],
"space-before-function-paren": [
"error",
{
anonymous: "always",
named: "never",
asyncArrow: "always",
},
],
"space-infix-ops": "error",
"eol-last": ["error", "always"],
},
},
// --- TypeScript style rules — historical scope only ---
{
files: ["*.ts"],
excludedFiles: STYLE_EXCLUDED,
plugins: ["@typescript-eslint/eslint-plugin"],
extends: ["plugin:@typescript-eslint/recommended"],
rules: {
"valid-jsdoc": "off",
"@typescript-eslint/no-non-null-assertion": "off",
// Disabled to avoid OOM: these require the TS type-checker, and pointing
// `parserOptions.project` at the whole monorepo to feed them exhausted
// the heap. Re-enabling needs a scoped/chunked `project` setup.
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/await-thenable": "off",
"@typescript-eslint/promise-function-async": "off",
"@typescript-eslint/keyword-spacing": "error",
"@typescript-eslint/space-before-function-paren": [
"error",
{
anonymous: "always",
named: "never",
asyncArrow: "always",
},
],
"@typescript-eslint/space-infix-ops": "error",
// --- Rules to be fixed
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-var-requires": "off",
},
},
{
files: [
"./packages/design-system/ui/**/*.ts",
"./packages/design-system/ui/**/*.tsx",
],
extends: [
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:@typescript-eslint/recommended",
],
plugins: ["@typescript-eslint"],
rules: {
"react/no-children-prop": "off",
"react-hooks/exhaustive-deps": "warn",
"react/prop-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{ argsIgnorePattern: "^_" },
],
},
settings: {
react: {
version: "detect",
},
},
parser: "@typescript-eslint/parser",
parserOptions: {
project: "./packages/design-system/ui/tsconfig.json",
},
},
{
files: [
"./packages/design-system/icons/**/*.ts",
"./packages/design-system/icons/**/*.tsx",
],
extends: [
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
],
plugins: ["@typescript-eslint"],
rules: {
"react/no-children-prop": "off",
"react/prop-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{ argsIgnorePattern: "^_" },
],
},
settings: {
react: {
version: "detect",
},
},
parser: "@typescript-eslint/parser",
parserOptions: {
project: "./packages/design-system/icons/tsconfig.json",
},
},
{
files: [
"./packages/admin/dashboard/**/*.ts",
"./packages/admin/dashboard/**/*.tsx",
],
plugins: ["unused-imports", "react-refresh"],
extends: [
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:react-hooks/recommended",
],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
sourceType: "module", // Allows for the use of imports
project: path.join(__dirname, "./packages/admin/dashboard/tsconfig.json"),
},
globals: {
__BASE__: "readonly",
__AUTH_TYPE__: "readonly",
__MAX_UPLOAD_FILE_SIZE__: "readonly",
},
env: {
browser: true,
},
rules: {
"prettier/prettier": "error",
"react/prop-types": "off",
"new-cap": "off",
"require-jsdoc": "off",
"valid-jsdoc": "off",
"react-refresh/only-export-components": [
"warn",
{ allowConstantExport: true },
],
"no-unused-expressions": "off",
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": [
"warn",
{
vars: "all",
varsIgnorePattern: "^_",
args: "after-used",
argsIgnorePattern: "^_",
},
],
},
},
// --- Medusa convention rules (generated from the plugin presets) ---
// `recommended` for the app-like packages. `packages/modules` and
// `packages/core/framework` are intentionally excluded from the Medusa rules
// here (see MEDUSA_EXCLUDED_DIRS) — they're linted for conventions
// separately — so no `modules`-preset override is registered.
...medusaOverrides("recommended", [
"packages/medusa",
"packages/plugins/*",
"packages/core/core-flows",
]),
],
}