Skip to content

Commit e7a3e03

Browse files
ipasechnikovclaudeNikitaSinc
committed
Add knip: detect dead files, exports, types across the project
Adds knip@6 with flat config in knip.json. Declares runtime entry points (index.ts, workers, mllp, BAR services, v2-to-fhir processor), script entries (scripts/**), and test entries. Cleanup to reach 0 findings: - Deleted 8 unused barrel files: src/bar/index.ts, src/code-mapping/ index.ts, src/mllp/index.ts, src/v2-to-fhir/index.ts, src/v2-to-fhir/{code-mapping,datatypes,messages,segments}/index.ts. Nothing imported them — were likely leftovers from an earlier extraction plan. - Removed 23 redundant `export default` lines from converter modules (adt-a01/a03/a08, oru-r01, vxu-v04, pid-patient, SAD/ST/XAD/XCN/XON/ XPN/XTN datatype converters, NK1/DG1/AL1/IN1 segment converters). All had both a named export and a default for the same function; default was never imported. - De-exported 49 unused named exports across ~26 files (made file-private by dropping the `export` keyword). - De-exported 91 unused exported types/interfaces across ~36 files (same pattern — kept as internal types for readability). - Deleted genuinely dead code: getValidValuesWithDisplay + getDisplayForCode (mapping-type-options), convertXPNArrayToHumanNames (xpn-humanname), fetchConceptMap (concept-map/service — shadowed by test-local helper), plus a couple of dead re-exports. Also wire `bun run knip` into test:local and test:all. Any new dead file, export, or redundant export breaks the test loop. Typecheck + lint stay at 0 errors/warnings. Unit tests unchanged (1878 pass / 17 todo / 74 preexisting failures). Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> Co-authored-by: Nikita Sintsev <nikita.sintsev@health-samurai.io>
1 parent c18aba4 commit e7a3e03

87 files changed

Lines changed: 270 additions & 399 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bun.lock

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

knip.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"$schema": "https://unpkg.com/knip@6/schema.json",
3+
"entry": [
4+
"src/workers.ts",
5+
"src/bar/sender-service.ts",
6+
"src/bar/account-builder-service.ts",
7+
"src/v2-to-fhir/processor-service.ts",
8+
"scripts/**/*.ts",
9+
"test/**/*.test.ts",
10+
"test/integration/preload.ts",
11+
"test/integration/helpers.ts",
12+
"test/unit/v2-to-fhir/helpers.ts"
13+
],
14+
"project": [
15+
"src/**/*.ts",
16+
"scripts/**/*.ts",
17+
"test/**/*.ts"
18+
],
19+
"ignore": [
20+
"src/fhir/**",
21+
"src/hl7v2/generated/**"
22+
]
23+
}

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"name": "aidbox-hl7",
3-
"module": "index.ts",
3+
"module": "src/index.ts",
44
"devDependencies": {
55
"@eslint/js": "^10.0.1",
66
"@types/bun": "latest",
77
"eslint": "^10.2.1",
88
"fast-xml-parser": "^5.3.5",
9+
"knip": "^6.6.2",
910
"typescript-eslint": "^8.59.0"
1011
},
1112
"peerDependencies": {
@@ -19,14 +20,15 @@
1920
"typecheck": "bash scripts/typecheck.sh",
2021
"lint": "eslint . --max-warnings 0",
2122
"lint:fix": "eslint . --fix --max-warnings 0",
23+
"knip": "knip-bun",
2224
"mllp": "bun src/mllp/mllp-server.ts",
2325
"test-mllp": "bun scripts/test-mllp-client.ts",
2426
"regenerate-hl7v2": "bash scripts/regenerate-hl7v2.sh",
2527
"regenerate-fhir": "bun scripts/regenerate-fhir.ts",
2628
"generate-hl7v2-reference": "bun scripts/generate-hl7v2-reference.ts",
2729
"migrate": "bun src/migrate.ts",
28-
"test:all": "bun run lint && bun test && bun test:integration",
29-
"test:local": "bun run lint && bun test && bun test:smoke",
30+
"test:all": "bun run lint && bun run knip && bun test && bun test:integration",
31+
"test:local": "bun run lint && bun run knip && bun test && bun test:smoke",
3032
"test:unit": "bun test",
3133
"test:integration": "bun test --test-root ./test/integration --preload ./test/integration/preload.ts --max-concurrency=1",
3234
"test:smoke": "bun test --test-root ./test/integration --preload ./test/integration/preload.ts --max-concurrency=1 --test-name-pattern \"smoke: \"",

src/aidbox.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export async function resourceExists(
7676
}
7777
}
7878

