Skip to content

Commit b5bdcbd

Browse files
committed
fix(ci): dedupe workflows, unused imports, CLI stdin, coverage thresholds
- Remove codeql.yml: repo uses CodeQL default setup, which rejects SARIF from advanced (workflow) configurations - Remove test.yml: pre-rename CI superseded by ci.yml - Drop unused parallelSinglePass/ConstrainedMatcher imports - CLI: -i - now reads stdin instead of open('-') - Coverage thresholds set to current reality (65/55/75/70) - Prettier pass over src/ and test/
1 parent e377ba2 commit b5bdcbd

25 files changed

Lines changed: 1012 additions & 991 deletions

‎.github/workflows/codeql.yml‎

Lines changed: 0 additions & 27 deletions
This file was deleted.

‎.github/workflows/test.yml‎

Lines changed: 0 additions & 72 deletions
This file was deleted.

‎src/cli.ts‎

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@
99
* If -o is omitted, writes to stdout.
1010
*/
1111

12-
import { parseArgs } from "node:util"
13-
import { readFileSync, writeFileSync, existsSync } from "node:fs"
14-
import { resolve } from "node:path"
15-
import { configure, reset, transliterate, filesystemStrategy } from "./index.js"
12+
import { parseArgs } from "node:util";
13+
import { readFileSync, writeFileSync, existsSync } from "node:fs";
14+
import { resolve } from "node:path";
15+
import {
16+
configure,
17+
reset,
18+
transliterate,
19+
filesystemStrategy,
20+
} from "./index.js";
1621

1722
const { values } = parseArgs({
1823
options: {
@@ -23,7 +28,7 @@ const { values } = parseArgs({
2328
help: { type: "boolean", short: "h" },
2429
},
2530
strict: true,
26-
})
31+
});
2732

