lintmax 0.1.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +2629 -0
- package/dist/eslint.d.mts +7 -0
- package/dist/eslint.mjs +449 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.mjs +2 -0
- package/dist/lintmax-types-yjUuaLkM.d.mts +68 -0
- package/dist/path-BJn_2Ond.mjs +346 -0
- package/dist/src-Dd1x9nto.mjs +803 -0
- package/oxlintrc.json +161 -0
- package/package.json +90 -0
- package/tsconfig.json +27 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { n as EslintOptions } from "./lintmax-types-yjUuaLkM.mjs";
|
|
2
|
+
import { Linter } from "eslint";
|
|
3
|
+
//#region src/eslint.d.ts
|
|
4
|
+
declare const eslintFactory: (options?: EslintOptions) => Promise<Linter.Config[]>;
|
|
5
|
+
declare const defaultConfig: Linter.Config[];
|
|
6
|
+
//#endregion
|
|
7
|
+
export { type EslintOptions, defaultConfig as default, eslintFactory as eslint };
|
package/dist/eslint.mjs
ADDED
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
import { E as TAILWIND_ENTRY_CANDIDATES, T as SHARED_OVERRIDE_SYMBOL_KEY, b as DEFAULT_SHARED_IGNORE_PATTERNS, c as findUnknownRules, d as normalizeObjectListInput, f as normalizePathListInput, g as warnToError, i as joinPath, l as isRecord, m as normalizeTailwindOption, p as normalizeRulesOffInput, r as isAbsolutePath, x as ESLINT_TEST_FILE_PATTERNS } from "./path-BJn_2Ond.mjs";
|
|
2
|
+
import { file } from "bun";
|
|
3
|
+
import eslintReact from "@eslint-react/eslint-plugin";
|
|
4
|
+
import { includeIgnoreFile } from "@eslint/compat";
|
|
5
|
+
import eslint from "@eslint/js";
|
|
6
|
+
import nextPlugin from "@next/eslint-plugin-next";
|
|
7
|
+
import eslintPluginBetterTailwindcss from "eslint-plugin-better-tailwindcss";
|
|
8
|
+
import erasableSyntaxOnly from "eslint-plugin-erasable-syntax-only";
|
|
9
|
+
import { configs } from "eslint-plugin-package-json";
|
|
10
|
+
import { configs as configs$1 } from "eslint-plugin-perfectionist";
|
|
11
|
+
import preferArrow from "eslint-plugin-prefer-arrow-functions";
|
|
12
|
+
import reactPlugin from "eslint-plugin-react";
|
|
13
|
+
import reactHooks from "eslint-plugin-react-hooks";
|
|
14
|
+
import { configs as configs$2 } from "eslint-plugin-regexp";
|
|
15
|
+
import sonarjs from "eslint-plugin-sonarjs";
|
|
16
|
+
import turbo from "eslint-plugin-turbo";
|
|
17
|
+
import { defineConfig, globalIgnores } from "eslint/config";
|
|
18
|
+
import tseslint from "typescript-eslint";
|
|
19
|
+
//#region src/eslint.ts
|
|
20
|
+
const sharedOverrideMarker = Symbol.for(SHARED_OVERRIDE_SYMBOL_KEY);
|
|
21
|
+
const normalizeAppendInput = ({ append }) => {
|
|
22
|
+
const out = [];
|
|
23
|
+
for (const value of normalizeObjectListInput({
|
|
24
|
+
allowNonPlain: true,
|
|
25
|
+
label: "eslint.append",
|
|
26
|
+
value: append
|
|
27
|
+
})) out.push(value);
|
|
28
|
+
return out;
|
|
29
|
+
};
|
|
30
|
+
const validateEslintOptions = async ({ options }) => {
|
|
31
|
+
if (!options) return;
|
|
32
|
+
if (options.ignores !== void 0) normalizePathListInput({
|
|
33
|
+
allowUndefined: true,
|
|
34
|
+
label: "eslint.ignores",
|
|
35
|
+
value: options.ignores
|
|
36
|
+
});
|
|
37
|
+
if (options.off !== void 0) normalizeRulesOffInput({
|
|
38
|
+
label: "eslint.off",
|
|
39
|
+
value: options.off
|
|
40
|
+
});
|
|
41
|
+
if (options.append !== void 0) normalizeAppendInput({ append: options.append });
|
|
42
|
+
const tailwindEntrySetting = normalizeTailwindOption({
|
|
43
|
+
label: "eslint.tailwind",
|
|
44
|
+
value: options.tailwind
|
|
45
|
+
});
|
|
46
|
+
if (typeof tailwindEntrySetting === "string") {
|
|
47
|
+
const root = options.tsconfigRootDir ?? process.cwd();
|
|
48
|
+
const resolved = isAbsolutePath(tailwindEntrySetting) ? tailwindEntrySetting : joinPath(root, tailwindEntrySetting);
|
|
49
|
+
if (!await file(resolved).exists()) throw new Error(`eslint.tailwind file not found: ${resolved}. Use an existing path, set eslint.tailwind to false, or remove eslint.tailwind to use auto-detection.`);
|
|
50
|
+
}
|
|
51
|
+
if (options.tsconfigRootDir !== void 0 && typeof options.tsconfigRootDir !== "string") throw new Error("eslint.tsconfigRootDir must be a string");
|
|
52
|
+
};
|
|
53
|
+
const collectKnownEslintRuleNames = ({ appendConfigs, baseConfigs }) => {
|
|
54
|
+
const knownRuleNames = /* @__PURE__ */ new Set();
|
|
55
|
+
const seenConfigs = /* @__PURE__ */ new WeakSet();
|
|
56
|
+
const collectPluginRuleNames = ({ plugins }) => {
|
|
57
|
+
if (!isRecord(plugins)) return;
|
|
58
|
+
for (const [pluginName, plugin] of Object.entries(plugins)) if (isRecord(plugin) && isRecord(plugin.rules)) for (const ruleName of Object.keys(plugin.rules)) knownRuleNames.add(`${pluginName}/${ruleName}`);
|
|
59
|
+
};
|
|
60
|
+
const collectFromConfig = ({ config, includeRules }) => {
|
|
61
|
+
if (typeof config !== "object" || config === null) return;
|
|
62
|
+
if (seenConfigs.has(config)) return;
|
|
63
|
+
seenConfigs.add(config);
|
|
64
|
+
if (Array.isArray(config)) {
|
|
65
|
+
for (const entry of config) collectFromConfig({
|
|
66
|
+
config: entry,
|
|
67
|
+
includeRules
|
|
68
|
+
});
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (!isRecord(config)) return;
|
|
72
|
+
if (includeRules && isRecord(config.rules)) for (const ruleName of Object.keys(config.rules)) knownRuleNames.add(ruleName);
|
|
73
|
+
if ("plugins" in config) collectPluginRuleNames({ plugins: config.plugins });
|
|
74
|
+
if ("extends" in config) collectFromConfig({
|
|
75
|
+
config: config.extends,
|
|
76
|
+
includeRules: true
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
for (const config of baseConfigs) collectFromConfig({
|
|
80
|
+
config,
|
|
81
|
+
includeRules: true
|
|
82
|
+
});
|
|
83
|
+
for (const config of appendConfigs) collectFromConfig({
|
|
84
|
+
config,
|
|
85
|
+
includeRules: false
|
|
86
|
+
});
|
|
87
|
+
return knownRuleNames;
|
|
88
|
+
};
|
|
89
|
+
const getSharedAppendConfig = ({ config }) => {
|
|
90
|
+
return config[sharedOverrideMarker] === true ? config : null;
|
|
91
|
+
};
|
|
92
|
+
const resolveTailwindEntry = async ({ root, tailwind }) => {
|
|
93
|
+
const tailwindSetting = tailwind ?? true;
|
|
94
|
+
if (tailwindSetting === false) return;
|
|
95
|
+
if (typeof tailwindSetting === "string") return isAbsolutePath(tailwindSetting) ? tailwindSetting : joinPath(root, tailwindSetting);
|
|
96
|
+
const matches = (await Promise.all(TAILWIND_ENTRY_CANDIDATES.map(async (candidate) => {
|
|
97
|
+
const resolved = joinPath(root, candidate);
|
|
98
|
+
return await file(resolved).exists() ? [resolved] : [];
|
|
99
|
+
}))).flat();
|
|
100
|
+
if (matches.length <= 1) return matches[0];
|
|
101
|
+
const preferredOnAmbiguous = [joinPath(root, "ui/src/styles/globals.css")];
|
|
102
|
+
for (const preferred of preferredOnAmbiguous) if (matches.includes(preferred)) return preferred;
|
|
103
|
+
const relMatches = matches.map((path) => path.slice(root.length + 1));
|
|
104
|
+
throw new Error(`Multiple Tailwind entry files found: ${relMatches.join(", ")}. Set eslint.tailwind to an explicit path.`);
|
|
105
|
+
};
|
|
106
|
+
/** The files whose rules need a JavaScript AST. A config that carries JS rules and NO `files` matches every path eslint is handed — harmless while the gate only ever linted JS/TS, and a hard crash the moment a non-JS file type joins the target set, because a type-aware rule then runs against (say) the JSON parser's tree. Every such config is scoped to these. */
|
|
107
|
+
const SOURCE_FILE_PATTERNS = [
|
|
108
|
+
"**/*.js",
|
|
109
|
+
"**/*.jsx",
|
|
110
|
+
"**/*.mjs",
|
|
111
|
+
"**/*.cjs",
|
|
112
|
+
"**/*.ts",
|
|
113
|
+
"**/*.tsx"
|
|
114
|
+
];
|
|
115
|
+
const tailwindRules = (entryPoint) => entryPoint ? eslintPluginBetterTailwindcss.configs["recommended-error"].rules : {};
|
|
116
|
+
/** regexp's `flat/recommended` is the curated set: it keeps every correctness rule (no-super-linear-backtracking — the real ReDoS — plus no-misleading-capturing-group, no-dupe-disjunctions, no-unused-capturing-group) and drops the pure-style ones `flat/all` adds (prefer-named-capture-group, require-unicode-sets-regexp, sort-character-class-elements) and the author-excluded advisory no-super-linear-move. Its rules ship at warn, and a warn enforces nothing because the gate's `warnToError` covers consumer overrides, not a config reached through `extends`, so they are lifted to error here. */
|
|
117
|
+
const regexpRecommendedAtError = () => {
|
|
118
|
+
const rec = configs$2["flat/recommended"];
|
|
119
|
+
return {
|
|
120
|
+
...rec,
|
|
121
|
+
rules: warnToError(rec.rules ?? {})
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
/** package.json is a file type the gate would otherwise never lint. The plugin ships its own `files` glob and JSON parser, so it stands alone rather than riding the TypeScript block. Its `recommended` + `stylistic` are the curated set; the `require-*` family stays out because those demand OPT-IN metadata (`bin`, `browser`, `cpu`, `gypfile`, `libc`, `man`, `os`) that no ordinary package declares. `require-type` is disabled with cause: its autofix stamps `"type": "commonjs"` onto any manifest missing `type`, which silently BREAKS an ESM package (a Next/MDX app relying on extension-based resolution) — a rule that guesses a load-bearing field and defaults it wrong is harm, not strictness. */
|
|
125
|
+
const packageJsonConfig = () => {
|
|
126
|
+
const recommended = configs.recommended;
|
|
127
|
+
const stylistic = configs.stylistic;
|
|
128
|
+
return {
|
|
129
|
+
...recommended,
|
|
130
|
+
rules: {
|
|
131
|
+
...warnToError({
|
|
132
|
+
...recommended.rules,
|
|
133
|
+
...stylistic.rules
|
|
134
|
+
}),
|
|
135
|
+
"package-json/require-type": "off",
|
|
136
|
+
"package-json/specify-peers-locally": "off"
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
const buildBaseTypescriptConfigs = () => defineConfig({
|
|
141
|
+
...configs$1["recommended-natural"],
|
|
142
|
+
files: SOURCE_FILE_PATTERNS
|
|
143
|
+
}, { ignores: ["**/postcss.config.mjs"] }, {
|
|
144
|
+
extends: [
|
|
145
|
+
eslint.configs.recommended,
|
|
146
|
+
eslint.configs.all,
|
|
147
|
+
...tseslint.configs.all,
|
|
148
|
+
...tseslint.configs.recommended,
|
|
149
|
+
...tseslint.configs.recommendedTypeChecked,
|
|
150
|
+
...tseslint.configs.stylisticTypeChecked,
|
|
151
|
+
eslintReact.configs.all,
|
|
152
|
+
eslintReact.configs["strict-type-checked"],
|
|
153
|
+
eslintReact.configs.recommended,
|
|
154
|
+
eslintReact.configs.dom,
|
|
155
|
+
eslintReact.configs["web-api"],
|
|
156
|
+
eslintReact.configs.jsx,
|
|
157
|
+
eslintReact.configs["naming-convention"],
|
|
158
|
+
eslintReact.configs.rsc,
|
|
159
|
+
regexpRecommendedAtError(),
|
|
160
|
+
sonarjs.configs.recommended,
|
|
161
|
+
erasableSyntaxOnly.configs.recommended
|
|
162
|
+
],
|
|
163
|
+
files: [
|
|
164
|
+
"**/*.js",
|
|
165
|
+
"**/*.ts",
|
|
166
|
+
"**/*.tsx"
|
|
167
|
+
],
|
|
168
|
+
plugins: {
|
|
169
|
+
preferArrow,
|
|
170
|
+
turbo
|
|
171
|
+
},
|
|
172
|
+
rules: {
|
|
173
|
+
"@eslint-react/jsx-no-leaked-dollar": "error",
|
|
174
|
+
"@eslint-react/naming-convention-ref-name": "error",
|
|
175
|
+
"@eslint-react/no-duplicate-key": "error",
|
|
176
|
+
"@eslint-react/no-implicit-key": "error",
|
|
177
|
+
"@eslint-react/no-missing-component-display-name": "error",
|
|
178
|
+
"@eslint-react/no-missing-context-display-name": "error",
|
|
179
|
+
"@typescript-eslint/consistent-return": "off",
|
|
180
|
+
"@typescript-eslint/consistent-type-imports": ["error", {
|
|
181
|
+
fixStyle: "separate-type-imports",
|
|
182
|
+
prefer: "type-imports"
|
|
183
|
+
}],
|
|
184
|
+
"@typescript-eslint/explicit-function-return-type": "off",
|
|
185
|
+
"@typescript-eslint/explicit-member-accessibility": "off",
|
|
186
|
+
"@typescript-eslint/explicit-module-boundary-types": "off",
|
|
187
|
+
"@typescript-eslint/init-declarations": "off",
|
|
188
|
+
"@typescript-eslint/naming-convention": ["error", {
|
|
189
|
+
format: [
|
|
190
|
+
"camelCase",
|
|
191
|
+
"UPPER_CASE",
|
|
192
|
+
"PascalCase"
|
|
193
|
+
],
|
|
194
|
+
selector: "variable"
|
|
195
|
+
}],
|
|
196
|
+
"@typescript-eslint/no-confusing-void-expression": "off",
|
|
197
|
+
"@typescript-eslint/no-floating-promises": "off",
|
|
198
|
+
"@typescript-eslint/no-magic-numbers": "off",
|
|
199
|
+
"@typescript-eslint/no-misused-promises": [2, { checksVoidReturn: { attributes: false } }],
|
|
200
|
+
"@typescript-eslint/no-unnecessary-condition": ["error", { allowConstantLoopConditions: true }],
|
|
201
|
+
"@typescript-eslint/no-unsafe-type-assertion": "off",
|
|
202
|
+
"@typescript-eslint/no-useless-default-assignment": "off",
|
|
203
|
+
"@typescript-eslint/prefer-destructuring": ["error", {
|
|
204
|
+
array: false,
|
|
205
|
+
object: true
|
|
206
|
+
}],
|
|
207
|
+
"@typescript-eslint/prefer-readonly-parameter-types": "off",
|
|
208
|
+
"@typescript-eslint/strict-boolean-expressions": "off",
|
|
209
|
+
camelcase: "off",
|
|
210
|
+
"capitalized-comments": "off",
|
|
211
|
+
curly: ["error", "multi"],
|
|
212
|
+
"id-length": "off",
|
|
213
|
+
"max-lines": "off",
|
|
214
|
+
"max-lines-per-function": "off",
|
|
215
|
+
"max-statements": "off",
|
|
216
|
+
"new-cap": ["error", { capIsNewExceptionPattern: ".*" }],
|
|
217
|
+
"no-duplicate-imports": ["error", { allowSeparateTypeImports: true }],
|
|
218
|
+
"no-magic-numbers": "off",
|
|
219
|
+
"no-nested-ternary": "off",
|
|
220
|
+
"no-ternary": "off",
|
|
221
|
+
"no-undefined": "off",
|
|
222
|
+
"no-underscore-dangle": "off",
|
|
223
|
+
"one-var": ["error", "never"],
|
|
224
|
+
"perfectionist/sort-imports": ["error", {
|
|
225
|
+
newlinesBetween: 0,
|
|
226
|
+
order: "asc",
|
|
227
|
+
type: "natural"
|
|
228
|
+
}],
|
|
229
|
+
"perfectionist/sort-objects": "off",
|
|
230
|
+
"perfectionist/sort-variable-declarations": "off",
|
|
231
|
+
"preferArrow/prefer-arrow-functions": ["error", { returnStyle: "implicit" }],
|
|
232
|
+
"require-atomic-updates": "off",
|
|
233
|
+
"sort-imports": "off",
|
|
234
|
+
"sort-keys": "off",
|
|
235
|
+
"sort-vars": "off"
|
|
236
|
+
}
|
|
237
|
+
}, {
|
|
238
|
+
files: [
|
|
239
|
+
"**/*.js",
|
|
240
|
+
"**/*.ts",
|
|
241
|
+
"**/*.tsx"
|
|
242
|
+
],
|
|
243
|
+
plugins: eslintReact.configs["strict-type-checked"].plugins,
|
|
244
|
+
rules: {
|
|
245
|
+
...warnToError({
|
|
246
|
+
...eslintReact.configs.all.rules,
|
|
247
|
+
...eslintReact.configs["strict-type-checked"].rules,
|
|
248
|
+
...eslintReact.configs.recommended.rules,
|
|
249
|
+
...eslintReact.configs.dom.rules,
|
|
250
|
+
...eslintReact.configs["web-api"].rules,
|
|
251
|
+
...eslintReact.configs.jsx.rules,
|
|
252
|
+
...eslintReact.configs["naming-convention"].rules,
|
|
253
|
+
...eslintReact.configs.rsc.rules
|
|
254
|
+
}),
|
|
255
|
+
"@eslint-react/dom-no-string-style-prop": "error",
|
|
256
|
+
"@eslint-react/dom-no-unknown-property": "error"
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
const buildReactConfigs = ({ tailwindEntry, tailwindSettings }) => defineConfig({
|
|
260
|
+
...reactHooks.configs.flat["recommended-latest"],
|
|
261
|
+
files: SOURCE_FILE_PATTERNS
|
|
262
|
+
}, {
|
|
263
|
+
files: ["**/*.ts", "**/*.tsx"],
|
|
264
|
+
...reactPlugin.configs.flat.all,
|
|
265
|
+
...reactPlugin.configs.flat["jsx-runtime"],
|
|
266
|
+
languageOptions: {
|
|
267
|
+
...reactPlugin.configs.flat.all?.languageOptions,
|
|
268
|
+
...reactPlugin.configs.flat["jsx-runtime"]?.languageOptions,
|
|
269
|
+
globals: { React: "writable" }
|
|
270
|
+
},
|
|
271
|
+
plugins: {
|
|
272
|
+
"better-tailwindcss": eslintPluginBetterTailwindcss,
|
|
273
|
+
react: reactPlugin
|
|
274
|
+
},
|
|
275
|
+
rules: {
|
|
276
|
+
...reactPlugin.configs["jsx-runtime"].rules,
|
|
277
|
+
...reactPlugin.configs.all.rules,
|
|
278
|
+
...tailwindRules(tailwindEntry),
|
|
279
|
+
"better-tailwindcss/enforce-consistent-line-wrapping": "off",
|
|
280
|
+
"no-restricted-syntax": ["error", {
|
|
281
|
+
message: "Extract the immediately-invoked function in JSX to a named component; it is rebuilt on every render.",
|
|
282
|
+
selector: "JSXExpressionContainer CallExpression[callee.type=/^(Arrow)?FunctionExpression$/]"
|
|
283
|
+
}],
|
|
284
|
+
"react-hooks/capitalized-calls": "error",
|
|
285
|
+
"react-hooks/component-hook-factories": "error",
|
|
286
|
+
"react-hooks/exhaustive-deps": "error",
|
|
287
|
+
"react-hooks/exhaustive-effect-dependencies": "error",
|
|
288
|
+
"react-hooks/incompatible-library": "error",
|
|
289
|
+
"react-hooks/memo-dependencies": "off",
|
|
290
|
+
"react-hooks/memoized-effect-dependencies": "error",
|
|
291
|
+
"react-hooks/no-deriving-state-in-effects": "error",
|
|
292
|
+
"react-hooks/preserve-manual-memoization": "off",
|
|
293
|
+
"react-hooks/set-state-in-effect": "off",
|
|
294
|
+
"react-hooks/unsupported-syntax": "error",
|
|
295
|
+
"react/forbid-component-props": "off",
|
|
296
|
+
"react/function-component-definition": "off",
|
|
297
|
+
"react/jsx-child-element-spacing": "off",
|
|
298
|
+
"react/jsx-closing-bracket-location": "off",
|
|
299
|
+
"react/jsx-curly-newline": "off",
|
|
300
|
+
"react/jsx-filename-extension": ["error", { extensions: [".tsx"] }],
|
|
301
|
+
"react/jsx-handler-names": "off",
|
|
302
|
+
"react/jsx-indent": "off",
|
|
303
|
+
"react/jsx-indent-props": "off",
|
|
304
|
+
"react/jsx-max-depth": "off",
|
|
305
|
+
"react/jsx-max-props-per-line": "off",
|
|
306
|
+
"react/jsx-newline": "off",
|
|
307
|
+
"react/jsx-no-bind": "off",
|
|
308
|
+
"react/jsx-no-literals": "off",
|
|
309
|
+
"react/jsx-one-expression-per-line": "off",
|
|
310
|
+
"react/jsx-props-no-spreading": "off",
|
|
311
|
+
"react/jsx-sort-props": ["error", { ignoreCase: true }],
|
|
312
|
+
"react/no-multi-comp": "off",
|
|
313
|
+
"react/prefer-read-only-props": "off",
|
|
314
|
+
"react/require-default-props": "off"
|
|
315
|
+
},
|
|
316
|
+
settings: tailwindSettings
|
|
317
|
+
});
|
|
318
|
+
const buildNextConfigs = () => defineConfig({
|
|
319
|
+
files: ["**/*.ts", "**/*.tsx"],
|
|
320
|
+
plugins: { "@next/next": nextPlugin },
|
|
321
|
+
rules: {
|
|
322
|
+
...warnToError({
|
|
323
|
+
...nextPlugin.configs.recommended.rules,
|
|
324
|
+
...nextPlugin.configs["core-web-vitals"].rules
|
|
325
|
+
}),
|
|
326
|
+
"@next/next/no-duplicate-head": "off",
|
|
327
|
+
"@next/next/no-html-link-for-pages": "off"
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
const buildTestFileConfigs = () => defineConfig({
|
|
331
|
+
files: [...ESLINT_TEST_FILE_PATTERNS],
|
|
332
|
+
rules: {
|
|
333
|
+
"@typescript-eslint/await-thenable": "off",
|
|
334
|
+
"@typescript-eslint/no-misused-promises": "off",
|
|
335
|
+
"@typescript-eslint/require-await": "off",
|
|
336
|
+
"@typescript-eslint/strict-void-return": "off",
|
|
337
|
+
"no-await-in-loop": "off",
|
|
338
|
+
"no-control-regex": "off"
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
const buildConvexTestConfigs = () => defineConfig({
|
|
342
|
+
files: ["**/convex/**/*.test.ts", "**/test-utils/**/*.ts"],
|
|
343
|
+
rules: {
|
|
344
|
+
"@typescript-eslint/no-unsafe-argument": "off",
|
|
345
|
+
"@typescript-eslint/no-unsafe-assignment": "off",
|
|
346
|
+
"@typescript-eslint/no-unsafe-call": "off",
|
|
347
|
+
"@typescript-eslint/no-unsafe-member-access": "off",
|
|
348
|
+
"@typescript-eslint/no-unsafe-return": "off"
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
const buildScriptFileConfigs = () => defineConfig({
|
|
352
|
+
files: ["**/*Script.ts", "**/*.generated.ts"],
|
|
353
|
+
rules: { "no-template-curly-in-string": "off" }
|
|
354
|
+
});
|
|
355
|
+
const buildAuthConfigConfigs = () => defineConfig({
|
|
356
|
+
files: ["**/auth.config.js"],
|
|
357
|
+
rules: { "no-undef": "off" }
|
|
358
|
+
});
|
|
359
|
+
const buildOffOverrideConfigs = ({ knownRuleNames, normalizedRules }) => {
|
|
360
|
+
if (!normalizedRules) return [];
|
|
361
|
+
const unknownRules = findUnknownRules({
|
|
362
|
+
knownRules: knownRuleNames,
|
|
363
|
+
rules: normalizedRules
|
|
364
|
+
});
|
|
365
|
+
if (unknownRules.length > 0) throw new Error(`eslint.off contains unknown eslint rules: ${unknownRules.join(", ")}`);
|
|
366
|
+
const overrideRules = {};
|
|
367
|
+
for (const [key, value] of Object.entries(normalizedRules)) overrideRules[key] = value;
|
|
368
|
+
return [{ rules: overrideRules }];
|
|
369
|
+
};
|
|
370
|
+
const buildAppendOverrideConfigs = ({ appendConfigs, knownRuleNames }) => {
|
|
371
|
+
const out = [];
|
|
372
|
+
for (const config of appendConfigs) {
|
|
373
|
+
const shared = getSharedAppendConfig({ config });
|
|
374
|
+
const unknownRules = shared && config.rules ? findUnknownRules({
|
|
375
|
+
knownRules: knownRuleNames,
|
|
376
|
+
rules: config.rules
|
|
377
|
+
}) : [];
|
|
378
|
+
if (unknownRules.length > 0) throw new Error(`overrides.eslint contains unknown eslint rules: ${unknownRules.join(", ")}`);
|
|
379
|
+
const sanitized = shared === null ? config : (() => {
|
|
380
|
+
const sanitizedShared = {};
|
|
381
|
+
if (shared.files !== void 0) sanitizedShared.files = shared.files;
|
|
382
|
+
if (shared.rules !== void 0) sanitizedShared.rules = shared.rules;
|
|
383
|
+
return sanitizedShared;
|
|
384
|
+
})();
|
|
385
|
+
out.push(sanitized.rules ? {
|
|
386
|
+
...sanitized,
|
|
387
|
+
rules: warnToError(sanitized.rules)
|
|
388
|
+
} : sanitized);
|
|
389
|
+
}
|
|
390
|
+
return out;
|
|
391
|
+
};
|
|
392
|
+
const buildParserOptionsConfigs = ({ root }) => [{
|
|
393
|
+
files: SOURCE_FILE_PATTERNS,
|
|
394
|
+
languageOptions: { parserOptions: {
|
|
395
|
+
projectService: true,
|
|
396
|
+
tsconfigRootDir: root
|
|
397
|
+
} }
|
|
398
|
+
}, { linterOptions: { reportUnusedDisableDirectives: true } }];
|
|
399
|
+
const eslintFactory = async (options) => {
|
|
400
|
+
await validateEslintOptions({ options });
|
|
401
|
+
const opts = options ?? {};
|
|
402
|
+
const root = opts.tsconfigRootDir ?? process.cwd();
|
|
403
|
+
const configs = [];
|
|
404
|
+
const gitignorePath = joinPath(root, ".gitignore");
|
|
405
|
+
const normalizedIgnores = normalizePathListInput({
|
|
406
|
+
allowUndefined: true,
|
|
407
|
+
label: "eslint.ignores",
|
|
408
|
+
value: opts.ignores
|
|
409
|
+
});
|
|
410
|
+
const tailwindEntry = await resolveTailwindEntry({
|
|
411
|
+
root,
|
|
412
|
+
tailwind: opts.tailwind
|
|
413
|
+
});
|
|
414
|
+
const tailwindSettings = {};
|
|
415
|
+
if (tailwindEntry) tailwindSettings["better-tailwindcss"] = { entryPoint: tailwindEntry };
|
|
416
|
+
configs.push(globalIgnores([...DEFAULT_SHARED_IGNORE_PATTERNS, ...normalizedIgnores]));
|
|
417
|
+
try {
|
|
418
|
+
configs.push(includeIgnoreFile(gitignorePath));
|
|
419
|
+
} catch (error) {
|
|
420
|
+
if (error instanceof Error) {
|
|
421
|
+
const message = error.message.toLowerCase();
|
|
422
|
+
if (!(message.includes("enoent") || message.includes("no such file"))) throw error;
|
|
423
|
+
} else throw error;
|
|
424
|
+
}
|
|
425
|
+
configs.push(packageJsonConfig(), ...buildBaseTypescriptConfigs(), ...buildReactConfigs({
|
|
426
|
+
tailwindEntry,
|
|
427
|
+
tailwindSettings
|
|
428
|
+
}), ...buildNextConfigs(), ...buildTestFileConfigs(), ...buildConvexTestConfigs(), ...buildScriptFileConfigs(), ...buildAuthConfigConfigs());
|
|
429
|
+
const appendConfigs = normalizeAppendInput({ append: opts.append });
|
|
430
|
+
const knownRuleNames = collectKnownEslintRuleNames({
|
|
431
|
+
appendConfigs,
|
|
432
|
+
baseConfigs: configs
|
|
433
|
+
});
|
|
434
|
+
const normalizedRules = normalizeRulesOffInput({
|
|
435
|
+
label: "eslint.off",
|
|
436
|
+
value: opts.off
|
|
437
|
+
});
|
|
438
|
+
configs.push(...buildOffOverrideConfigs({
|
|
439
|
+
knownRuleNames,
|
|
440
|
+
normalizedRules
|
|
441
|
+
}), ...buildAppendOverrideConfigs({
|
|
442
|
+
appendConfigs,
|
|
443
|
+
knownRuleNames
|
|
444
|
+
}), ...buildParserOptionsConfigs({ root }));
|
|
445
|
+
return defineConfig(...configs);
|
|
446
|
+
};
|
|
447
|
+
const defaultConfig = await eslintFactory();
|
|
448
|
+
//#endregion
|
|
449
|
+
export { defaultConfig as default, eslintFactory as eslint };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { r as SyncOptions, t as EslintImportAppendEntry } from "./lintmax-types-yjUuaLkM.mjs";
|
|
2
|
+
//#region src/index.d.ts
|
|
3
|
+
declare const sync: (options?: SyncOptions) => Promise<void>;
|
|
4
|
+
declare const eslintImport: ({ files, from, ignores, name }: Omit<EslintImportAppendEntry, "$lintmax">) => EslintImportAppendEntry;
|
|
5
|
+
declare const defineConfig: <T extends SyncOptions>(options: T) => T;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { type EslintImportAppendEntry, type SyncOptions, defineConfig, eslintImport, sync };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Linter } from "eslint";
|
|
2
|
+
//#region src/lintmax-types.d.ts
|
|
3
|
+
interface BiomeOptions {
|
|
4
|
+
ignores?: PathListInput;
|
|
5
|
+
off?: RulesOffInput;
|
|
6
|
+
overrides?: {
|
|
7
|
+
includes: PathListInput;
|
|
8
|
+
off: RulesOffInput;
|
|
9
|
+
}[];
|
|
10
|
+
}
|
|
11
|
+
interface EslintImportAppendEntry {
|
|
12
|
+
$lintmax: 'eslint-import';
|
|
13
|
+
files?: PathListInput;
|
|
14
|
+
from: string;
|
|
15
|
+
ignores?: PathListInput;
|
|
16
|
+
name?: string;
|
|
17
|
+
}
|
|
18
|
+
interface EslintOptions {
|
|
19
|
+
append?: Linter.Config[];
|
|
20
|
+
ignores?: PathListInput;
|
|
21
|
+
off?: RulesOffInput;
|
|
22
|
+
tailwind?: TailwindOption;
|
|
23
|
+
tsconfigRootDir?: string;
|
|
24
|
+
}
|
|
25
|
+
interface JsonObject {
|
|
26
|
+
[key: string]: JsonValue;
|
|
27
|
+
}
|
|
28
|
+
type JsonPrimitive = boolean | null | number | string;
|
|
29
|
+
type JsonValue = JsonObject | JsonPrimitive | JsonValue[];
|
|
30
|
+
interface OxlintOptions {
|
|
31
|
+
ignores?: PathListInput;
|
|
32
|
+
off?: RulesOffInput;
|
|
33
|
+
overrides?: {
|
|
34
|
+
files: PathListInput;
|
|
35
|
+
off: RulesOffInput;
|
|
36
|
+
}[];
|
|
37
|
+
}
|
|
38
|
+
type PathListInput = readonly string[];
|
|
39
|
+
type RulesOffInput = readonly string[];
|
|
40
|
+
type SharedOverrideMapRuleOptions = {
|
|
41
|
+
biome: RulesOffInput;
|
|
42
|
+
eslint?: RulesOffInput;
|
|
43
|
+
oxlint?: RulesOffInput;
|
|
44
|
+
} | {
|
|
45
|
+
biome?: RulesOffInput;
|
|
46
|
+
eslint: RulesOffInput;
|
|
47
|
+
oxlint?: RulesOffInput;
|
|
48
|
+
} | {
|
|
49
|
+
biome?: RulesOffInput;
|
|
50
|
+
eslint?: RulesOffInput;
|
|
51
|
+
oxlint: RulesOffInput;
|
|
52
|
+
};
|
|
53
|
+
interface SyncOptions {
|
|
54
|
+
biome?: BiomeOptions;
|
|
55
|
+
comments?: boolean;
|
|
56
|
+
compact?: boolean;
|
|
57
|
+
eslint?: Omit<EslintOptions, 'append' | 'tailwind' | 'tsconfigRootDir'> & {
|
|
58
|
+
append?: readonly (EslintImportAppendEntry | JsonObject)[];
|
|
59
|
+
};
|
|
60
|
+
ignores?: PathListInput;
|
|
61
|
+
overrides?: Record<string, SharedOverrideMapRuleOptions>;
|
|
62
|
+
oxlint?: OxlintOptions;
|
|
63
|
+
tailwind?: TailwindOption;
|
|
64
|
+
tsconfigRootDir?: string;
|
|
65
|
+
}
|
|
66
|
+
type TailwindOption = boolean | string;
|
|
67
|
+
//#endregion
|
|
68
|
+
export { EslintOptions as n, SyncOptions as r, EslintImportAppendEntry as t };
|