2026-10-18 01:03:33 +00:00
|
|
|
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 {
|
2026-10-18 01:27:52 +00:00
|
|
|
if (rawLine.trim().length === 0) {return;}
|
|
|
|
|
if (rawLine.includes('\t')) {return;}
|
2026-10-18 01:03:33 +00:00
|
|
|
|
2026-10-27 22:38:30 +00:00
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-18 01:03:33 +00:00
|
|
|
const leadingSpacesMatch = rawLine.match(/^ +/);
|
|
|
|
|
const spaceCount = leadingSpacesMatch ? leadingSpacesMatch[0].length : 0;
|
|
|
|
|
|
|
|
|
|
if (spaceCount > 0 && spaceCount % 4 !== 0) {
|
|
|
|
|
ctx.addDiag(
|
|
|
|
|
lineIdx,
|
|
|
|
|
0,
|
2026-10-27 22:38:30 +00:00
|
|
|
spaceCount,
|
|
|
|
|
`Invalid indentation (${spaceCount} spaces). Please use a multiple of 4. (Tip: Shift+Alt+F to auto-format)`,
|
|
|
|
|
vscode.DiagnosticSeverity.Warning
|
2026-10-18 01:03:33 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public checkEnd(lines: string[], ctx: LinterContext): void {
|
2026-10-27 22:38:30 +00:00
|
|
|
// empty
|
2026-10-18 01:03:33 +00:00
|
|
|
}
|
2026-10-27 22:38:30 +00:00
|
|
|
}
|