Skip to content

Commit 25485f2

Browse files
committed
Fix a lot of biome suggestions.
1 parent 276099c commit 25485f2

14 files changed

Lines changed: 71 additions & 28 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ AIDBOX_LICENSE_ID ?=
22

33
TYPECHECK = bunx tsc --noEmit
44
FORMAT = bunx biome format --write
5-
LINT = bunx biome check --diagnostic-level=error --write --unsafe
5+
LINT = bunx biome check --write
66
TEST = bun test
77

88
.PHONY: all typecheck test-typeschema test-register test-codegen test-typescript-r4-example

examples/typescript-r4/demo.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,15 @@ function runDemo() {
276276
const patient = createPatient();
277277
console.log("✓ Created patient:", patient.id);
278278

279-
const observation = createObservation(patient.id!);
279+
if (!patient.id) throw new Error("Failed to create patient");
280+
const observation = createObservation(patient.id);
280281
console.log("✓ Created glucose observation:", observation.id);
281282

282283
console.log(`\n${"=".repeat(60)}`);
283284
console.log("Bodyweight profile attach/extract demo:");
284285
console.log("=".repeat(60));
285286

286-
const bodyweightObs = createBodyWeightObservation(patient.id!);
287+
const bodyweightObs = createBodyWeightObservation(patient.id);
287288
console.log("✓ Created body weight observation with profile:", bodyweightObs.id);
288289

289290
const bundle = createBundle(patient, observation, bodyweightObs);

src/api/writer-generator/typescript.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ export class TypeScript extends Writer<TypeScriptOptions> {
275275
if (field.enum) {
276276
tsType = tsEnumType(field.enum);
277277
} else if (schema.identifier.name === "Reference" && tsName === "reference") {
278+
// biome-ignore lint: that is exactly string what we want
278279
tsType = "`${T}/${string}`";
279280
} else if (field.reference && field.reference.length > 0) {
280281
const references = field.reference.map((ref) => `"${ref.name}"`).join(" | ");

src/cli/commands/typeschema/generate.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ export const generateTypeschemaCommand: CommandModule<Record<string, unknown>, G
126126
// Use the output format determined earlier
127127

128128
// Ensure output directory exists
129-
const outputPath = argv.output!;
129+
const outputPath = argv.output;
130+
if (!outputPath) throw new Error("Output format not specified");
130131
await mkdir(dirname(outputPath), { recursive: true });
131132

132133
// Format and write the schemas

src/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,8 @@ export class ConfigLoader {
731731
}
732732

733733
// Merge with defaults
734-
return this.mergeWithDefaults(validation.config!);
734+
if (!validation.config) throw new Error("Invalid configuration");
735+
return this.mergeWithDefaults(validation.config);
735736
} catch (error) {
736737
if (error instanceof Error) {
737738
throw new Error(`Failed to load config from ${filePath}: ${error.message}`);

src/typeschema/core/field-builder.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import { mkBindingIdentifier, mkIdentifier } from "./identifier";
1414
import { mkNestedIdentifier } from "./nested-types";
1515

1616
function isRequired(register: Register, fhirSchema: RichFHIRSchema, path: string[]): boolean {
17-
const fieldName = path[path.length - 1]!;
17+
const fieldName = path[path.length - 1];
18+
if (!fieldName) throw new Error(`Internal error: fieldName is missing for path ${path.join("/")}`);
1819
const parentPath = path.slice(0, -1);
1920

2021
const requires = register.resolveFsGenealogy(fhirSchema.package_meta, fhirSchema.url).flatMap((fs) => {
@@ -116,7 +117,7 @@ export const mkField = (
116117
if (!fieldType)
117118
logger?.warn(`Field type not found for '${fhirSchema.url}#${path.join(".")}' (${fhirSchema.derivation})`);
118119
return {
119-
type: fieldType!,
120+
type: fieldType as Identifier,
120121
required: isRequired(register, fhirSchema, path),
121122
excluded: isExcluded(register, fhirSchema, path),
122123

src/typeschema/core/nested-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export function mkNestedTypes(
116116
url: baseUrl,
117117
};
118118

119-
const fields = transformNestedElements(register, fhirSchema, path, element.elements!, logger);
119+
const fields = transformNestedElements(register, fhirSchema, path, element.elements ?? {}, logger);
120120

121121
const nestedType: NestedType = {
122122
identifier,

src/typeschema/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ type ValueSetCompose = {
344344
include: {
345345
concept?: Concept[];
346346
system?: string;
347-
filter?: {}[];
347+
filter?: unknown[];
348348
}[];
349349
};
350350

src/utils/codegen-logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class CodegenLogger {
3636
};
3737
}
3838

39-
private static consoleLevelsMap: Record<LogLevel, Function> = {
39+
private static consoleLevelsMap: Record<LogLevel, (...data: any[]) => void> = {
4040
[LogLevel.INFO]: console.log,
4141
[LogLevel.WARN]: console.warn,
4242
[LogLevel.ERROR]: console.error,

test/unit/typeschema/r4.test.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ describe("TypeSchema R4 generation", async () => {
77
const r4 = await mkR4Register();
88

99
it("Bundle and elementReference", async () => {
10-
const profile = r4.resolveFs(r4Package, "http://hl7.org/fhir/StructureDefinition/Bundle" as CanonicalUrl)!;
10+
const profile = r4.resolveFs(r4Package, "http://hl7.org/fhir/StructureDefinition/Bundle" as CanonicalUrl);
11+
if (!profile) {
12+
throw new Error("Bundle profile not found");
13+
}
1114
const ts = (await registerFsAndMkTs(r4, profile))[0] as RegularTypeSchema;
1215
expect(ts?.nested).toHaveLength(5);
1316
expect(ts).toMatchObject({
@@ -47,7 +50,10 @@ describe("TypeSchema R4 generation", async () => {
4750
});
4851

4952
it("markdown", async () => {
50-
const md = r4.resolveFs(r4Package, "http://hl7.org/fhir/StructureDefinition/markdown" as CanonicalUrl)!;
53+
const md = r4.resolveFs(r4Package, "http://hl7.org/fhir/StructureDefinition/markdown" as CanonicalUrl);
54+
if (!md) {
55+
throw new Error("markdown type not found");
56+
}
5157
const ts = (await registerFsAndMkTs(r4, md))[0] as RegularTypeSchema;
5258
expect(ts).toMatchObject({
5359
identifier: {
@@ -67,9 +73,13 @@ describe("TypeSchema R4 generation", async () => {
6773
const parameters = r4.resolveFs(
6874
r4Package,
6975
"http://hl7.org/fhir/StructureDefinition/Parameters" as CanonicalUrl,
70-
)!;
76+
);
77+
if (!parameters) {
78+
throw new Error("Parameters resource not found");
79+
}
7180
const ts = (await registerFsAndMkTs(r4, parameters))[0] as RegularTypeSchema;
72-
expect(ts.dependencies!).toContainEqual({
81+
expect(ts.dependencies).toBeDefined();
82+
expect(ts.dependencies).toContainEqual({
7383
kind: "primitive-type",
7484
package: "hl7.fhir.r4.core",
7585
version: "4.0.1",

0 commit comments

Comments
 (0)