Skip to content

Commit eebf0fa

Browse files
committed
Add eslint config
1 parent 94c1d29 commit eebf0fa

File tree

2 files changed

+148
-8
lines changed

2 files changed

+148
-8
lines changed

eslint.config.js

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
import eslint from "@eslint/js";
2+
import tseslint from "@typescript-eslint/eslint-plugin";
3+
import tsparser from "@typescript-eslint/parser";
4+
5+
export default [
6+
// Base ESLint recommended rules
7+
eslint.configs.recommended,
8+
9+
// TypeScript configuration
10+
{
11+
files: ["src/**/*.ts"],
12+
languageOptions: {
13+
parser: tsparser,
14+
parserOptions: {
15+
ecmaVersion: 2022,
16+
sourceType: "module",
17+
project: "./tsconfig.json",
18+
},
19+
globals: {
20+
process: "readonly",
21+
console: "readonly",
22+
Buffer: "readonly",
23+
__dirname: "readonly",
24+
__filename: "readonly",
25+
global: "writable",
26+
},
27+
},
28+
plugins: {
29+
"@typescript-eslint": tseslint,
30+
},
31+
rules: {
32+
// TypeScript-specific rules for medical/healthcare code
33+
"@typescript-eslint/no-explicit-any": "error",
34+
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_", varsIgnorePattern: "^_" }],
35+
"no-unused-vars": ["error", { argsIgnorePattern: "^_", varsIgnorePattern: "^_" }],
36+
"@typescript-eslint/explicit-function-return-type": "error",
37+
"@typescript-eslint/no-non-null-assertion": "error",
38+
"@typescript-eslint/prefer-nullish-coalescing": "error",
39+
"@typescript-eslint/prefer-optional-chain": "error",
40+
"@typescript-eslint/no-floating-promises": "error",
41+
"@typescript-eslint/await-thenable": "error",
42+
"@typescript-eslint/no-misused-promises": "error",
43+
"@typescript-eslint/require-await": "error",
44+
45+
// Naming conventions (Australian English preference)
46+
"@typescript-eslint/naming-convention": [
47+
"error",
48+
{
49+
selector: "default",
50+
format: ["camelCase"],
51+
leadingUnderscore: "allow",
52+
trailingUnderscore: "forbid",
53+
},
54+
{
55+
selector: "variable",
56+
format: ["camelCase", "UPPER_CASE"],
57+
},
58+
{
59+
selector: "typeLike",
60+
format: ["PascalCase"],
61+
},
62+
{
63+
selector: "enumMember",
64+
format: ["PascalCase"],
65+
},
66+
],
67+
68+
// Code quality and safety rules for healthcare data
69+
"complexity": ["error", 10],
70+
"max-depth": ["error", 4],
71+
"max-lines-per-function": ["error", 50],
72+
"no-console": ["warn", { allow: ["warn", "error"] }],
73+
"no-debugger": "error",
74+
"no-eval": "error",
75+
"no-implied-eval": "error",
76+
"no-new-func": "error",
77+
"no-var": "error",
78+
"prefer-const": "error",
79+
"eqeqeq": ["error", "always"],
80+
81+
// Import and module rules
82+
"no-duplicate-imports": "error",
83+
"sort-imports": ["error", {
84+
ignoreCase: true,
85+
ignoreDeclarationSort: true,
86+
ignoreMemberSort: false,
87+
memberSyntaxSortOrder: ["none", "all", "multiple", "single"]
88+
}],
89+
90+
// Error handling - critical for medical data processing
91+
"no-throw-literal": "error",
92+
93+
// Disable rules that conflict with Prettier
94+
"indent": "off",
95+
"quotes": "off",
96+
"semi": "off",
97+
"comma-dangle": "off",
98+
"max-len": "off",
99+
},
100+
},
101+
102+
// Test files configuration
103+
{
104+
files: ["src/**/*.test.ts"],
105+
rules: {
106+
// Relax some rules for test files
107+
"@typescript-eslint/explicit-function-return-type": "off",
108+
"@typescript-eslint/no-explicit-any": "off",
109+
"max-lines-per-function": "off",
110+
"no-console": "off",
111+
"complexity": "off",
112+
},
113+
},
114+
115+
// ANTLR visitor files configuration
116+
{
117+
files: ["src/fhirpath/visitor.ts", "src/fhirpath/transpiler.ts"],
118+
rules: {
119+
// Relax rules for complex ANTLR visitor code
120+
"complexity": ["error", 30],
121+
"@typescript-eslint/no-explicit-any": "warn",
122+
"@typescript-eslint/no-non-null-assertion": "warn",
123+
"@typescript-eslint/prefer-nullish-coalescing": "warn",
124+
},
125+
},
126+
127+
// Ignore patterns
128+
{
129+
ignores: [
130+
"dist/**/*",
131+
"out/**/*",
132+
"node_modules/**/*",
133+
"coverage/**/*",
134+
"src/generated/**/*", // Generated ANTLR grammar files
135+
"*.d.ts",
136+
"*.config.js",
137+
"*.config.ts",
138+
],
139+
},
140+
];

