Skip to content

Commit 03261a1

Browse files
pranavcodeantclaude
andcommitted
Apply CodeAnt review fixes for PR #13
- Fix NaN sort comparator in listRepos when pushed_at is missing - Preserve multi-line file_line_range in fetchAdvancedScanResults - Add item.check_name to dead-code normalization fallback chain - Fix confidence_score type error with String() coercion before toLowerCase - Strip all scan-result suffixes in fetchDismissedAlerts (not just security_issues) - Add optional chaining on dismissInfo to prevent null crash - Fall back to input repo param when backend omits it in getScanHistory - Add dismissed-finding display fallbacks in ScanCenter - Use full_name || name fallback in handleSelectRepo to avoid undefined API call - Gate debug stderr logging behind CODEANT_DEBUG_SCAN_HISTORY=1 - Guard paginate offset/limit against NaN with Number.isFinite - Fix dismissMatch line-number comparison with null check and Number() coercion Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 1c4fee3 commit 03261a1

8 files changed

Lines changed: 21 additions & 17 deletions

File tree

‎src/commands/scans/lib/dismissMatch.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function findDismissMatch(finding, dismissedAlerts) {
2020
if (d.test_id && finding.check_id && d.test_id !== finding.check_id) continue;
2121

2222
// Line number match when available (secrets format uses line_number as part1)
23-
if (d.line_number && finding.line_number && d.line_number !== finding.line_number) continue;
23+
if (d.line_number != null && finding.line_number != null && Number(d.line_number) !== Number(finding.line_number)) continue;
2424

2525
return d;
2626
}

‎src/commands/scans/lib/paginate.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
*/
77
export function paginate(findings, { limit = 100, offset = 0 } = {}) {
88
const total = findings.length;
9-
const safeOffset = Math.max(0, offset);
10-
const safeLimit = limit > 0 ? limit : total;
9+
const safeOffset = Number.isFinite(offset) ? Math.max(0, Math.trunc(offset)) : 0;
10+
const safeLimit = Number.isFinite(limit) && limit > 0 ? Math.trunc(limit) : 100;
1111
const items = findings.slice(safeOffset, safeOffset + safeLimit);
1212
return {
1313
items,

‎src/components/ScanCenter.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function ResultsView({ issues, resultTypeLabel, breadcrumbParts, onBack }) {
112112
ce(Text, { color: 'gray' },
113113
(issue.file_path || 'unknown') + (issue.line_number ? `:${issue.line_number}` : '')),
114114
ce(Text, null,
115-
issue.check_name || issue.issue_text || issue.message || '')
115+
issue.check_name || issue.issue_text || issue.message || issue.test_id || issue.type || issue.reason_for_dismiss || 'Dismissed finding')
116116
)
117117
),
118118
];

‎src/scanCenter/handleSelectRepo.js‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ import { getScanHistory } from '../scans/getScanHistory.js';
33
export async function handleSelectRepo({ STEPS, item, setSelectedRepo, setStep, setLoadingMsg, setError, setScanHistory }) {
44
setSelectedRepo(item.value);
55
setStep(STEPS.LOADING);
6-
setLoadingMsg(`Loading scan history for ${item.value.full_name}…`);
7-
const res = await getScanHistory(item.value.full_name);
6+
const repoFullName = item.value.full_name || item.value.name;
7+
setLoadingMsg(`Loading scan history for ${repoFullName}…`);
8+
const res = await getScanHistory(repoFullName);
89
if (!res.success) {
910
setError(res.error || 'Failed to fetch scan history', STEPS.SELECT_REPO);
1011
return;
1112
}
1213
const history = res.scanHistory || [];
13-
process.stderr.write('SCAN_HISTORY_SAMPLE: ' + JSON.stringify(history.slice(0, 15), null, 2) + '\n');
14+
if (process.env.CODEANT_DEBUG_SCAN_HISTORY === '1') {
15+
process.stderr.write('SCAN_HISTORY_SAMPLE: ' + JSON.stringify(history.slice(0, 15), null, 2) + '\n');
16+
}
1417
setScanHistory(history);
1518
setStep(STEPS.SELECT_SCAN);
1619
}

