Skip to content

Commit 38c01fa

Browse files
committed
fix: refactor handleRegularCharacter to eliminate invariant return
Resolves SonarQube code smell S3516 by removing redundant if-else branches that both returned the same value. The function now advances the position unconditionally and only conditionally updates line/column tracking for newlines before returning the character once at the end. This maintains identical behavior while improving code maintainability.
1 parent 743fb90 commit 38c01fa

4 files changed

Lines changed: 14 additions & 27 deletions

File tree

package-lock.json

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lexer.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -457,15 +457,12 @@ export class Lexer {
457457

458458
private handleRegularCharacter(): string {
459459
const char = this.currentChar();
460+
this.advance();
460461
if (char === '\n') {
461-
this.advance();
462462
this.line++;
463463
this.column = 1;
464-
return char;
465-
} else {
466-
this.advance();
467-
return char;
468464
}
465+
return char;
469466
}
470467

471468
private readNumber(startLine: number, startColumn: number): Token {

src/module-system/module-system.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ export class ModuleSystem {
231231
// Try to extract line and column from error message
232232
const lineColMatch = message.match(/(?:line|:)\s*(\d+)(?::(\d+))?/i);
233233
const line = lineColMatch ? Number.parseInt(lineColMatch[1], 10) : undefined;
234-
const column = lineColMatch && lineColMatch[2] ? Number.parseInt(lineColMatch[2], 10) : undefined;
234+
const column =
235+
lineColMatch && lineColMatch[2] ? Number.parseInt(lineColMatch[2], 10) : undefined;
235236

236237
return {
237238
message,

tests/helpers/test-utils.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,19 @@ export interface CliRunOptions {
6969

7070
/** Run a CLI command with common defaults */
7171
export function runCliCommand(options: CliRunOptions): SpawnSyncReturns<string> {
72-
return spawnSync(
73-
process.execPath,
74-
[CLI_PATH, options.command, ...options.args],
75-
{
76-
encoding: options.encoding || 'utf-8',
77-
timeout: options.timeout || 10000,
78-
cwd: options.cwd,
79-
env: options.env || process.env,
80-
}
81-
);
72+
return spawnSync(process.execPath, [CLI_PATH, options.command, ...options.args], {
73+
encoding: options.encoding || 'utf-8',
74+
timeout: options.timeout || 10000,
75+
cwd: options.cwd,
76+
env: options.env || process.env,
77+
});
8278
}
8379

8480
/** Create a test .som file with given content */
85-
export function createTestFile(filePath: string, content: string = TEST_FIXTURES.testFunction): void {
81+
export function createTestFile(
82+
filePath: string,
83+
content: string = TEST_FIXTURES.testFunction
84+
): void {
8685
fs.writeFileSync(filePath, content);
8786
}
8887

0 commit comments

Comments
 (0)