-
Notifications
You must be signed in to change notification settings - Fork 356
Expand file tree
/
Copy patheslint.config.js
More file actions
241 lines (231 loc) · 6.88 KB
/
Copy patheslint.config.js
File metadata and controls
241 lines (231 loc) · 6.88 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import path from "node:path";
import { includeIgnoreFile } from "@eslint/compat";
import tseslint from "typescript-eslint";
import prettierConfigRules from "eslint-config-prettier/flat";
import prettierPlugin from "eslint-plugin-prettier";
import importPlugin from "eslint-plugin-import";
import tsdoc from "eslint-plugin-tsdoc";
import js from "@eslint/js";
import globals from "globals";
const gitignorePath = path.resolve(".", ".gitignore");
const javascriptConfig = [
js.configs.recommended,
{
name: "javascript/node-globals",
files: ["**/*.js", "**/*.ts"],
languageOptions: {
globals: {
...globals.node,
},
},
},
];
const typescriptConfig = [
// typescript-eslint recommended (registers the parser + plugin)
...tseslint.configs.recommended,
{
name: "typescript/parser-options",
files: ["**/*.ts", "**/*.tsx"],
languageOptions: {
parserOptions: {
projectService: false,
project: ["./tsconfig.json"],
},
},
},
{
name: "typescript/custom-rules",
files: ["**/*.ts", "**/*.tsx"],
rules: {
"@typescript-eslint/require-await": "error",
// Delegated to TypeScript's `noUnusedLocals` / `noUnusedParameters`
// (set in tsconfig.json) — TS understands JSDoc `{@link}` references,
// typescript-eslint's no-unused-vars does not.
"@typescript-eslint/no-unused-vars": "off",
"no-unused-vars": "off",
"no-fallthrough": "off",
// `any` is used deliberately at dynamic boundaries — XDR decoding,
// JSON-RPC payloads, and Horizon response shaping — across ~125 sites,
// too many to annotate individually. Tightening these is tracked as
// separate, incremental work.
"@typescript-eslint/no-explicit-any": "off",
// `namespace` declarations are part of the published public API
// (e.g. Horizon, rpc `Api`, stellartoml), not an organizational crutch.
"@typescript-eslint/no-namespace": "off",
},
},
];
const prettierConfig = [
// Prettier Plugin and Config
{
name: "prettier/config",
plugins: {
prettier: prettierPlugin,
},
rules: {
...prettierConfigRules.rules,
"prettier/prettier": ["error"],
},
},
];
const tsdocConfig = [
{
name: "tsdoc/syntax",
files: ["**/*.ts"],
plugins: { tsdoc },
rules: { "tsdoc/syntax": "warn" },
},
];
const testConfig = [
{
name: "test/typescript",
files: ["test/**/*.ts", "test/**/*.tsx", "test/**/*.js"],
languageOptions: {
parserOptions: {
project: "./test/tsconfig.json",
},
},
rules: {
"no-unused-vars": 0,
radix: 0,
"@typescript-eslint/no-throw-literal": 0,
},
},
];
// Guide snippets (examples/guides/*.ts) are standalone programs embedded into
// docs/guides/*.md, not library code. They live outside tsconfig.json's `src`
// include, so point type-aware lint at their own project.
const examplesConfig = [
{
name: "examples/typescript",
files: ["examples/**/*.ts"],
languageOptions: {
parserOptions: {
project: "./examples/tsconfig.json",
},
},
rules: {
// Snippets read as documentation: they log, and they evaluate
// expressions like `result.hash` to show what a response carries.
"no-console": "off",
"@typescript-eslint/no-unused-expressions": "off",
},
},
];
const scriptsConfig = [
{
name: "scripts/typescript",
files: ["scripts/**/*.ts"],
languageOptions: {
parserOptions: {
project: "./scripts/tsconfig.json",
},
},
},
];
// The base XDR/SDK module preserves a public API shape (namespace+const merging,
// XDR-string-literal type aliases, snake_case helpers like `best_r`, leading-_
// internals) and uses a "public API at top, helpers below" file layout. Loosen
// rules that would otherwise force breaking renames or large reorders.
const baseSdkConfig = [
{
name: "base/sdk-public-api",
files: ["src/base/**/*.ts"],
rules: {
"@typescript-eslint/no-redeclare": "off",
"@typescript-eslint/no-use-before-define": [
"error",
{ functions: false },
],
"@typescript-eslint/naming-convention": "off",
},
},
];
// The generated class-XDR layer relies on abstract-base ↔ concrete-subclass
// references that are only safe under class hoisting, and preserves generated
// naming/redeclaration shapes. Loosen the rules that would otherwise flag them.
const xdrGenConfig = [
{
name: "src/xdr",
files: ["src/xdr/**/*.ts"],
rules: {
"@typescript-eslint/no-redeclare": "off",
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/no-use-before-define": [
"error",
{ functions: false },
],
},
},
];
// scripts/build-docs.ts dispatches a discriminated-union renderer through
// mutually recursive helpers; function-declaration hoisting handles the
// runtime ordering. Match baseSdkConfig's `functions: false` loosening.
//
// The scripts are dev-only docs tooling, never bundled into the published
// package, so importing devDependencies (e.g. github-slugger) is expected —
// override airbnb's default that only allows devDeps in test/build-config
// globs.
const scriptsRulesConfig = [
{
name: "scripts/mutual-recursion",
files: ["scripts/**/*.ts"],
rules: {
"@typescript-eslint/no-use-before-define": [
"error",
{ functions: false },
],
"import/no-extraneous-dependencies": ["error", { devDependencies: true }],
},
},
];
const importConfig = [
{
name: "import/plugin/config",
plugins: {
import: importPlugin,
},
},
];
const ignoreFiles = includeIgnoreFile(gitignorePath);
ignoreFiles.ignores.push(
...[
"eslint.config.js",
"rollup.config.mjs",
"config/**/*",
"src/base/generated/**",
"tools/**",
// Astro build-time configs — excluded from tsconfig.json (they
// import the virtual `astro:content` module), so the typescript-
// eslint parser can't resolve them via the SDK project. Lint
// coverage from prettier is sufficient for these small configs.
"src/content.config.ts",
"astro.config.mjs",
],
);
export default [
// Ignore .gitignore files/folder in eslint
ignoreFiles,
// Import Plugin Config
...importConfig,
// JavaScript Config
...javascriptConfig,
// TypeScript Config
...typescriptConfig,
// XDR Gen Config (must come after typescriptConfig to allow overrides)
...xdrGenConfig,
// TSDoc Config
...tsdocConfig,
// Test Config
...testConfig,
// Scripts Config (uses scripts/tsconfig.json for type-aware lint)
...scriptsConfig,
// Examples Config (uses examples/tsconfig.json for type-aware lint)
...examplesConfig,
// Base SDK overrides (must come after typescriptConfig/tsdocConfig)
...baseSdkConfig,
// Scripts overrides (must come after typescriptConfig/scriptsConfig)
...scriptsRulesConfig,
// Prettier Config
...prettierConfig,
];