Improve compiler output for line validation
This commit improves feedback when a line is too long to enhance developer/maintainer productivity. - Trim long lines in output to 500 characters - Show character count exceeding max line length - Refactor line formatting for better readability
This commit is contained in:
@@ -12,7 +12,7 @@ export const analyzeTooLongLines: CodeValidationAnalyzer = (
|
||||
lineNumber: line.lineNumber,
|
||||
error: [
|
||||
`Line is too long (${line.text.length}).`,
|
||||
`It exceed maximum allowed length ${maxLineLength}.`,
|
||||
`It exceed maximum allowed length ${maxLineLength} by ${line.text.length - maxLineLength} characters.`,
|
||||
'This may cause bugs due to unintended trimming by operating system, shells or terminal emulators.',
|
||||
].join(' '),
|
||||
}));
|
||||
@@ -39,6 +39,6 @@ function getMaxAllowedLineLength(language: ScriptingLanguage): number {
|
||||
*/
|
||||
return 1048576; // Minimum value for reliability
|
||||
default:
|
||||
throw new Error(`Unsupported language: ${language}`);
|
||||
throw new Error(`Unsupported language: ${ScriptingLanguage[language]} (${language})`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,9 +46,33 @@ function formatLines(
|
||||
): string {
|
||||
return lines.map((line) => {
|
||||
const badLine = invalidLines.find((invalidLine) => invalidLine.lineNumber === line.lineNumber);
|
||||
if (!badLine) {
|
||||
return `[${line.lineNumber}] ✅ ${line.text}`;
|
||||
}
|
||||
return `[${badLine.lineNumber}] ❌ ${line.text}\n\t⟶ ${badLine.error}`;
|
||||
return formatLine({
|
||||
lineNumber: line.lineNumber,
|
||||
text: line.text,
|
||||
error: badLine?.error,
|
||||
});
|
||||
}).join('\n');
|
||||
}
|
||||
function formatLine(
|
||||
line: {
|
||||
readonly lineNumber: number;
|
||||
readonly text: string;
|
||||
readonly error?: string;
|
||||
},
|
||||
): string {
|
||||
let text = `[${line.lineNumber}] `;
|
||||
text += line.error ? '❌' : '✅';
|
||||
text += ` ${trimLine(line.text)}`;
|
||||
if (line.error) {
|
||||
text += `\n\t⟶ ${line.error}`;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
function trimLine(line: string) {
|
||||
const maxLength = 500;
|
||||
if (line.length > maxLength) {
|
||||
line = `${line.substring(0, maxLength)}... [Rest of the line trimmed]`;
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user