From 0dc572d7da431059da83f17a43db216e40e2fa4f Mon Sep 17 00:00:00 2001 From: openhands Date: Thu, 28 Nov 2024 16:52:30 +0000 Subject: [PATCH] Make TypeScript configuration stricter and fix Vega-Lite types --- eslint.config.js | 21 ++++++++++++++++++++- src/components/ActivityChart.tsx | 4 ++-- tsconfig.app.json | 25 +++++++++++++++++++++++-- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 092408a..ff9c0d6 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -7,11 +7,19 @@ import tseslint from 'typescript-eslint' export default tseslint.config( { ignores: ['dist'] }, { - extends: [js.configs.recommended, ...tseslint.configs.recommended], + extends: [ + js.configs.recommended, + ...tseslint.configs.recommendedTypeChecked, + ...tseslint.configs.strictTypeChecked, + ], files: ['**/*.{ts,tsx}'], languageOptions: { ecmaVersion: 2020, globals: globals.browser, + parserOptions: { + project: ['./tsconfig.app.json', './tsconfig.node.json'], + tsconfigRootDir: import.meta.dirname, + }, }, plugins: { 'react-hooks': reactHooks, @@ -23,6 +31,17 @@ export default tseslint.config( 'warn', { allowConstantExport: true }, ], + '@typescript-eslint/no-explicit-any': 'error', + '@typescript-eslint/explicit-function-return-type': 'error', + '@typescript-eslint/strict-boolean-expressions': 'error', + '@typescript-eslint/no-unnecessary-condition': 'error', + '@typescript-eslint/no-floating-promises': 'error', + '@typescript-eslint/no-misused-promises': 'error', + '@typescript-eslint/await-thenable': 'error', + '@typescript-eslint/no-unsafe-assignment': 'error', + '@typescript-eslint/no-unsafe-member-access': 'error', + '@typescript-eslint/no-unsafe-call': 'error', + '@typescript-eslint/no-unsafe-return': 'error', }, }, ) diff --git a/src/components/ActivityChart.tsx b/src/components/ActivityChart.tsx index eb33698..110cff2 100644 --- a/src/components/ActivityChart.tsx +++ b/src/components/ActivityChart.tsx @@ -8,7 +8,7 @@ interface ActivityChartProps { type: ActivityType; } -export function ActivityChart({ activities, type }: ActivityChartProps) { +export function ActivityChart({ activities, type }: ActivityChartProps): JSX.Element { const spec: VisualizationSpec = useMemo(() => ({ $schema: 'https://vega.github.io/schema/vega-lite/v5.json', data: { @@ -19,7 +19,7 @@ export function ActivityChart({ activities, type }: ActivityChartProps) { status: a.status, })), }, - mark: 'line', + mark: { type: 'line' } as const, encoding: { x: { field: 'date', diff --git a/tsconfig.app.json b/tsconfig.app.json index 358ca9b..c1a90cc 100644 --- a/tsconfig.app.json +++ b/tsconfig.app.json @@ -20,7 +20,28 @@ "noUnusedLocals": true, "noUnusedParameters": true, "noFallthroughCasesInSwitch": true, - "noUncheckedSideEffectImports": true + "noUncheckedIndexedAccess": true, + "noImplicitReturns": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "exactOptionalPropertyTypes": true, + "noUncheckedSideEffectImports": true, + + /* Type Checking */ + "allowUnreachableCode": false, + "allowUnusedLabels": false, + "noImplicitAny": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "strictBindCallApply": true, + "strictPropertyInitialization": true, + "noImplicitThis": true, + "useUnknownInCatchVariables": true, + "alwaysStrict": true, + "esModuleInterop": true, + "allowJs": false, + "checkJs": false }, - "include": ["src"] + "include": ["src"], + "exclude": ["node_modules"] }