@kirill.konshin/lint 0.8.9 → 0.8.10
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 +5 -5
- package/dist/configs/base.js +2 -4
- package/dist/configs/nx.d.ts +3 -1
- package/dist/configs/nx.js +4 -4
- package/dist/configs/promise.js +2 -6
- package/dist/configs/react.d.ts +4 -2
- package/dist/configs/react.js +12 -31
- package/dist/configs/testing.js +32 -18
- package/dist/configs/turbo.d.ts +4 -3
- package/dist/configs/turbo.js +5 -7
- package/dist/configs/unicorn.js +2 -2
- package/dist/conventions.d.ts +26 -1
- package/dist/conventions.js +66 -1
- package/dist/exts.d.ts +3 -0
- package/dist/exts.js +4 -1
- package/dist/gates.d.ts +5 -5
- package/dist/gates.js +36 -24
- package/dist/graphify.d.ts +10 -5
- package/dist/graphify.js +35 -40
- package/dist/index.d.ts +6 -6
- package/dist/index.js +7 -8
- package/dist/lib.d.ts +37 -21
- package/dist/lib.js +104 -71
- package/dist/lintPrepare.d.ts +11 -8
- package/dist/lintPrepare.js +39 -37
- package/dist/runCommand.d.ts +24 -0
- package/dist/runCommand.js +12 -0
- package/dist/textBlocks.d.ts +7 -0
- package/dist/textBlocks.js +12 -0
- package/dist/vitePlus.js +34 -68
- package/package.json +1 -1
- package/skills/spec-tools/scripts/cli.js +700 -627
package/dist/lintPrepare.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LintConfig, SkillsConfig } from "./config.js";
|
|
2
|
-
import {
|
|
2
|
+
import { RunCommand } from "./runCommand.js";
|
|
3
3
|
//#region src/lintPrepare.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* A rule file. `paths` scopes it: Claude Code loads it only for matching files.
|
|
@@ -20,11 +20,14 @@ type ExistingFile = {
|
|
|
20
20
|
customSection: string | null;
|
|
21
21
|
};
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* A marked section of AGENTS.md another tool owns: its anchors - lines of their own - and what `lint-prepare` writes
|
|
24
|
+
* after them (`tail`).
|
|
24
25
|
*/
|
|
25
|
-
export type
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
export type ToolSection = {
|
|
27
|
+
tool: string;
|
|
28
|
+
start: string;
|
|
29
|
+
end: string;
|
|
30
|
+
tail?: string;
|
|
28
31
|
};
|
|
29
32
|
/**
|
|
30
33
|
* Read all markdown files from the package rules directory.
|
|
@@ -138,9 +141,9 @@ export declare function symlinkClaudeMd(cwd: string): void;
|
|
|
138
141
|
*
|
|
139
142
|
* The links are plain, never `@path` imports: Claude Code loads `.claude/rules` itself (syncAgentDirs() links them
|
|
140
143
|
* there) and honours each rule's `paths`, while an `@` import would load every rule into every session, scoped or not.
|
|
141
|
-
* Codex, which expands no `@`, reads this index. `
|
|
144
|
+
* Codex, which expands no `@`, reads this index. `toolSections` follow the sections of {@link TOOL_SECTIONS}.
|
|
142
145
|
*/
|
|
143
|
-
export declare function generateAgentsFile(rules: Rule[], customSection: string | null, previous?: string,
|
|
146
|
+
export declare function generateAgentsFile(rules: Rule[], customSection: string | null, previous?: string, toolSections?: ToolSection[]): string;
|
|
144
147
|
/**
|
|
145
148
|
* Check if AGENTS.md exists and was generated by this tool. When it was, also return
|
|
146
149
|
* whatever follows the marker (the user's custom section) so it can be carried forward -
|
|
@@ -153,4 +156,4 @@ export declare function checkExisting(targetPath: string): ExistingFile;
|
|
|
153
156
|
*/
|
|
154
157
|
export declare function main(): Promise<void>;
|
|
155
158
|
//#endregion
|
|
156
|
-
export {};
|
|
159
|
+
export type { RunCommand };
|
package/dist/lintPrepare.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { asOptions, findWorkspaceRoot, workspaceDependsOn } from "./lib.js";
|
|
2
|
+
import { asOptions, detectionOf, findWorkspaceRoot, workspaceDependsOn } from "./lib.js";
|
|
3
3
|
import { LINT_CONFIG_FILE, resolveLintConfig } from "./config.js";
|
|
4
|
-
import {
|
|
4
|
+
import { runOrWarn } from "./runCommand.js";
|
|
5
|
+
import { findBlock } from "./textBlocks.js";
|
|
6
|
+
import { GRAPHIFY_SECTION, GRAPHIFY_SKILL, finishGraphify, isGraphifySkill, setUpGraphify, writeGitignoreBlock } from "./graphify.js";
|
|
5
7
|
import { createRequire } from "node:module";
|
|
6
8
|
import fs from "node:fs";
|
|
7
9
|
import path from "node:path";
|
|
@@ -71,6 +73,7 @@ const GENERATED_MARKER = "<!-- @kirill.konshin/lint:generated -->";
|
|
|
71
73
|
* hand: this file only provides each anchor, a marker pair, on every generation, and keeps what the tool wrote between
|
|
72
74
|
* them. Vite+ fills its section on `vp config`, run right after `lint-prepare` in the same install script (it never
|
|
73
75
|
* creates a section, and its creating commands rewrite dependencies); Next.js on `next dev`, when it detects an agent.
|
|
76
|
+
* Sections of tools `lint.config.ts` turns on (graphify) are passed to generateAgentsFile().
|
|
74
77
|
*/
|
|
75
78
|
const TOOL_SECTIONS = [{
|
|
76
79
|
tool: "Vite+",
|
|
@@ -268,8 +271,12 @@ function readRules() {
|
|
|
268
271
|
* shipped with all its files (scripts, references, ...).
|
|
269
272
|
*/
|
|
270
273
|
function readSkills() {
|
|
271
|
-
|
|
272
|
-
|
|
274
|
+
return skillDirs(SKILLS_DIR).sort((a, b) => a.localeCompare(b)).map((name) => ({ name }));
|
|
275
|
+
}
|
|
276
|
+
/** The skills in `root`: every directory holding a `SKILL.md`, by name; none when `root` does not exist. */
|
|
277
|
+
function skillDirs(root) {
|
|
278
|
+
if (!fs.existsSync(root)) return [];
|
|
279
|
+
return fs.readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && fs.existsSync(path.join(root, entry.name, "SKILL.md"))).map((entry) => entry.name);
|
|
273
280
|
}
|
|
274
281
|
/**
|
|
275
282
|
* Package entries to link, keyed by their path inside an agent dir: every rule file as `rules/<file>`. Package skills
|
|
@@ -290,12 +297,7 @@ const skillDirName = (name) => name.toLowerCase().replace(/[^a-z0-9._]+/g, "-").
|
|
|
290
297
|
* none.
|
|
291
298
|
*/
|
|
292
299
|
function readSyncedSkills(cwd) {
|
|
293
|
-
|
|
294
|
-
const skills = JSON.parse(fs.readFileSync(path.join(cwd, SKILLS_LOCK), "utf-8"))?.skills;
|
|
295
|
-
return new Set(skills && typeof skills === "object" ? Object.keys(skills).map(skillDirName) : []);
|
|
296
|
-
} catch {
|
|
297
|
-
return /* @__PURE__ */ new Set();
|
|
298
|
-
}
|
|
300
|
+
return new Set(Object.keys(readSkillsLock(cwd)).map(skillDirName));
|
|
299
301
|
}
|
|
300
302
|
/**
|
|
301
303
|
* A symlink into `node_modules`: how the `skills` CLI links a package skill, before its lock lists it.
|
|
@@ -328,17 +330,20 @@ function readUserEntries(cwd) {
|
|
|
328
330
|
function runSkillsCli(cwd, args, run) {
|
|
329
331
|
const manifestPath = createRequire(import.meta.url).resolve("skills/package.json");
|
|
330
332
|
const { bin } = JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
333
|
+
return runOrWarn(run, {
|
|
334
|
+
command: process.execPath,
|
|
335
|
+
args: [path.join(path.dirname(manifestPath), bin.skills), ...args],
|
|
336
|
+
options: {
|
|
337
|
+
cwd,
|
|
338
|
+
stdio: "inherit",
|
|
339
|
+
env: {
|
|
340
|
+
DISABLE_TELEMETRY: "1",
|
|
341
|
+
...process.env
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
label: `skills ${args[0]}`,
|
|
345
|
+
what: "skills"
|
|
338
346
|
});
|
|
339
|
-
if (result.status === 0) return true;
|
|
340
|
-
console.warn(`[lint-prepare] skills ${args[0]} failed (${result.error?.message ?? `exit code ${result.status}`}), skills may be missing: re-run lint-prepare`);
|
|
341
|
-
return false;
|
|
342
347
|
}
|
|
343
348
|
/**
|
|
344
349
|
* Install the skills that the dependencies of the root and of every workspace package ship (this package's own
|
|
@@ -358,11 +363,7 @@ const isNpmSkillSource = (source) => source.startsWith("@") || !source.includes(
|
|
|
358
363
|
* Names of the skills an installed npm package ships: `skills/<name>/SKILL.md` or `dist/skills/<name>/SKILL.md`.
|
|
359
364
|
*/
|
|
360
365
|
function readPackageSkills(cwd, packageName) {
|
|
361
|
-
return ["skills", path.join("dist", "skills")].flatMap((dir) =>
|
|
362
|
-
const root = path.join(cwd, "node_modules", packageName, dir);
|
|
363
|
-
if (!fs.existsSync(root)) return [];
|
|
364
|
-
return fs.readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && fs.existsSync(path.join(root, entry.name, "SKILL.md"))).map((entry) => entry.name);
|
|
365
|
-
});
|
|
366
|
+
return ["skills", path.join("dist", "skills")].flatMap((dir) => skillDirs(path.join(cwd, "node_modules", packageName, dir)));
|
|
366
367
|
}
|
|
367
368
|
/**
|
|
368
369
|
* Turn the `skills` map into CLI work. A skill gated by a package name is on when `hasDependency` says the workspace
|
|
@@ -419,8 +420,9 @@ function syncRemoteSkills(cwd, remote, run = spawnSync) {
|
|
|
419
420
|
if (process.env.CI) return;
|
|
420
421
|
const own = (entry) => entry.sourceType !== "node_modules" && !entry.via;
|
|
421
422
|
const fromSource = (lock, { source, ref }) => Object.keys(lock).filter((name) => own(lock[name]) && lock[name].source === source && lock[name].ref === ref);
|
|
423
|
+
let lock = readSkillsLock(cwd);
|
|
422
424
|
for (const wanted of remote) {
|
|
423
|
-
const installed = fromSource(
|
|
425
|
+
const installed = fromSource(lock, wanted);
|
|
424
426
|
if (wanted.skills === "*" ? installed.length > 0 : wanted.skills.every((name) => installed.includes(name))) continue;
|
|
425
427
|
const skills = wanted.skills === "*" ? ["*"] : wanted.skills;
|
|
426
428
|
runSkillsCli(cwd, [
|
|
@@ -431,8 +433,8 @@ function syncRemoteSkills(cwd, remote, run = spawnSync) {
|
|
|
431
433
|
"--skill",
|
|
432
434
|
...skills
|
|
433
435
|
], run);
|
|
436
|
+
lock = readSkillsLock(cwd);
|
|
434
437
|
}
|
|
435
|
-
const lock = readSkillsLock(cwd);
|
|
436
438
|
const kept = new Set(remote.flatMap((wanted) => fromSource(lock, wanted).filter((name) => wanted.skills === "*" ? !wanted.exclude.includes(name) : wanted.skills.includes(name))));
|
|
437
439
|
const stale = Object.keys(lock).filter((name) => own(lock[name]) && !kept.has(name));
|
|
438
440
|
if (stale.length) runSkillsCli(cwd, [
|
|
@@ -544,21 +546,21 @@ function symlinkClaudeMd(cwd) {
|
|
|
544
546
|
*
|
|
545
547
|
* The links are plain, never `@path` imports: Claude Code loads `.claude/rules` itself (syncAgentDirs() links them
|
|
546
548
|
* there) and honours each rule's `paths`, while an `@` import would load every rule into every session, scoped or not.
|
|
547
|
-
* Codex, which expands no `@`, reads this index. `
|
|
549
|
+
* Codex, which expands no `@`, reads this index. `toolSections` follow the sections of {@link TOOL_SECTIONS}.
|
|
548
550
|
*/
|
|
549
|
-
function generateAgentsFile(rules, customSection, previous = "",
|
|
551
|
+
function generateAgentsFile(rules, customSection, previous = "", toolSections = []) {
|
|
550
552
|
const entries = rules.map((rule) => {
|
|
551
553
|
const rulePath = `${CANONICAL_AGENT_DIR}/rules/${rule.file}`;
|
|
552
554
|
const description = rule.description ? ` — ${rule.description}` : "";
|
|
553
555
|
const scope = rule.paths ? `; when touching ${rule.paths.map((glob) => `\`${glob}\``).join(", ")}` : "";
|
|
554
556
|
return `- **${toTitle(rule.name)}**${description}${scope}: [${rulePath}](${rulePath})`;
|
|
555
557
|
});
|
|
556
|
-
const
|
|
557
|
-
|
|
558
|
-
const
|
|
559
|
-
|
|
558
|
+
const lines = previous.split(/\r?\n/);
|
|
559
|
+
const sections = [...TOOL_SECTIONS, ...toolSections].map(({ start, end, tail }) => {
|
|
560
|
+
const block = findBlock(lines, start, end);
|
|
561
|
+
const kept = block ? lines.slice(block[0], block[1] + 1).join("\n") : `${start}\n${end}`;
|
|
562
|
+
return tail ? `${kept}\n\n${tail}` : kept;
|
|
560
563
|
});
|
|
561
|
-
if (graphifySection) sections.push(graphifySection);
|
|
562
564
|
const generated = `${HEADER}\n\n# Rules\n\n${entries.join("\n")}\n\n${sections.join("\n\n")}\n\n${FOOTER}\n\n${GENERATED_MARKER}`;
|
|
563
565
|
return customSection ? `${generated}\n\n${customSection}\n` : `${generated}\n`;
|
|
564
566
|
}
|
|
@@ -614,14 +616,14 @@ async function main() {
|
|
|
614
616
|
const userEntries = readUserEntries(cwd);
|
|
615
617
|
syncAgentDirs(cwd, packageEntries(rules), userEntries);
|
|
616
618
|
console.log(`Synced ${AGENT_DIRS.join(", ")}, mirrored ${userEntries.size} own entries from ${CANONICAL_AGENT_DIR}`);
|
|
617
|
-
const {
|
|
619
|
+
const { detect } = detectionOf(config);
|
|
618
620
|
const plan = planSkills(config.skills ?? {}, (packageName) => readPackageSkills(cwd, packageName), detect ? (packageName) => workspaceDependsOn(packageName, root) : void 0);
|
|
619
621
|
if (runSkillsSync(cwd, spawnSync, plan.syncExclude)) console.log(`Synced skills with the skills CLI, see ${SKILLS_LOCK}`);
|
|
620
622
|
syncRemoteSkills(cwd, plan.remote);
|
|
621
623
|
recordSyncedSkills(cwd);
|
|
622
624
|
const previous = exists ? fs.readFileSync(targetPath, "utf-8") : "";
|
|
623
|
-
const
|
|
624
|
-
const content = generateAgentsFile(installedRules(rules, userEntries), customSection, previous,
|
|
625
|
+
const toolSections = graphify.mode === "venv" ? [GRAPHIFY_SECTION] : [];
|
|
626
|
+
const content = generateAgentsFile(installedRules(rules, userEntries), customSection, previous, toolSections);
|
|
625
627
|
fs.writeFileSync(targetPath, content, "utf-8");
|
|
626
628
|
console.log(`${exists ? "Updated" : "Created"} ${AGENTS_FILE}`);
|
|
627
629
|
symlinkClaudeMd(cwd);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SpawnSyncOptions } from "node:child_process";
|
|
2
|
+
//#region src/runCommand.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The part of `spawnSync` `lint-prepare` uses to run the tools it drives (the `skills` CLI, uv, graphify); tests pass a
|
|
5
|
+
* stand-in.
|
|
6
|
+
*/
|
|
7
|
+
export type RunCommand = (command: string, args: string[], options: SpawnSyncOptions) => {
|
|
8
|
+
status: number | null;
|
|
9
|
+
error?: Error;
|
|
10
|
+
};
|
|
11
|
+
/** A command `lint-prepare` runs, named in its warning by `label`; `what` may be incomplete when it fails. */
|
|
12
|
+
type ToolRun = {
|
|
13
|
+
command: string;
|
|
14
|
+
args: string[];
|
|
15
|
+
options: SpawnSyncOptions;
|
|
16
|
+
label: string;
|
|
17
|
+
what: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Run a tool `lint-prepare` drives. A failure is a warning, the install goes on. Returns whether the command succeeded.
|
|
21
|
+
*/
|
|
22
|
+
export declare function runOrWarn(run: RunCommand, { command, args, options, label, what }: ToolRun): boolean;
|
|
23
|
+
//#endregion
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/runCommand.ts
|
|
2
|
+
/**
|
|
3
|
+
* Run a tool `lint-prepare` drives. A failure is a warning, the install goes on. Returns whether the command succeeded.
|
|
4
|
+
*/
|
|
5
|
+
function runOrWarn(run, { command, args, options, label, what }) {
|
|
6
|
+
const result = run(command, args, options);
|
|
7
|
+
if (result.status === 0) return true;
|
|
8
|
+
console.warn(`[lint-prepare] ${label} failed (${result.error?.message ?? `exit code ${result.status}`}), ${what} may be incomplete: re-run lint-prepare`);
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { runOrWarn };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/textBlocks.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The line range of a marked block in `lines`: the first line that is exactly `start`, through the first line after it
|
|
4
|
+
* that is exactly `end`. Undefined when either is missing.
|
|
5
|
+
*/
|
|
6
|
+
export declare function findBlock(lines: string[], start: string, end: string): [from: number, to: number] | undefined;
|
|
7
|
+
//#endregion
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/textBlocks.ts
|
|
2
|
+
/**
|
|
3
|
+
* The line range of a marked block in `lines`: the first line that is exactly `start`, through the first line after it
|
|
4
|
+
* that is exactly `end`. Undefined when either is missing.
|
|
5
|
+
*/
|
|
6
|
+
function findBlock(lines, start, end) {
|
|
7
|
+
const from = lines.indexOf(start);
|
|
8
|
+
const to = from === -1 ? -1 : lines.indexOf(end, from + 1);
|
|
9
|
+
return to === -1 ? void 0 : [from, to];
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { findBlock };
|
package/dist/vitePlus.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { GLOBAL_IGNORES, asOptions, findWorkspaceRoot } from "./lib.js";
|
|
2
|
-
import {
|
|
1
|
+
import { GLOBAL_IGNORES, asOptions, detectionOf, findWorkspaceRoot } from "./lib.js";
|
|
2
|
+
import { markupExtsRaw, prettierExtsRaw, testFiles, tsExts, tsExtsRaw, tsFiles } from "./exts.js";
|
|
3
3
|
import { resolveLintConfig } from "./config.js";
|
|
4
|
-
import { defaultExportFiles, filenameCaseIgnore } from "./conventions.js";
|
|
4
|
+
import { coreRules, declarationFileRules, defaultExportFiles, filenameCaseIgnore, nextRules, promiseRules, reactRules, testRunnerRules, typescriptRules, vitestRules } from "./conventions.js";
|
|
5
5
|
import { jestGate, nextGate, nxGate, storybookGate, tailwindGate, turboGate } from "./gates.js";
|
|
6
|
+
import { prettier } from "./prettier.js";
|
|
6
7
|
import { dirname, relative } from "node:path";
|
|
7
8
|
import { fileURLToPath } from "node:url";
|
|
8
9
|
//#region src/vitePlus.ts
|
|
9
|
-
const TS_FILES = `**/*.${tsExts}`;
|
|
10
|
-
const TEST_FILES = `**/*.{test,spec}.${tsExts}`;
|
|
11
10
|
/**
|
|
12
11
|
* Type-aware `correctness` rules of Oxlint 1.88 that stay off when `typeAware` is on. Tried on this monorepo they
|
|
13
12
|
* reported mostly noise (`act()` with sync callbacks, `for await` over sync iterables, unions with `any`); the
|
|
@@ -26,6 +25,14 @@ const TYPE_AWARE_CORRECTNESS_OFF = [
|
|
|
26
25
|
function pluginPath(specifier) {
|
|
27
26
|
return fileURLToPath(import.meta.resolve(specifier));
|
|
28
27
|
}
|
|
28
|
+
const OXLINT_PREFIXES = [["@typescript-eslint/", "typescript/"], ["@next/next/", "nextjs/"]];
|
|
29
|
+
/** Rules by their ESLint names, renamed for Oxlint. */
|
|
30
|
+
function oxlintRules(rules) {
|
|
31
|
+
return Object.fromEntries(Object.entries(rules).map(([name, setting]) => {
|
|
32
|
+
const prefix = OXLINT_PREFIXES.find(([eslint]) => name.startsWith(eslint));
|
|
33
|
+
return [prefix ? prefix[1] + name.slice(prefix[0].length) : name, setting];
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
29
36
|
/** A workspace-root-relative glob for an absolute directory (Oxlint override globs resolve from the config file). */
|
|
30
37
|
function workspaceGlob(dir, glob) {
|
|
31
38
|
const rel = relative(findWorkspaceRoot(), dir).replaceAll("\\", "/");
|
|
@@ -42,14 +49,13 @@ function workspaceGlob(dir, glob) {
|
|
|
42
49
|
* import autofix.
|
|
43
50
|
*/
|
|
44
51
|
function lintConfig(options = {}) {
|
|
45
|
-
const {
|
|
46
|
-
const flag = (option) => option === void 0 && !defaultOn ? false : option;
|
|
52
|
+
const { strict, flag } = detectionOf(options);
|
|
47
53
|
const next = nextGate(flag(options.next), strict, { requirePackage: false });
|
|
48
54
|
const storybook = storybookGate(flag(options.storybook), strict);
|
|
49
55
|
const turbo = turboGate(flag(options.turbo));
|
|
50
56
|
const nx = nxGate(flag(options.nx), strict, { packageName: "eslint" });
|
|
51
57
|
const jest = jestGate(flag(options.jest), strict);
|
|
52
|
-
const vitest = asOptions(flag(options.vitest)).enabled ??
|
|
58
|
+
const vitest = asOptions(flag(options.vitest)).enabled ?? !jest.enabled;
|
|
53
59
|
const tailwind = tailwindGate(flag(options.tailwind), strict);
|
|
54
60
|
const { enabled: typeAware = true } = asOptions(options.vitePlus?.typeAware);
|
|
55
61
|
const nextRootDir = next.enabled ? next.options.rootDir ?? (next.files.length > 0 ? next.files.map(dirname) : void 0) : void 0;
|
|
@@ -64,18 +70,14 @@ function lintConfig(options = {}) {
|
|
|
64
70
|
const overrides = [
|
|
65
71
|
{
|
|
66
72
|
files: ["**/*.d.ts"],
|
|
67
|
-
rules:
|
|
68
|
-
prefer: "type-imports",
|
|
69
|
-
fixStyle: "inline-type-imports",
|
|
70
|
-
disallowTypeAnnotations: false
|
|
71
|
-
}] }
|
|
73
|
+
rules: oxlintRules(declarationFileRules)
|
|
72
74
|
},
|
|
73
75
|
{
|
|
74
76
|
files: defaultExportFiles,
|
|
75
77
|
rules: { "import/no-default-export": "off" }
|
|
76
78
|
},
|
|
77
79
|
{
|
|
78
|
-
files: [
|
|
80
|
+
files: [testFiles],
|
|
79
81
|
plugins: [...vitest ? ["vitest"] : [], ...jest.enabled ? ["jest"] : []],
|
|
80
82
|
env: {
|
|
81
83
|
...vitest ? { vitest: true } : {},
|
|
@@ -83,21 +85,12 @@ function lintConfig(options = {}) {
|
|
|
83
85
|
},
|
|
84
86
|
rules: {
|
|
85
87
|
"local/test-colocation": "error",
|
|
86
|
-
...vitest ? {
|
|
87
|
-
"vitest
|
|
88
|
-
"vitest/no-disabled-tests": "warn",
|
|
88
|
+
...vitest ? oxlintRules({
|
|
89
|
+
...testRunnerRules("vitest"),
|
|
89
90
|
"vitest/require-mock-type-parameters": "off",
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
"expectTypeOf",
|
|
94
|
-
"assertType"
|
|
95
|
-
] }]
|
|
96
|
-
} : {},
|
|
97
|
-
...jest.enabled ? {
|
|
98
|
-
"jest/consistent-test-it": ["error", { fn: "test" }],
|
|
99
|
-
"jest/no-disabled-tests": "warn"
|
|
100
|
-
} : {}
|
|
91
|
+
...vitestRules
|
|
92
|
+
}) : {},
|
|
93
|
+
...jest.enabled ? oxlintRules(testRunnerRules("jest")) : {}
|
|
101
94
|
}
|
|
102
95
|
}
|
|
103
96
|
];
|
|
@@ -133,7 +126,7 @@ function lintConfig(options = {}) {
|
|
|
133
126
|
});
|
|
134
127
|
}
|
|
135
128
|
if (tailwind) overrides.push({
|
|
136
|
-
files: [tailwind.packageDir ? workspaceGlob(tailwind.packageDir,
|
|
129
|
+
files: [tailwind.packageDir ? workspaceGlob(tailwind.packageDir, tsFiles) : tsFiles],
|
|
137
130
|
jsPlugins: [{
|
|
138
131
|
name: "tailwindcss",
|
|
139
132
|
specifier: pluginPath("eslint-plugin-tailwindcss")
|
|
@@ -149,7 +142,7 @@ function lintConfig(options = {}) {
|
|
|
149
142
|
}
|
|
150
143
|
});
|
|
151
144
|
if (turbo.enabled) overrides.push({
|
|
152
|
-
files: [
|
|
145
|
+
files: [tsFiles],
|
|
153
146
|
jsPlugins: [{
|
|
154
147
|
name: "turbo",
|
|
155
148
|
specifier: pluginPath("eslint-plugin-turbo")
|
|
@@ -186,10 +179,7 @@ function lintConfig(options = {}) {
|
|
|
186
179
|
typeCheck: true
|
|
187
180
|
} } : {},
|
|
188
181
|
rules: {
|
|
189
|
-
|
|
190
|
-
name: "next/router",
|
|
191
|
-
message: "Please use next/navigation instead of next/router"
|
|
192
|
-
}] }],
|
|
182
|
+
...oxlintRules(coreRules),
|
|
193
183
|
"no-unused-vars": ["error", {
|
|
194
184
|
args: "none",
|
|
195
185
|
caughtErrors: "none",
|
|
@@ -206,22 +196,7 @@ function lintConfig(options = {}) {
|
|
|
206
196
|
"unicorn/no-empty-file": "off",
|
|
207
197
|
"jsx-a11y/prefer-tag-over-role": "off",
|
|
208
198
|
"typescript/no-useless-empty-export": "off",
|
|
209
|
-
|
|
210
|
-
"typescript/consistent-type-imports": ["error", {
|
|
211
|
-
prefer: "type-imports",
|
|
212
|
-
fixStyle: "inline-type-imports"
|
|
213
|
-
}],
|
|
214
|
-
"typescript/ban-ts-comment": ["error", {
|
|
215
|
-
"ts-expect-error": "allow-with-description",
|
|
216
|
-
"ts-ignore": true,
|
|
217
|
-
"ts-nocheck": true,
|
|
218
|
-
"ts-check": false,
|
|
219
|
-
minimumDescriptionLength: 3
|
|
220
|
-
}],
|
|
221
|
-
"typescript/prefer-as-const": "error",
|
|
222
|
-
"typescript/no-explicit-any": "off",
|
|
223
|
-
"typescript/no-empty-function": "off",
|
|
224
|
-
"typescript/no-require-imports": "off",
|
|
199
|
+
...oxlintRules(typescriptRules),
|
|
225
200
|
...typeAware ? {
|
|
226
201
|
"typescript/prefer-optional-chain": "warn",
|
|
227
202
|
"typescript/prefer-nullish-coalescing": "warn",
|
|
@@ -243,17 +218,10 @@ function lintConfig(options = {}) {
|
|
|
243
218
|
"react/set-state-in-render": "error",
|
|
244
219
|
"react/unsupported-syntax": "warn",
|
|
245
220
|
"react/react-in-jsx-scope": "off",
|
|
246
|
-
|
|
247
|
-
...next.enabled ? {
|
|
248
|
-
"nextjs/no-html-link-for-pages": "off",
|
|
249
|
-
"nextjs/no-img-element": "off"
|
|
250
|
-
} : {},
|
|
251
|
-
"import/no-anonymous-default-export": "off",
|
|
221
|
+
...oxlintRules(reactRules),
|
|
222
|
+
...next.enabled ? oxlintRules(nextRules) : {},
|
|
252
223
|
"import/no-default-export": "warn",
|
|
253
|
-
|
|
254
|
-
"promise/param-names": "off",
|
|
255
|
-
"promise/always-return": "off",
|
|
256
|
-
"promise/catch-or-return": "off",
|
|
224
|
+
...oxlintRules(promiseRules),
|
|
257
225
|
"unicorn/filename-case": ["error", {
|
|
258
226
|
case: "camelCase",
|
|
259
227
|
ignore: filenameCaseIgnore.map((regex) => regex.source)
|
|
@@ -272,11 +240,9 @@ function lintConfig(options = {}) {
|
|
|
272
240
|
* Markdown gets 200 columns; a wider table is HTML, or stays unaligned when it is mostly code (rules/markdown.md).
|
|
273
241
|
*/
|
|
274
242
|
function fmtConfig() {
|
|
243
|
+
const { overrides: prettierOverrides = [], ...prettierOptions } = prettier;
|
|
275
244
|
return {
|
|
276
|
-
|
|
277
|
-
tabWidth: 2,
|
|
278
|
-
singleQuote: true,
|
|
279
|
-
proseWrap: "never",
|
|
245
|
+
...prettierOptions,
|
|
280
246
|
insertFinalNewline: true,
|
|
281
247
|
sortPackageJson: false,
|
|
282
248
|
ignorePatterns: [
|
|
@@ -332,10 +298,10 @@ function fmtConfig() {
|
|
|
332
298
|
"unknown"
|
|
333
299
|
]
|
|
334
300
|
},
|
|
335
|
-
overrides: [{
|
|
336
|
-
files: [`**/${
|
|
337
|
-
options
|
|
338
|
-
}, {
|
|
301
|
+
overrides: [...prettierOverrides.map(({ files, options }) => ({
|
|
302
|
+
files: [files].flat().map((glob) => `**/${glob}`),
|
|
303
|
+
options
|
|
304
|
+
})), {
|
|
339
305
|
files: ["**/*.{md,mdx}"],
|
|
340
306
|
options: {
|
|
341
307
|
sortImports: false,
|