79-
export class PreconditionFailedError extends Error {
79+
class PreconditionFailedError extends Error {
8080
constructor(message: string) {
8181
super(message);
8282
this.name = "PreconditionFailedError";
@@ -90,7 +90,7 @@ export class NotFoundError extends Error {
9090
}
9191
}
9292

93-
export interface ResourceWithETag<T> {
93+
interface ResourceWithETag<T> {
9494
resource: T;
9595
etag: string;
9696
}

src/api/demo-scenario.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const DEMO_SAMPLE_IDS = [
4141
export const DEMO_WAIT_DEADLINE_MS = 8000;
4242
export const DEMO_POLL_INTERVAL_MS = 500;
4343

44-
export interface RunDemoScenarioOptions {
44+
interface RunDemoScenarioOptions {
4545
send?: (host: string, port: number, message: string) => Promise<string>;
4646
sleep?: (ms: number) => Promise<void>;
4747
/** Fetch current status for a message by MSH-10. Inject for tests. */

src/api/task-resolution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
/**
2929
* Get a value from a Task's input array by type text.
3030
*/
31-
export function getTaskInputValue(
31+
function getTaskInputValue(
3232
task: Task,
3333
typeText: string,
3434
): string | undefined {

src/bar/generator.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,3 @@ export function generateBarMessage(input: BarMessageInput): HL7v2Message {
348348
.addVISIT(buildVisit(input))
349349
.build();
350350
}
351-
352-
// Re-export types
353-
export type { BarMessageInput } from "./types";

src/bar/index.ts

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

src/code-mapping/concept-map/observation-code-resolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
type SenderContext,
1515
} from "./service";
1616

17-
export interface CodeResolutionResult {
17+
interface CodeResolutionResult {
1818
loinc: Coding;
1919
local?: Coding;
2020
}
@@ -33,7 +33,7 @@ export class LoincResolutionError extends Error {
3333
}
3434
}
3535

36-
export class MissingLocalSystemError extends Error {
36+
class MissingLocalSystemError extends Error {
3737
constructor(
3838
message: string,
3939
public readonly localCode: string | undefined,

src/code-mapping/concept-map/service.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ export interface SenderContext {
4545
* Mapping type filter options for the UI.
4646
* "all" shows all mapping types.
4747
*/
48-
export type MappingTypeFilter = MappingTypeName | "all";
48+
type MappingTypeFilter = MappingTypeName | "all";
4949

50-
export interface ConceptMapSummary {
50+
interface ConceptMapSummary {
5151
id: string;
5252
displayName: string;
5353
mappingType: MappingTypeName;
5454
targetSystem: string;
5555
}
5656

57-
export interface MappingEntry {
57+
interface MappingEntry {
5858
localCode: string;
5959
localDisplay: string;
6060
localSystem: string;
@@ -79,7 +79,7 @@ interface TranslateResponse {
7979
parameter?: TranslateResponseParameter[];
8080
}
8181

82-
export type TranslateResult =
82+
type TranslateResult =
8383
| { status: "found"; coding: Coding }
8484
| { status: "no_mapping" }
8585
| { status: "not_found" };
@@ -92,7 +92,7 @@ export type TranslateResult =
9292
* Generate the base ConceptMap ID from sender context (without mapping type).
9393
* Format: hl7v2-{sendingApplication}-{sendingFacility}
9494
*/
95-
export function generateBaseConceptMapId(sender: SenderContext): string {
95+
function generateBaseConceptMapId(sender: SenderContext): string {
9696
const app = toKebabCase(sender.sendingApplication);
9797
const facility = toKebabCase(sender.sendingFacility);
9898
return `hl7v2-${app}-${facility}`;
@@ -116,7 +116,7 @@ export function generateConceptMapId(
116116
* Format sender context as title string (format: "APP | FACILITY")
117117
* Used for ConceptMap.title field
118118
*/
119-
export function formatSenderAsTitle(sender: SenderContext): string {
119+
function formatSenderAsTitle(sender: SenderContext): string {
120120
return `${sender.sendingApplication} | ${sender.sendingFacility}`;
121121
}
122122

@@ -198,19 +198,6 @@ export async function translateCode(
198198
// ConceptMap CRUD operations
199199
// ============================================================================
200200

201-
export async function fetchConceptMap(
202-
conceptMapId: string,
203-
): Promise<ConceptMap | null> {
204-
try {
205-
return await aidboxFetch<ConceptMap>(`/fhir/ConceptMap/${conceptMapId}`);
206-
} catch (error) {
207-
if (error instanceof Error && error.message.includes("404")) {
208-
return null;
209-
}
210-
throw error;
211-
}
212-
}
213-
214201
export function createEmptyConceptMap(
215202
sender: SenderContext,
216203
mappingType: MappingTypeName,
@@ -323,7 +310,7 @@ export function detectMappingTypeFromConceptMap(
323310
/**
324311
* Check if a mapping entry matches a search query
325312
*/
326-
export function matchesSearch(entry: MappingEntry, search: string): boolean {
313+
function matchesSearch(entry: MappingEntry, search: string): boolean {
327314
const query = search.toLowerCase();
328315
return (
329316
entry.localCode.toLowerCase().includes(query) ||
@@ -336,7 +323,7 @@ export function matchesSearch(entry: MappingEntry, search: string): boolean {
336323
/**
337324
* Check if a mapping entry already exists
338325
*/
339-
export function checkDuplicateEntry(
326+
function checkDuplicateEntry(
340327
conceptMap: ConceptMap,
341328
localSystem: string,
342329
localCode: string,

0 commit comments

Comments
 (0)