-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.mjs
More file actions
222 lines (215 loc) · 6.92 KB
/
Copy patheslint.config.mjs
File metadata and controls
222 lines (215 loc) · 6.92 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
import js from "@eslint/js";
import tsPlugin from "@typescript-eslint/eslint-plugin";
import tsParser from "@typescript-eslint/parser";
import { resolve } from "node:path";
/*
* Strict, type-checked ESLint flat config for the @blockchaincommons/dcbor library.
* (Migrated from the @bcts/eslint shared config, inlined here so the package
* is self-contained.)
*/
const project = resolve(process.cwd(), "./tsconfig.json");
export default [
js.configs.recommended,
// Source code rules - strict type checking
{
files: ["src/**/*.ts", "**/*.tsx"],
languageOptions: {
parser: tsParser,
parserOptions: {
ecmaVersion: 2020,
sourceType: "module",
project,
},
globals: {
TextEncoder: "readonly",
TextDecoder: "readonly",
btoa: "readonly",
atob: "readonly",
},
},
plugins: {
"@typescript-eslint": tsPlugin,
},
rules: {
...tsPlugin.configs["recommended-type-checked"].rules,
...tsPlugin.configs["stylistic-type-checked"].rules,
// Conflicts with tsconfig `isolatedDeclarations` (P1.3), which REQUIRES
// explicit annotations on exported consts the rule deems inferrable.
"@typescript-eslint/no-inferrable-types": "off",
// Type safety errors
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-unsafe-assignment": "error",
"@typescript-eslint/no-unsafe-call": "error",
"@typescript-eslint/no-unsafe-member-access": "error",
"@typescript-eslint/no-unsafe-return": "error",
"@typescript-eslint/no-unsafe-argument": "error",
"@typescript-eslint/strict-boolean-expressions": [
"error",
{
allowString: false,
allowNumber: false,
allowNullableObject: false,
},
],
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-misused-promises": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/require-await": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/no-non-null-assertion": "error",
// Code quality
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
},
],
"@typescript-eslint/consistent-type-imports": [
"error",
{
prefer: "type-imports",
fixStyle: "inline-type-imports",
},
],
"@typescript-eslint/consistent-type-exports": [
"error",
{
fixMixedExportsWithInlineTypeSpecifier: true,
},
],
"@typescript-eslint/explicit-function-return-type": [
"error",
{
allowExpressions: true,
allowTypedFunctionExpressions: true,
allowHigherOrderFunctions: true,
},
],
"@typescript-eslint/explicit-module-boundary-types": "error",
"@typescript-eslint/no-redundant-type-constituents": "error",
// Cross-environment compatibility
"no-restricted-globals": [
"error",
{ name: "process", message: "Use platform detection instead" },
{ name: "Buffer", message: "Use Uint8Array for cross-platform compatibility" },
{ name: "__dirname", message: "Not available in all environments" },
{ name: "__filename", message: "Not available in all environments" },
{ name: "window", message: "Not available in Node.js/Bun" },
{ name: "document", message: "Not available in Node.js/Bun" },
{ name: "navigator", message: "Not available in Node.js/Bun" },
],
"no-restricted-syntax": [
"error",
{
selector: 'NewExpression[callee.name="Buffer"]',
message: "Use Uint8Array instead of Buffer for cross-platform compatibility",
},
],
// Best practices for library code
"no-console": "error",
"no-var": "error",
"prefer-const": "error",
"prefer-arrow-callback": "error",
"prefer-template": "error",
"no-throw-literal": "error",
"@typescript-eslint/prefer-nullish-coalescing": "error",
"@typescript-eslint/prefer-optional-chain": "error",
"@typescript-eslint/prefer-readonly": "error",
"@typescript-eslint/prefer-reduce-type-parameter": "error",
"@typescript-eslint/switch-exhaustiveness-check": [
"error",
{ considerDefaultExhaustiveForUnions: true },
],
// A value and a type may intentionally share a name (e.g. `MajorType`,
// `Cbor`, `EdgeType`); tsc already rejects genuine illegal redeclarations.
"no-redeclare": "off",
"@typescript-eslint/no-redeclare": "off",
"@typescript-eslint/no-namespace": "off",
},
settings: {
"import/resolver": {
typescript: {
project,
},
},
},
},
// Test file rules - relaxed for testing
{
files: ["tests/**/*.ts", "**/*.test.ts", "**/*.spec.ts"],
languageOptions: {
parser: tsParser,
parserOptions: {
ecmaVersion: 2020,
sourceType: "module",
project,
},
globals: {
describe: "readonly",
test: "readonly",
it: "readonly",
expect: "readonly",
beforeEach: "readonly",
afterEach: "readonly",
beforeAll: "readonly",
afterAll: "readonly",
jest: "readonly",
console: "readonly",
Buffer: "readonly",
TextEncoder: "readonly",
TextDecoder: "readonly",
},
},
plugins: {
"@typescript-eslint": tsPlugin,
},
rules: {
...tsPlugin.configs.recommended.rules,
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
},
],
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/consistent-type-imports": [
"error",
{
prefer: "type-imports",
fixStyle: "inline-type-imports",
},
],
"@typescript-eslint/strict-boolean-expressions": "off",
"@typescript-eslint/no-floating-promises": "off",
"no-console": "off",
"prefer-const": "warn",
"no-var": "error",
},
},
// Ignore patterns
{
ignores: [
"node_modules/**",
"dist/**",
"coverage/**",
"build/**",
"docs/**",
"examples/**",
"scripts/**",
"**/*.js",
"**/*.mjs",
"**/*.cjs",
],
},
];