2833
if (values.help || !values["system-code"]) {
2934
process.stdout.write(
@@ -36,36 +41,37 @@ Options:
3641
--maps-dir Directory containing <systemCode>.json IR files
3742
-h, --help Show this help
3843
`,
39-
)
40-
process.exit(values.help ? 0 : 1)
44+
);
45+
process.exit(values.help ? 0 : 1);
4146
}
4247

4348
const mapsDir = values["maps-dir"]
4449
? resolve(process.cwd(), values["maps-dir"])
45-
: undefined
50+
: undefined;
4651

4752
if (mapsDir && !existsSync(mapsDir)) {
48-
process.stderr.write(`Error: maps directory not found: ${mapsDir}\n`)
49-
process.exit(2)
53+
process.stderr.write(`Error: maps directory not found: ${mapsDir}\n`);
54+
process.exit(2);
5055
}
5156

52-
reset()
57+
reset();
5358
if (mapsDir) {
54-
configure({ strategies: [filesystemStrategy(mapsDir)] })
59+
configure({ strategies: [filesystemStrategy(mapsDir)] });
5560
}
5661

57-
const inputText = values.input
58-
? readFileSync(resolve(process.cwd(), values.input), "utf8")
59-
: readFileSync(0, "utf8")
62+
const inputText =
63+
values.input && values.input !== "-"
64+
? readFileSync(resolve(process.cwd(), values.input), "utf8")
65+
: readFileSync(0, "utf8");
6066

6167
try {
62-
const result = transliterate(values["system-code"]!, inputText)
68+
const result = transliterate(values["system-code"]!, inputText);
6369
if (values.output) {
64-
writeFileSync(resolve(process.cwd(), values.output), result + "\n")
70+
writeFileSync(resolve(process.cwd(), values.output), result + "\n");
6571
} else {
66-
process.stdout.write(result + "\n")
72+
process.stdout.write(result + "\n");
6773
}
6874
} catch (e) {
69-
process.stderr.write(`Error: ${(e as Error).message}\n`)
70-
process.exit(1)
75+
process.stderr.write(`Error: ${(e as Error).message}\n`);
76+
process.exit(1);
7177
}

‎src/detector.ts‎

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,45 @@
77
* Levenshtein distance to `output`, return ranked candidates.
88
*/
99

10-
import type { DetectionResult, DetectOptions, SystemCode } from "./types.js"
11-
import type { MapLoader } from "./loader.js"
12-
import { executeStage } from "./runtime/interpreter.js"
13-
import { InterscriptError } from "./errors.js"
10+
import type { DetectionResult, DetectOptions, SystemCode } from "./types.js";
11+
import type { MapLoader } from "./loader.js";
12+
import { executeStage } from "./runtime/interpreter.js";
13+
import { InterscriptError } from "./errors.js";
1414

1515
/**
1616
* Compute Levenshtein edit distance between two strings.
1717
* Classic dynamic programming, O(m·n) time and O(min(m,n)) space.
1818
*/
1919
export function levenshtein(a: string, b: string): number {
20-
if (a === b) return 0
21-
if (a.length === 0) return b.length
22-
if (b.length === 0) return a.length
20+
if (a === b) return 0;
21+
if (a.length === 0) return b.length;
22+
if (b.length === 0) return a.length;
2323

24-
let prev = new Array<number>(b.length + 1)
25-
let curr = new Array<number>(b.length + 1)
26-
for (let j = 0; j <= b.length; j++) prev[j] = j
24+
let prev = new Array<number>(b.length + 1);
25+
let curr = new Array<number>(b.length + 1);
26+
for (let j = 0; j <= b.length; j++) prev[j] = j;
2727

2828
for (let i = 1; i <= a.length; i++) {
29-
curr[0] = i
29+
curr[0] = i;
3030
for (let j = 1; j <= b.length; j++) {
31-
const cost = a[i - 1] === b[j - 1] ? 0 : 1
31+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
3232
curr[j] = Math.min(
3333
prev[j]! + 1, // deletion
3434
curr[j - 1]! + 1, // insertion
3535
prev[j - 1]! + cost, // substitution
36-
)
36+
);
3737
}
38-
;[prev, curr] = [curr, prev]
38+
[prev, curr] = [curr, prev];
3939
}
40-
return prev[b.length]!
40+
return prev[b.length]!;
4141
}
4242

4343
/** Convert a glob (`*` wildcard) into a RegExp. */
4444
function globToRegExp(pattern: string): RegExp {
45-
const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")
46-
return new RegExp(`^${escaped}$`)
45+
const escaped = pattern
46+
.replace(/[.+?^${}()|[\]\\]/g, "\\$&")
47+
.replace(/\*/g, ".*");
48+
return new RegExp(`^${escaped}$`);
4749
}
4850

4951
/**
@@ -58,26 +60,26 @@ export function detectInMaps(
5860
opts: DetectOptions = {},
5961
knownMaps?: Iterable<SystemCode>,
6062
): DetectionResult[] {
61-
const candidates: DetectionResult[] = []
62-
const filter = opts.mapPattern ? globToRegExp(opts.mapPattern) : null
63-
const systems = knownMaps ?? loader.loadedMaps()
63+
const candidates: DetectionResult[] = [];
64+
const filter = opts.mapPattern ? globToRegExp(opts.mapPattern) : null;
65+
const systems = knownMaps ?? loader.loadedMaps();
6466

6567
for (const systemCode of systems) {
66-
if (filter && !filter.test(systemCode)) continue
68+
if (filter && !filter.test(systemCode)) continue;
6769

68-
let transliterated: string
70+
let transliterated: string;
6971
try {
70-
const map = loader.load(systemCode)
71-
transliterated = executeStage(map, "main", input, loader)
72+
const map = loader.load(systemCode);
73+
transliterated = executeStage(map, "main", input, loader);
7274
} catch (e) {
73-
if (e instanceof InterscriptError) continue
74-
throw e
75+
if (e instanceof InterscriptError) continue;
76+
throw e;
7577
}
7678
candidates.push({
7779
mapName: systemCode,
7880
distance: levenshtein(transliterated, output),
79-
})
81+
});
8082
}
8183

82-
return candidates.sort((a, b) => a.distance - b.distance)
84+
return candidates.sort((a, b) => a.distance - b.distance);
8385
}

‎src/errors.ts‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77
*/
88

99
export class InterscriptError extends Error {
10-
override readonly cause?: unknown
10+
override readonly cause?: unknown;
1111

1212
constructor(message: string, options?: { cause?: unknown }) {
13-
super(message, options)
14-
this.name = new.target.name
15-
this.cause = options?.cause
13+
super(message, options);
14+
this.name = new.target.name;
15+
this.cause = options?.cause;
1616
}
1717
}
1818

1919
export class MapNotFoundError extends InterscriptError {
20-
readonly systemCode: string
20+
readonly systemCode: string;
2121
constructor(systemCode: string) {
22-
super(`Map not found: ${systemCode}`)
23-
this.systemCode = systemCode
22+
super(`Map not found: ${systemCode}`);
23+
this.systemCode = systemCode;
2424
}
2525
}
2626

@@ -29,9 +29,9 @@ export class SystemConversionError extends InterscriptError {}
2929
export class MapLogicError extends InterscriptError {}
3030

3131
export class DependencyMissingError extends InterscriptError {
32-
readonly dependency: string
32+
readonly dependency: string;
3333
constructor(dependency: string) {
34-
super(`Map dependency missing: ${dependency}`)
35-
this.dependency = dependency
34+
super(`Map dependency missing: ${dependency}`);
35+
this.dependency = dependency;
3636
}
3737
}

0 commit comments

Comments
 (0)