|
1
|
import type { Linter } from "eslint" |
|
2
|
import { PLUGIN_NAMESPACE } from "../constants" |
|
3
|
|
|
4
|
/** |
|
5
|
* The directories every preset ignores: build output, dependency trees, caches, |
|
6
|
* generated sources, and test scaffolding. Test files and fixtures aren't real |
|
7
|
* Medusa source — linting them produces false positives (e.g. treating a test |
|
8
|
* `medusa-config.js` fixture as a project config), so they're excluded here. |
|
9
|
*/ |
|
10
|
export const ignoresBlock: Linter.Config = { |
|
11
|
ignores: [ |
|
12
|
"**/.medusa/**", |
|
13
|
"**/.yalc/**", |
|
14
|
"**/dist/**", |
|
15
|
"**/build/**", |
|
16
|
"**/node_modules/**", |
|
17
|
"**/coverage/**", |
|
18
|
"**/.cache/**", |
|
19
|
"**/*.generated.ts", |
|
20
|
"**/__tests__/**", |
|
21
|
"**/__fixtures__/**", |
|
22
|
"**/__mocks__/**", |
|
23
|
"**/integration-tests/**", |
|
24
|
"**/*.spec.*", |
|
25
|
"**/*.test.*", |
|
26
|
"**/apps/storefront/**" |
|
27
|
], |
|
28
|
} |
|
29
|
|
|
30
|
/** |
|
31
|
* Register the plugin globally (no `files` key) so that EVERY file ESLint |
|
32
|
* processes can resolve `@medusajs/*` rule references — including `.js`/`.mjs`/ |
|
33
|
* `.cjs`/`.jsx` files matched by directory-scoped rule blocks, and the |
|
34
|
* `eslint.config.js` file itself. If this registration were scoped to |
|
35
|
* `.ts,.tsx` only, linting a matched `.js` file would fail with |
|
36
|
* `Could not find plugin "@medusajs" in configuration`. |
|
37
|
*/ |
|
38
|
export function pluginBlock(plugin: unknown): Linter.Config { |
|
39
|
return { plugins: { [PLUGIN_NAMESPACE]: plugin as never } } |
|
40
|
} |
|
41
|
|
|
42
|
/** |
|
43
|
* Parse TypeScript source with the bundled `@typescript-eslint/parser`. |
|
44
|
* |
|
45
|
* `withProject` controls type-aware parsing: |
|
46
|
* - `true` sets `parserOptions.project` (required by type-aware rules; consumers |
|
47
|
* must have a tsconfig that includes the linted files). |
|
48
|
* - `false` (the default) skips it, so the preset is zero-config — no rule in it |
|
49
|
* needs type information, so there is nothing to gain from building a program. |
|
50
|
*/ |
|
51
|
export function tsParserBlock(withProject = false): Linter.Config { |
|
52
|
return { |
|
53
|
files: ["**/*.{ts,tsx}"], |
|
54
|
languageOptions: { |
|
55
|
parser: require("@typescript-eslint/parser"), |
|
56
|
parserOptions: withProject |
|
57
|
? { project: true, sourceType: "module" } |
|
58
|
: { sourceType: "module" }, |
|
59
|
}, |
|
60
|
rules: {}, |
|
61
|
} |
|
62
|
} |