-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy patheslint.config.js
More file actions
81 lines (80 loc) · 3.34 KB
/
Copy patheslint.config.js
File metadata and controls
81 lines (80 loc) · 3.34 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
// Flat config — ported 1:1 from the previous .eslintrc.js so behaviour
// stays the same. Two rule overrides from the old config were dropped
// because the rules no longer exist in @typescript-eslint v8:
// - '@typescript-eslint/camelcase' (removed in v6; superseded by
// '@typescript-eslint/naming-convention', which is not enabled by
// the recommended preset, so the explicit 'off' was already a no-op)
// - '@typescript-eslint/member-delimiter-style' (moved to
// @stylistic in v6; not part of the recommended preset, so the
// explicit 'off' was already a no-op)
//
// Effective rule set: eslint:recommended + plugin:@typescript-eslint/recommended
// (the v8 recommended preset already applies the eslint-recommended
// overrides for TypeScript).
const js = require('@eslint/js')
const tseslint = require('typescript-eslint')
const globals = require('globals')
const n = require('eslint-plugin-n')
module.exports = tseslint.config(
// Replaces the old .eslintignore
{
ignores: ['dist/**', 'node_modules/**', 'example/node_modules/**', '.env'],
},
// eslint 10 enables reportUnusedDisableDirectives by default; the old
// setup (eslint 9 + .eslintrc.js without overrides) did not flag
// them, so turning it off here preserves the v2 lint behaviour.
{
linterOptions: {
reportUnusedDisableDirectives: false,
},
},
js.configs.recommended,
// CJS config files (jest.config.js, eslint.config.js) — declare the
// Node globals that the old .eslintrc.js used to provide implicitly
// via `env: node`.
{
files: ['**/*.js'],
languageOptions: {
globals: { ...globals.node },
sourceType: 'commonjs',
},
},
// Node-API guardrail: reads `engines.node` from package.json and
// flags any built-in / global usage that is not available in that
// version range (e.g. `fs.cp` would error because it requires
// Node 16.7+ while engines.node is '>=12.0.0'). Scoped to src/
// only — runtime code is the only place that ships to consumers;
// tests and config can freely use modern Node APIs.
{
files: ['src/**/*.ts'],
plugins: { n },
rules: {
'n/no-unsupported-features/node-builtins': 'error',
'n/no-unsupported-features/es-builtins': 'error',
// es-syntax is already covered by `target: "ES2019"` in
// tsconfig.build.json (anything newer gets transpiled), so we
// don't duplicate it here.
},
},
// Scope the typescript-eslint recommended preset (and the rule
// overrides below) to .ts only. Without this, flat config applies
// these TS-targeted rules to every file in the project.
{
files: ['**/*.ts'],
extends: [...tseslint.configs.recommended],
rules: {
// Rules introduced (or significantly tightened) in
// @typescript-eslint/recommended v3+, which the old
// .eslintrc.js did not enforce. Disabled to preserve the v2
// recommended-preset behaviour.
//
// 'no-require-imports' is net-new in v8 (replaced the v2
// 'no-var-requires' surface area with a stricter check).
'@typescript-eslint/no-require-imports': 'off',
// 'no-unused-vars' existed in v2 but v8 now flags `const` arrays
// whose only consumer is a `typeof X[number]` type alias — a
// common pattern in this repo (e.g. ITEM_STATUSES, LOAN_*).
'@typescript-eslint/no-unused-vars': 'off',
},
}
)