|
1
|
// Medusa-only ESLint config. |
|
2
|
// |
|
3
|
// Runs ONLY the `@medusajs/eslint-plugin` convention rules, using the exact |
|
4
|
// scope and rules defined in the root `.eslintrc.js` — the root config stays the |
|
5
|
// single source of truth, and this config follows it automatically. The style / |
|
6
|
// prettier / @typescript-eslint overrides are filtered out so a run reports only |
|
7
|
// Medusa rule violations. |
|
8
|
// |
|
9
|
// Used by the `lint:medusa` npm script (and CI): |
|
10
|
// eslint --no-eslintrc --config eslint.medusa.cjs --ignore-path .eslintignore --ext .js,.ts,.tsx . |
|
11
|
const root = require("./.eslintrc.js") |
|
12
|
|
|
13
|
// An override that only configures the parser (no `rules`) — kept so TypeScript |
|
14
|
// files still parse. |
|
15
|
const isRuleless = (o) => !o.rules || Object.keys(o.rules).length === 0 |
|
16
|
|
|
17
|
// An override whose every rule is a Medusa rule (`@medusajs/*`). |
|
18
|
const isMedusaOverride = (o) => |
|
19
|
o.rules && |
|
20
|
Object.keys(o.rules).length > 0 && |
|
21
|
Object.keys(o.rules).every((rule) => rule.startsWith("@medusajs/")) |
|
22
|
|
|
23
|
const overrides = (root.overrides || []).filter( |
|
24
|
(o) => isRuleless(o) || isMedusaOverride(o) |
|
25
|
) |
|
26
|
|
|
27
|
module.exports = { |
|
28
|
root: true, |
|
29
|
// The root config gets JS parser settings from its (dropped) style overrides' |
|
30
|
// `extends`; supply modern defaults here so plain `.js`/`.mjs`/`.cjs`/`.jsx` |
|
31
|
// files still parse. TypeScript files are handled by the `*.ts`/`*.tsx` parser |
|
32
|
// override carried over from the root config. |
|
33
|
parserOptions: Object.assign({}, root.parserOptions, { |
|
34
|
ecmaVersion: "latest", |
|
35
|
sourceType: "module", |
|
36
|
ecmaFeatures: Object.assign( |
|
37
|
{}, |
|
38
|
root.parserOptions && root.parserOptions.ecmaFeatures, |
|
39
|
{ jsx: true } |
|
40
|
), |
|
41
|
}), |
|
42
|
env: root.env, |
|
43
|
// Reuse the same plugin registrations so rule references and any third-party |
|
44
|
// `eslint-disable` directives in linted files still resolve (no rules from |
|
45
|
// these plugins are enabled here). |
|
46
|
plugins: root.plugins, |
|
47
|
overrides, |
|
48
|
} |