bmc-tpl-code-all-around/src/core/rules/IndentationRule.ts

35 lines
1.2 KiB
TypeScript
Raw Normal View History

import * as vscode from 'vscode';
import { LinterRule } from './LinterRule';
import { LinterContext } from '../LinterContext';
export class IndentationRule implements LinterRule {
public checkLine(line: string, rawLine: string, lineIdx: number, ctx: LinterContext, lines: string[]): void {
if (rawLine.trim().length === 0) {return;}
if (rawLine.includes('\t')) {return;}
// HIER IST DER FIX: Wenn wir innerhalb von Klammern sind (Visual Alignment),
// greift die 4-Leerzeichen-Regel nicht!
if (ctx.parenStack.length > 0 || ctx.bracketStack.length > 0) {
return;
}
const leadingSpacesMatch = rawLine.match(/^ +/);
const spaceCount = leadingSpacesMatch ? leadingSpacesMatch[0].length : 0;
if (spaceCount > 0 && spaceCount % 4 !== 0) {
ctx.addDiag(
lineIdx,
0,
spaceCount,
`Invalid indentation (${spaceCount} spaces). Please use a multiple of 4. (Tip: Shift+Alt+F to auto-format)`,
vscode.DiagnosticSeverity.Warning
);
}
}
public checkEnd(lines: string[], ctx: LinterContext): void {
// empty
}
}