src/fhirpath/visitor.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export class FHIRPathToTSqlVisitor
265265
}
266266

267267
// Literal visitors
268-
visitNullLiteral(ctx: NullLiteralContext): string {
268+
visitNullLiteral(_ctx: NullLiteralContext): string {
269269
return "NULL";
270270
}
271271

@@ -331,20 +331,20 @@ export class FHIRPathToTSqlVisitor
331331
return this.visit(ctx.function());
332332
}
333333

334-
visitThisInvocation(ctx: ThisInvocationContext): string {
334+
visitThisInvocation(_ctx: ThisInvocationContext): string {
335335
// $this refers to the current item in an iteration context
336336
if (this.context.iterationContext) {
337337
return this.context.iterationContext;
338338
}
339339
return `${this.context.resourceAlias}.json`;
340340
}
341341

342-
visitIndexInvocation(ctx: IndexInvocationContext): string {
342+
visitIndexInvocation(_ctx: IndexInvocationContext): string {
343343
// $index in forEach contexts - simplified implementation
344344
return "0"; // Default to first index
345345
}
346346

347-
visitTotalInvocation(ctx: TotalInvocationContext): string {
347+
visitTotalInvocation(_ctx: TotalInvocationContext): string {
348348
// $total in forEach contexts - simplified implementation
349349
return "1"; // Default count
350350
}
@@ -592,7 +592,7 @@ export class FHIRPathToTSqlVisitor
592592
}
593593
}
594594

595-
private handleEmptyFunction(args: string[]): string {
595+
private handleEmptyFunction(_args: string[]): string {
596596
if (this.context.iterationContext) {
597597
if (this.context.iterationContext.includes("JSON_QUERY")) {
598598
return `CASE
@@ -615,7 +615,7 @@ export class FHIRPathToTSqlVisitor
615615
}
616616
}
617617

618-
private handleFirstFunction(args: string[]): string {
618+
private handleFirstFunction(_args: string[]): string {
619619
if (this.context.iterationContext) {
620620
// Check if we have a JSON_QUERY expression for an array
621621
if (this.context.iterationContext.includes("JSON_QUERY")) {
@@ -713,7 +713,7 @@ export class FHIRPathToTSqlVisitor
713713
return this.context.iterationContext || `${this.context.resourceAlias}.json`;
714714
}
715715

716-
private handleGetReferenceKeyFunction(args: string[]): string {
716+
private handleGetReferenceKeyFunction(_args: string[]): string {
717717
if (this.context.iterationContext) {
718718
return `SUBSTRING(${this.context.iterationContext}, CHARINDEX('/', ${this.context.iterationContext}) + 1, LEN(${this.context.iterationContext}))`;
719719
}
@@ -738,7 +738,7 @@ export class FHIRPathToTSqlVisitor
738738
return `JSON_QUERY(${base}, '$.extension')`;
739739
}
740740

741-
private handleBoundaryFunction(functionName: string, args: string[]): string {
741+
private handleBoundaryFunction(_functionName: string, _args: string[]): string {
742742
const base = this.context.iterationContext || `${this.context.resourceAlias}.json`;
743743
// Simplified implementation - return the value as-is
744744
return base;

0 commit comments

Comments
 (0)