Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 9x 9x 10x 10x 1x 1x 1x 1x 1x 10x 10x 10x 8x 1x 1x 10x | import { Severity, IssueType, SignalContext, SignalResult } from './types';
import { isAmbiguousName } from '../helpers';
import type { ParseResult } from '@aiready/core';
import {
LINE_THRESHOLD_CRITICAL,
LINE_THRESHOLD_MAJOR,
CATEGORY_LARGE_FILE,
CATEGORY_UNDOCUMENTED_EXPORT,
CATEGORY_IMPLICIT_SIDE_EFFECT,
CATEGORY_AMBIGUOUS_NAME,
CATEGORY_OVERLOADED_SYMBOL,
IGNORE_EXPORTS,
MSG_EXTREME_FILE,
MSG_LARGE_FILE,
SUGGESTION_SPLIT_FILE,
SUGGESTION_REFACTOR_FILE,
} from './constants';
/**
* Checks for signals in exported symbols and general file properties.
*/
export function detectExportSignals(
ctx: SignalContext,
parseResult: ParseResult
): SignalResult {
const issues: any[] = [];
const signals = {
largeFiles: 0,
undocumentedExports: 0,
implicitSideEffects: 0,
ambiguousNames: 0,
overloadedSymbols: 0,
};
const { filePath, lineCount, options } = ctx;
// 0. Check File Size (Large Files)
Eif (options.checkLargeFiles !== false) {
Iif (lineCount > LINE_THRESHOLD_CRITICAL) {
signals.largeFiles++;
issues.push({
type: IssueType.AiSignalClarity,
category: CATEGORY_LARGE_FILE,
severity: Severity.Critical,
message: MSG_EXTREME_FILE(lineCount),
location: { file: filePath, line: 1 },
suggestion: SUGGESTION_SPLIT_FILE,
});
I} else if (lineCount > LINE_THRESHOLD_MAJOR) {
signals.largeFiles++;
issues.push({
type: IssueType.AiSignalClarity,
category: CATEGORY_LARGE_FILE,
severity: Severity.Major,
message: MSG_LARGE_FILE(lineCount),
location: { file: filePath, line: 1 },
suggestion: SUGGESTION_REFACTOR_FILE,
});
}
}
// Symbol tracking for overloading detection
const symbolCounts = new Map<string, number>();
for (const exp of parseResult.exports) {
// Overload tracking
symbolCounts.set(exp.name, (symbolCounts.get(exp.name) || 0) + 1);
// Undocumented Exports
Eif (options.checkUndocumentedExports !== false) {
if (!exp.documentation || !exp.documentation.content) {
signals.undocumentedExports++;
issues.push({
type: IssueType.AiSignalClarity,
category: CATEGORY_UNDOCUMENTED_EXPORT,
severity: Severity.Minor,
message: `Public export "${exp.name}" has no documentation — AI fabricates behavior from the name alone.`,
location: {
file: filePath,
line: exp.loc?.start.line || 1,
column: exp.loc?.start.column,
},
suggestion:
'Add a docstring or comment describing parameters, return value, and side effects.',
});
}
}
// Implicit Side Effects
Eif (options.checkImplicitSideEffects !== false) {
if (exp.hasSideEffects && !exp.isPure && exp.type === 'function') {
const lowerName = exp.name.toLowerCase();
const looksPure =
!/(set|update|save|delete|create|write|send|post|sync)/.test(
lowerName
);
Eif (looksPure) {
signals.implicitSideEffects++;
issues.push({
type: IssueType.AiSignalClarity,
category: CATEGORY_IMPLICIT_SIDE_EFFECT,
severity: Severity.Major,
message: `Function "${exp.name}" mutates external state but name doesn't reflect it — AI misses this contract.`,
location: {
file: filePath,
line: exp.loc?.start.line || 1,
},
suggestion:
'Make side-effects explicit in function name (e.g., updateX) or return a result.',
});
}
}
}
// Ambiguous Names for Exports
Iif (
options.checkAmbiguousNames !== false &&
!IGNORE_EXPORTS.includes(exp.name) &&
isAmbiguousName(exp.name)
) {
signals.ambiguousNames++;
issues.push({
type: IssueType.AmbiguousApi,
category: CATEGORY_AMBIGUOUS_NAME,
severity: Severity.Info,
message: `Ambiguous public export "${exp.name}" — AI cannot infer intent and will guess incorrectly.`,
location: {
file: filePath,
line: exp.loc?.start.line || 1,
},
suggestion: 'Use a domain-descriptive name instead.',
});
}
}
// Report Overloads
Eif (options.checkOverloadedSymbols !== false) {
for (const [name, count] of symbolCounts.entries()) {
if (count > 1 && !IGNORE_EXPORTS.includes(name)) {
signals.overloadedSymbols++;
issues.push({
type: IssueType.AiSignalClarity,
category: CATEGORY_OVERLOADED_SYMBOL,
severity: Severity.Critical,
message: `Symbol "${name}" has ${count} overloaded signatures — AI often picks the wrong one or gets confused by conflicting contracts.`,
location: {
file: filePath,
line: 1,
},
suggestion: `Rename overloads to unique, descriptive names if possible.`,
});
}
}
}
return { issues, signals };
}
|