1 const path = require("path")
2 const medusa = require("@medusajs/eslint-plugin")
3
4 // ---------------------------------------------------------------------------
5 // Scope definitions
6 // ---------------------------------------------------------------------------
7 // The repo's style lint (eslint:recommended + google + prettier + the
8 // @typescript-eslint formatting rules) historically ran only on a curated set
9 // of packages (the `.eslintignore` allowlist) plus root/integration-tests.
10 //
11 // We now also run `@medusajs/eslint-plugin` (Medusa convention rules) over all
12 // of the framework's own packages. Those packages must get the Medusa rules
13 // WITHOUT suddenly being subjected to the full style/prettier lint.
14 //
15 // NOTE: of the Medusa target packages, only `packages/medusa` was ever actually
16 // reached by the style lint. The `.eslintignore` allowlist negations for
17 // `packages/modules/*`, `packages/modules/providers/*`, and `packages/core/*`
18 // were no-ops — `packages/*` excludes the `packages/modules`/`packages/core`
19 // directories, and gitignore cannot re-include a grandchild whose parent dir is
20 // excluded. So to keep the style scope exactly as it was, style is excluded from
21 // every Medusa target except `packages/medusa`, plus data-model files (which the
22 // historical `**/models/*` ignore already kept out of style).
23 const STYLE_EXCLUDED = [
24 "packages/plugins/**",
25 "packages/modules/**",
26 "packages/core/core-flows/**",
27 "**/models/**",
28 ]
29
30 const MEDUSA_EXCLUDED = [
31 "**/__tests__/**",
32 "**/__mocks__/**",
33 "**/__fixtures__/**",
34 "**/*.spec.*",
35 "**/*.test.*",
36 "**/integration-tests/**",
37 "**/migrations/**",
38 "packages/modules/**",
39 "packages/core/framework/**",
40 "packages/admin/**"
41 ]
42
43 // Turn a flat preset's rule blocks into eslintrc `overrides`, scoping each
44 // block's `files` globs to the given package directories. The plugin presets
45 // remain the single source of truth for which rules run; this only decides
46 // where. (No `project`/type info is involved — these rules are AST-only.)
47 function medusaOverrides(presetName, dirs) {
48 return medusa.configs[presetName]
49 .filter((b) => b.files && b.rules && Object.keys(b.rules).length > 0)
50 .map((b) => ({
51 files: dirs.flatMap((d) => b.files.map((f) => `${d}/${f}`)),
52 excludedFiles: [
53 ...MEDUSA_EXCLUDED,
54 ...(b.ignores
55 ? dirs.flatMap((d) => b.ignores.map((i) => `${d}/${i}`))
56 : []),
57 ],
58 rules: b.rules,
59 }))
60 }
61
62 module.exports = {
63 root: true,
64 parserOptions: {
65 requireConfigFile: false,
66 ecmaFeatures: {
67 experimentalDecorators: true,
68 },
69 },
70 // Registered so rule references and `eslint-disable` directives resolve. The
71 // style rules come from the scoped overrides below; the Medusa rules from the
72 // generated overrides. `react-hooks`/`@typescript-eslint` are registered (not
73 // enabled globally) so their disable-directives in now-linted packages don't
74 // error "rule not found".
75 plugins: ["prettier", "@medusajs", "@typescript-eslint", "react-hooks"],
76 env: {
77 es6: true,
78 node: true,
79 jest: true,
80 },
81 overrides: [
82 // --- TypeScript parser (syntactic, no `project`) for ALL .ts/.tsx ---
83 // No rule in this repo needs type information anymore (the type-aware
84 // @typescript-eslint rules were disabled to avoid OOM), so a single
85 // program-free parser block covers every TypeScript file.
86 {
87 files: ["*.ts", "*.tsx"],
88 parser: "@typescript-eslint/parser",
89 parserOptions: {
90 sourceType: "module",
91 ecmaVersion: 2021,
92 },
93 },
94
95 // --- Base style rules — historical scope only (Medusa-only pkgs excluded) ---
96 {
97 files: ["**/*.{js,jsx,ts,tsx,cjs,mjs}"],
98 excludedFiles: STYLE_EXCLUDED,
99 plugins: ["prettier"],
100 extends: ["eslint:recommended", "google", "plugin:prettier/recommended"],
101 rules: {
102 curly: ["error", "all"],
103 "new-cap": "off",
104 "require-jsdoc": "off",
105 "no-unused-expressions": "off",
106 "no-unused-vars": "off",
107 camelcase: "off",
108 "no-invalid-this": "off",
109 "max-len": [
110 "error",
111 {
112 code: 80,
113 ignoreStrings: true,
114 ignoreRegExpLiterals: true,
115 ignoreComments: true,
116 ignoreTrailingComments: true,
117 ignoreUrls: true,
118 ignoreTemplateLiterals: true,
119 },
120 ],
121 semi: ["error", "never"],
122 quotes: [
123 "error",
124 "double",
125 {
126 allowTemplateLiterals: true,
127 },
128 ],
129 "comma-dangle": [
130 "error",
131 {
132 arrays: "always-multiline",
133 objects: "always-multiline",
134 imports: "always-multiline",
135 exports: "always-multiline",
136 functions: "never",
137 },
138 ],
139 "object-curly-spacing": ["error", "always"],
140 "arrow-parens": ["error", "always"],
141 "linebreak-style": 0,
142 "no-confusing-arrow": [
143 "error",
144 {
145 allowParens: false,
146 },
147 ],
148 "space-before-function-paren": [
149 "error",
150 {
151 anonymous: "always",
152 named: "never",
153 asyncArrow: "always",
154 },
155 ],
156 "space-infix-ops": "error",
157 "eol-last": ["error", "always"],
158 },
159 },
160
161 // --- TypeScript style rules — historical scope only ---
162 {
163 files: ["*.ts"],
164 excludedFiles: STYLE_EXCLUDED,
165 plugins: ["@typescript-eslint/eslint-plugin"],
166 extends: ["plugin:@typescript-eslint/recommended"],
167 rules: {
168 "valid-jsdoc": "off",
169 "@typescript-eslint/no-non-null-assertion": "off",
170 // Disabled to avoid OOM: these require the TS type-checker, and pointing
171 // `parserOptions.project` at the whole monorepo to feed them exhausted
172 // the heap. Re-enabling needs a scoped/chunked `project` setup.
173 "@typescript-eslint/no-floating-promises": "off",
174 "@typescript-eslint/await-thenable": "off",
175 "@typescript-eslint/promise-function-async": "off",
176 "@typescript-eslint/keyword-spacing": "error",
177 "@typescript-eslint/space-before-function-paren": [
178 "error",
179 {
180 anonymous: "always",
181 named: "never",
182 asyncArrow: "always",
183 },
184 ],
185 "@typescript-eslint/space-infix-ops": "error",
186
187 // --- Rules to be fixed
188 "@typescript-eslint/ban-ts-comment": "off",
189 "@typescript-eslint/no-unused-vars": "off",
190 "@typescript-eslint/no-explicit-any": "off",
191 "@typescript-eslint/explicit-function-return-type": "off",
192 "@typescript-eslint/ban-types": "off",
193 "@typescript-eslint/no-var-requires": "off",
194 },
195 },
196
197 {
198 files: [
199 "./packages/design-system/ui/**/*.ts",
200 "./packages/design-system/ui/**/*.tsx",
201 ],
202 extends: [
203 "plugin:react/recommended",
204 "plugin:react-hooks/recommended",
205 "plugin:@typescript-eslint/recommended",
206 ],
207 plugins: ["@typescript-eslint"],
208 rules: {
209 "react/no-children-prop": "off",
210 "react-hooks/exhaustive-deps": "warn",
211 "react/prop-types": "off",
212 "@typescript-eslint/no-explicit-any": "off",
213 "@typescript-eslint/no-unused-vars": [
214 "error",
215 { argsIgnorePattern: "^_" },
216 ],
217 },
218 settings: {
219 react: {
220 version: "detect",
221 },
222 },
223 parser: "@typescript-eslint/parser",
224 parserOptions: {
225 project: "./packages/design-system/ui/tsconfig.json",
226 },
227 },
228 {
229 files: [
230 "./packages/design-system/icons/**/*.ts",
231 "./packages/design-system/icons/**/*.tsx",
232 ],
233 extends: [
234 "plugin:react/recommended",
235 "plugin:@typescript-eslint/recommended",
236 ],
237 plugins: ["@typescript-eslint"],
238 rules: {
239 "react/no-children-prop": "off",
240 "react/prop-types": "off",
241 "@typescript-eslint/no-explicit-any": "off",
242 "@typescript-eslint/no-unused-vars": [
243 "error",
244 { argsIgnorePattern: "^_" },
245 ],
246 },
247 settings: {
248 react: {
249 version: "detect",
250 },
251 },
252 parser: "@typescript-eslint/parser",
253 parserOptions: {
254 project: "./packages/design-system/icons/tsconfig.json",
255 },
256 },
257 {
258 files: [
259 "./packages/admin/dashboard/**/*.ts",
260 "./packages/admin/dashboard/**/*.tsx",
261 ],
262 plugins: ["unused-imports", "react-refresh"],
263 extends: [
264 "plugin:react/recommended",
265 "plugin:react/jsx-runtime",
266 "plugin:react-hooks/recommended",
267 ],
268 parser: "@typescript-eslint/parser",
269 parserOptions: {
270 ecmaFeatures: {
271 jsx: true,
272 },
273 ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
274 sourceType: "module", // Allows for the use of imports
275 project: path.join(__dirname, "./packages/admin/dashboard/tsconfig.json"),
276 },
277 globals: {
278 __BASE__: "readonly",
279 __AUTH_TYPE__: "readonly",
280 __MAX_UPLOAD_FILE_SIZE__: "readonly",
281 },
282 env: {
283 browser: true,
284 },
285 rules: {
286 "prettier/prettier": "error",
287 "react/prop-types": "off",
288 "new-cap": "off",
289 "require-jsdoc": "off",
290 "valid-jsdoc": "off",
291 "react-refresh/only-export-components": [
292 "warn",
293 { allowConstantExport: true },
294 ],
295 "no-unused-expressions": "off",
296 "unused-imports/no-unused-imports": "error",
297 "unused-imports/no-unused-vars": [
298 "warn",
299 {
300 vars: "all",
301 varsIgnorePattern: "^_",
302 args: "after-used",
303 argsIgnorePattern: "^_",
304 },
305 ],
306 },
307 },
308
309 // --- Medusa convention rules (generated from the plugin presets) ---
310 // `recommended` for the app-like packages. `packages/modules` and
311 // `packages/core/framework` are intentionally excluded from the Medusa rules
312 // here (see MEDUSA_EXCLUDED_DIRS) — they're linted for conventions
313 // separately — so no `modules`-preset override is registered.
314 ...medusaOverrides("recommended", [
315 "packages/medusa",
316 "packages/plugins/*",
317 "packages/core/core-flows",
318 ]),
319 ],
320 }