‎src/scans/fetchAdvancedScanResults.js‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ function normalizeAdvancedIssue(item, resultType) {
152152
const normalized = { ...item };
153153
normalized.file_path = extractRelativeFilePath(item.file_path || item.path || item.filename || 'unknown');
154154
normalized.line_number = item.line_number || item.start_line || item.line || 1;
155-
normalized.file_line_range = [normalized.line_number];
155+
normalized.file_line_range =
156+
Array.isArray(item.file_line_range) && item.file_line_range.length > 0
157+
? item.file_line_range
158+
: [normalized.line_number];
156159

157160
switch (resultType) {
158161
case ADVANCED_RESULT_TYPES.SCA:
@@ -181,7 +184,7 @@ function normalizeAdvancedIssue(item, resultType) {
181184
break;
182185
case ADVANCED_RESULT_TYPES.DEAD_CODE:
183186
normalized.check_name =
184-
item.name || item.function_name || item.symbol_name || item.description || 'Unused code detected';
187+
item.check_name || item.name || item.function_name || item.symbol_name || item.description || 'Unused code detected';
185188
normalized.severity = item.severity || 'low';
186189
break;
187190
default:
@@ -293,7 +296,7 @@ export async function fetchAdvancedScanResults(repo, commitId, resultType) {
293296

294297
// Filter secrets false positives
295298
if (resultType === ADVANCED_RESULT_TYPES.SECRETS) {
296-
issues = issues.filter((issue) => issue.confidence_score?.toLowerCase() !== 'false_positive');
299+
issues = issues.filter((issue) => String(issue.confidence_score || '').toLowerCase() !== 'false_positive');
297300
}
298301

299302
if (resultType === ADVANCED_RESULT_TYPES.SCA) {

‎src/scans/fetchDismissedAlerts.js‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ export async function fetchDismissedAlerts(repo, analysisType = 'security') {
3636
const part1 = parts[1] || '';
3737
const part2 = parts[2] || '';
3838

39-
if (file_path.endsWith('/security_issues.json')) {
40-
file_path = file_path.replace('/security_issues.json', '');
41-
}
39+
file_path = file_path.replace(/\/(security_issues|anti_patterns|docstring|complex_functions)\.json$/, '');
4240

4341
dismissedAlerts.push({
4442
file_path,
@@ -47,8 +45,8 @@ export async function fetchDismissedAlerts(repo, analysisType = 'security') {
4745
line_number: parseInt(part1, 10) || 0,
4846
type: part2,
4947
issue_key: issueKey,
50-
reason_for_dismiss: dismissInfo.reason_for_dismiss || '',
51-
comment_for_dismiss: dismissInfo.comment_for_dismiss || '',
48+
reason_for_dismiss: dismissInfo?.reason_for_dismiss || '',
49+
comment_for_dismiss: dismissInfo?.comment_for_dismiss || '',
5250
});
5351
}
5452

‎src/scans/getScanHistory.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export async function getScanHistory(repo) {
2222
if (response.last_analysis_results !== undefined) {
2323
return {
2424
success: true,
25-
repo: response.repo,
25+
repo: response.repo || repo,
2626
scanHistory: response.last_analysis_results || [],
2727
};
2828
}

‎src/scans/listRepos.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export async function listRepos(organizationName) {
2222

2323
if (response.repos) {
2424
const sortedRepos = (response.repos || []).sort(
25-
(a, b) => new Date(b.pushed_at) - new Date(a.pushed_at)
25+
(a, b) => (Date.parse(b.pushed_at) || 0) - (Date.parse(a.pushed_at) || 0)
2626
);
2727
return { success: true, repos: sortedRepos };
2828
}

0 commit comments

Comments
 (0)