Skip to content

Commit 87f55fe

Browse files
devillclaude
andcommitted
Fix quality violations in LocationRange utility methods
- Remove comments by extracting self-documenting methods - Break down oversized functions into single-responsibility methods - Extract getPositionInSourceFile(), validateNodeHasSymbol(), and checkForCompilationErrors() - All methods now under 12 lines with clear, single purposes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 80b7716 commit 87f55fe

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

src/core/ast/location-range.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,19 @@ export class LocationRange {
9191
}
9292

9393
getNodeFromSourceFile(sourceFile: SourceFile): Node {
94-
const startPos = sourceFile.compilerNode.getPositionOfLineAndCharacter(
94+
const startPos = this.getPositionInSourceFile(sourceFile);
95+
const node = sourceFile.getDescendantAtPos(startPos);
96+
return this.validateNodeHasSymbol(node);
97+
}
98+
99+
private getPositionInSourceFile(sourceFile: SourceFile): number {
100+
return sourceFile.compilerNode.getPositionOfLineAndCharacter(
95101
this.start.line - 1,
96102
this.start.column - 1
97103
);
98-
const node = sourceFile.getDescendantAtPos(startPos);
104+
}
105+
106+
private validateNodeHasSymbol(node: Node | undefined): Node {
99107
if (!node) {
100108
throw new Error(`No symbol found at location ${this.start.line}:${this.start.column}`);
101109
}
@@ -110,16 +118,17 @@ export class LocationRange {
110118
const astService = ASTService.createForFile(this.file);
111119
const sourceFile = astService.loadSourceFile(this.file);
112120

113-
// Check for compilation errors
121+
this.checkForCompilationErrors(sourceFile);
122+
this.validateLocationBounds(sourceFile);
123+
124+
return this.getNodeFromSourceFile(sourceFile);
125+
}
126+
127+
private checkForCompilationErrors(sourceFile: SourceFile): void {
114128
const diagnostics = sourceFile.getPreEmitDiagnostics();
115129
if (diagnostics.length > 0) {
116130
throw new Error(`TypeScript compilation error in ${this.file}`);
117131
}
118-
119-
// Validate location bounds
120-
this.validateLocationBounds(sourceFile);
121-
122-
return this.getNodeFromSourceFile(sourceFile);
123132
}
124133
}
125134

0 commit comments

Comments
 (0)