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 {
|
|
|
|
|
// Leere Zeilen oder Zeilen, die nur aus Leerzeichen/Tabs bestehen, ignorieren
|
2026-10-18 01:27:52 +00:00
|
|
|
if (rawLine.trim().length === 0) {return;}
|
2026-10-18 01:03:33 +00:00
|
|
|
|
|
|
|
|
// Wenn Tabs drin sind, meckert die SyntaxRule bereits. Das ignorieren wir hier.
|
2026-10-18 01:27:52 +00:00
|
|
|
if (rawLine.includes('\t')) {return;}
|
2026-10-18 01:03:33 +00:00
|
|
|
|
|
|
|
|
const leadingSpacesMatch = rawLine.match(/^ +/);
|
|
|
|
|
const spaceCount = leadingSpacesMatch ? leadingSpacesMatch[0].length : 0;
|
|
|
|
|
|
|
|
|
|
// Ist die Anzahl der Leerzeichen kein Vielfaches von 4?
|
|
|
|
|
if (spaceCount > 0 && spaceCount % 4 !== 0) {
|
|
|
|
|
ctx.addDiag(
|
|
|
|
|
lineIdx,
|
|
|
|
|
0,
|
|
|
|
|
spaceCount, // Markiert genau den Bereich der Leerzeichen
|
|
|
|
|
`Unsaubere Einrückung (${spaceCount} Leerzeichen). Nutze ein Vielfaches von 4. (Tipp: Shift+Alt+F zum Auto-Formatieren)`,
|
|
|
|
|
vscode.DiagnosticSeverity.Warning // Warning reicht hier völlig, Error wäre beim Tippen zu aggressiv
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public checkEnd(lines: string[], ctx: LinterContext): void {
|
|
|
|
|
// Hier muss am Ende der Datei nichts geprüft werden
|
|
|
|
|
}
|
|
|
|
|
}
|