Skip to content

Commit 9e00f78

Browse files
chore: standardize error handling, add .editorconfig, enhance ESLint rules, and expand test coverage
- Fix 13 untyped catch blocks to use catch (error: unknown) pattern - Add .editorconfig for cross-IDE consistency - Add prefer-const and no-floating-promises ESLint rules - Fix 3 ESLint violations (let->const in agent.ts/formatter.ts, void in watch.ts) - Add 174 new tests across 9 test files: utils, api, lib, analysis, analysis-orchestration, config-resolution, server, templates, plugin-api Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6a21994 commit 9e00f78

19 files changed

+1978
-17
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[Makefile]
15+
indent_style = tab

eslint.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default [
1515
parserOptions: {
1616
ecmaVersion: "latest",
1717
sourceType: "module",
18+
project: "./tsconfig.json",
1819
},
1920
},
2021
plugins: {
@@ -29,6 +30,8 @@ export default [
2930
// Allow flexibility for small CLIs; keep TS strictness handled by tsc.
3031
"@typescript-eslint/no-explicit-any": "warn",
3132
"@typescript-eslint/no-unused-vars": "error",
33+
"@typescript-eslint/no-floating-promises": "error",
34+
"prefer-const": "error",
3235
},
3336
},
3437

src/agent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ No markdown, no explanations, just the JSON object starting with { and ending wi
10791079
}
10801080

10811081
// Cast to RepoFacts (ValidatedRepoFacts is compatible)
1082-
let facts = result.facts as unknown as RepoFacts;
1082+
const facts = result.facts as unknown as RepoFacts;
10831083

10841084
// Merge with detected stack info (trust deterministic detection)
10851085
facts.stack = {

src/commands/docs-command.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export async function runDocsCommand(
2222
}
2323
repoSource = await resolveRepo(repoUrl, process.cwd(), opts.branch || undefined);
2424
console.log(chalk.dim(`Analyzing: ${repoSource.repoInfo.fullName}`));
25-
} catch (error) {
26-
console.error(chalk.red(`❌ Failed to resolve repository: ${error}`));
25+
} catch (error: unknown) {
26+
console.error(chalk.red(`❌ Failed to resolve repository: ${error instanceof Error ? error.message : String(error)}`));
2727
process.exit(1);
2828
}
2929

src/deps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ async function extractNpmDependencies(repoPath: string): Promise<DependencyAnaly
115115
peer,
116116
categories,
117117
};
118-
} catch (err) {
118+
} catch (err: unknown) {
119119
console.debug?.(`npm dep extraction skipped: ${err instanceof Error ? err.message : err}`);
120120
return null;
121121
}
@@ -172,7 +172,7 @@ async function extractCargoDependencies(repoPath: string): Promise<DependencyAna
172172
peer: [],
173173
categories: [],
174174
};
175-
} catch (err) {
175+
} catch (err: unknown) {
176176
console.debug?.(`Cargo dep extraction skipped: ${err instanceof Error ? err.message : err}`);
177177
return null;
178178
}

src/diff.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async function getPackageJsonAtRef(
4141
{ cwd: repoPath }
4242
);
4343
return JSON.parse(stdout);
44-
} catch (err) {
44+
} catch (err: unknown) {
4545
console.debug?.(`package.json not available at ref ${ref}: ${err instanceof Error ? err.message : err}`);
4646
return {};
4747
}
@@ -108,7 +108,7 @@ async function getFileDiff(
108108
{ cwd: repoPath, maxBuffer: FILE_DIFF_MAX_BUFFER }
109109
);
110110
return stdout;
111-
} catch (err) {
111+
} catch (err: unknown) {
112112
console.debug?.(`git diff failed for ${filePath}: ${err instanceof Error ? err.message : err}`);
113113
return "";
114114
}
@@ -145,7 +145,7 @@ function extractDependencyChanges(
145145
for (const dep of baseDeps) {
146146
if (!headDeps.has(dep)) removed.push(dep);
147147
}
148-
} catch (err) {
148+
} catch (err: unknown) {
149149
console.debug?.(`Dependency comparison failed: ${err instanceof Error ? err.message : err}`);
150150
}
151151

@@ -173,7 +173,7 @@ async function extractEnvVarChanges(
173173
envFiles.map(async (file) => {
174174
try {
175175
return await getFileDiff(repoPath, baseRef, headRef, file);
176-
} catch (err) {
176+
} catch (err: unknown) {
177177
console.debug?.(`Env scan diff failed for ${file}: ${err instanceof Error ? err.message : err}`);
178178
return null;
179179
}
@@ -204,7 +204,7 @@ async function extractEnvVarChanges(
204204
codeFiles.slice(0, MAX_CODE_FILES_FOR_ENV_SCAN).map(async (file) => {
205205
try {
206206
return await getFileDiff(repoPath, baseRef, headRef, file);
207-
} catch (err) {
207+
} catch (err: unknown) {
208208
console.debug?.(`Code env scan failed for ${file}: ${err instanceof Error ? err.message : err}`);
209209
return null;
210210
}
@@ -250,7 +250,7 @@ function extractCommandChanges(
250250
newCommands.push(`npm run ${name}`);
251251
}
252252
}
253-
} catch (err) {
253+
} catch (err: unknown) {
254254
console.debug?.(`Command extraction failed: ${err instanceof Error ? err.message : err}`);
255255
}
256256

@@ -290,7 +290,7 @@ async function detectBreakingChanges(
290290
breakingChanges.push(`Major version bump: ${baseVersion}${headVersion}`);
291291
}
292292
}
293-
} catch (err) {
293+
} catch (err: unknown) {
294294
console.debug?.(`Version comparison failed: ${err instanceof Error ? err.message : err}`);
295295
}
296296

@@ -314,7 +314,7 @@ async function detectBreakingChanges(
314314
breakingChanges.push(`Removed export: ${match[1]} in ${file}`);
315315
}
316316
}
317-
} catch (err) {
317+
} catch (err: unknown) {
318318
console.debug?.(`Export removal check failed for ${file}: ${err instanceof Error ? err.message : err}`);
319319
}
320320
}

src/formatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function convertInlineFormatting(line: string): string {
6969
export function markdownToHtml(md: string): string {
7070
// Pull out code blocks so they aren't processed line-by-line
7171
const codeBlockPlaceholders: string[] = [];
72-
let processed = md.replace(/```(\w*)\n([\s\S]*?)```/g, (match) => {
72+
const processed = md.replace(/```(\w*)\n([\s\S]*?)```/g, (match) => {
7373
const idx = codeBlockPlaceholders.length;
7474
codeBlockPlaceholders.push(convertCodeBlocks(match));
7575
return `\x00CODEBLOCK_${idx}\x00`;

src/interactive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ export async function quickAsk(
391391
const answer = await session.ask(question);
392392
await session.stop();
393393
return answer;
394-
} catch (error) {
394+
} catch (error: unknown) {
395395
await session.stop();
396396
throw error;
397397
}

src/watch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export function startWatch(
164164
const triggerCheck = () => {
165165
if (!running && !stopped) {
166166
log("Local git ref change detected, checking...");
167-
check();
167+
void check();
168168
}
169169
};
170170

src/web/templates.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ export function getIndexHtml(): string {
223223
currentJobId = jobId;
224224
streamProgress(jobId);
225225
} catch (err) {
226-
addProgressItem(err.message, 'error');
226+
addProgressItem(err instanceof Error ? err.message : String(err), 'error');
227227
btn.disabled = false;
228228
btn.textContent = 'Analyze';
229229
}

0 commit comments

Comments
 (0)