Replace ESLint with oxlint and add code quality tooling

- Replace ESLint/typescript-eslint with oxlint (faster, zero-config TypeScript linting)
- Add oxlint config with complexity thresholds, max-lines, and TypeScript rules
- Add jscpd for duplicate code detection
- Add knip for dead code and unused dependency detection
- Add scripts/scan-todos.mjs for tech debt marker scanning
- Add Husky pre-commit hook running oxlint on staged files
- Fix unnecessary array spreads flagged by oxlint
This commit is contained in:
morluto 2026-07-12 10:14:37 +08:00
parent ff0cbf9ee2
commit 8a62075a8e
10 changed files with 1625 additions and 1217 deletions

1
.husky/pre-commit Executable file
View File

@ -0,0 +1 @@
npx oxlint --fix

16
.jscpd.json Normal file
View File

@ -0,0 +1,16 @@
{
"threshold": 3,
"reporters": ["consoleFull"],
"ignore": [
"node_modules/**",
"dist/**",
"docs/**",
".codex/**",
".devin/**",
"**/*.test.ts",
"tests/fixtures/**"
],
"gitignore": true,
"minLines": 5,
"minTokens": 50
}

33
.oxlintrc.json Normal file
View File

@ -0,0 +1,33 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"plugins": ["typescript", "import", "unicorn", "oxc"],
"rules": {
"complexity": ["warn", 20],
"max-depth": ["warn", 4],
"max-lines": [
"warn",
{ "max": 500, "skipBlankLines": true, "skipComments": true }
],
"max-lines-per-function": [
"warn",
{ "max": 100, "skipBlankLines": true, "skipComments": true }
],
"max-params": ["warn", 4],
"no-var": "warn",
"no-var-requires": "error"
},
"overrides": [
{
"files": ["tests/**/*.ts"],
"rules": {
"max-lines-per-function": "off",
"max-lines": "off"
}
}
],
"env": {
"node": true,
"es2023": true
},
"ignorePatterns": ["dist", "node_modules", "docs/api", ".codex", ".devin"]
}

View File

@ -1,3 +1,4 @@
dist
docs/api
node_modules
package-lock.json

19
knip.json Normal file
View File

@ -0,0 +1,19 @@
{
"$schema": "./node_modules/knip/schema.json",
"entry": ["src/main.ts", "src/cli.ts", "scripts/rea.mjs", "scripts/scan-todos.mjs"],
"project": ["src/**/*.ts", "tests/**/*.ts", "scripts/**/*.mjs", "vitest.config.ts"],
"ignore": ["dist/**", "docs/**", ".codex/**", ".devin/**"],
"ignoreDependencies": [],
"rules": {
"files": "warn",
"dependencies": "warn",
"devDependencies": "warn",
"unlisted": "error",
"exports": "warn",
"nsExports": "warn",
"types": "warn",
"nsTypes": "warn",
"enumMembers": "warn",
"duplicates": "error"
}
}

2698
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -41,7 +41,11 @@
"check": "npm run typecheck && npm run lint && npm run format:check && npm test",
"format": "prettier --write .",
"format:check": "prettier --check .",
"lint": "eslint 'src/**/*.ts' 'tests/**/*.ts' vitest.config.ts",
"lint": "oxlint",
"lint:fix": "oxlint --fix",
"knip": "knip",
"jscpd": "jscpd src/ tests/",
"scan:todos": "node scripts/scan-todos.mjs",
"start": "node dist/main.js",
"pretest": "npm run build",
"test": "vitest run",
@ -50,7 +54,9 @@
"verify:hopper": "npm run build && node scripts/verify-real-hopper.mjs",
"verify:package": "npm run build && node scripts/verify-package.mjs",
"config:print": "node scripts/print-mcp-config.mjs",
"prepack": "npm run build"
"docs:generate": "typedoc",
"prepack": "npm run build",
"prepare": "husky"
},
"dependencies": {
"@modelcontextprotocol/server": "2.0.0-beta.3",
@ -58,13 +64,15 @@
"zod": "4.4.3"
},
"devDependencies": {
"@eslint/js": "9.39.2",
"@modelcontextprotocol/client": "2.0.0-beta.3",
"@types/node": "24.10.1",
"eslint": "9.39.2",
"husky": "9.1.7",
"jscpd": "5.0.12",
"knip": "6.26.0",
"oxlint": "1.73.0",
"prettier": "3.6.2",
"typedoc": "0.28.20",
"typescript": "5.9.3",
"typescript-eslint": "8.48.1",
"vitest": "4.1.10"
}
}

52
scripts/scan-todos.mjs Normal file
View File

@ -0,0 +1,52 @@
#!/usr/bin/env node
import { readFileSync } from "node:fs";
import { globSync } from "node:fs";
import { relative, resolve } from "node:path";
const root = resolve(import.meta.dirname, "..");
// Collect all TS, MJS, and Python source files, excluding generated and third-party dirs.
const sourceFiles = [
...globSync("src/**/*.ts", {
cwd: root,
nodir: true,
ignore: ["dist/**", "node_modules/**"],
}),
...globSync("tests/**/*.ts", {
cwd: root,
nodir: true,
ignore: ["node_modules/**"],
}),
...globSync("scripts/**/*.mjs", { cwd: root, nodir: true }),
...globSync("bridge/**/*.py", { cwd: root, nodir: true }),
];
const patterns = [
{ regex: /TODO(?::\s*(.*))?$/gm, label: "TODO" },
{ regex: /FIXME(?::\s*(.*))?$/gm, label: "FIXME" },
{ regex: /HACK(?::\s*(.*))?$/gm, label: "HACK" },
];
let count = 0;
for (const file of sourceFiles) {
const content = readFileSync(resolve(root, file), "utf-8");
for (const { regex, label } of patterns) {
for (const match of content.matchAll(regex)) {
const comment = (match[1] ?? "").trim();
const line = content.slice(0, match.index).split("\n").length;
console.log(
`${relative(root, resolve(root, file))}:${line}: ${label}${comment ? ` - ${comment}` : ""}`,
);
count++;
}
}
}
if (count > 0) {
console.log(`\n${count} tech-debt marker(s) found.`);
process.exitCode = 0;
} else {
console.log("No tech-debt markers found.");
}

View File

@ -133,7 +133,7 @@ export class BinarySession implements HopperToolPort {
}
async #drainCalls(): Promise<void> {
await Promise.allSettled([...this.#calls]);
await Promise.allSettled(this.#calls);
}
async #restore(

View File

@ -338,7 +338,7 @@ export class HopperClient {
}
#failAll(error: HopperError): void {
for (const id of [...this.#pending.keys()]) this.#settle(id, err(error));
for (const id of this.#pending.keys()) this.#settle(id, err(error));
}
}