From a81440b7253fed68bee6df3965a0085a75ecb98b Mon Sep 17 00:00:00 2001 From: Ben Allfree Date: Thu, 12 Oct 2023 04:17:13 -0700 Subject: [PATCH] enh: add type checking to linting --- .husky/pre-commit | 2 ++ .husky/pre-push | 1 + package.json | 4 ++++ packages/common/package.json | 3 ++- packages/daemon/package.json | 1 + packages/dashboard/package.json | 4 +++- packages/dashboard/src/global.d.ts | 1 + packages/dashboard/tsconfig.json | 8 +++++++- 8 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 035ccfb0..99e7c44f 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,8 +1,10 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" + branch="$(git rev-parse --abbrev-ref HEAD)" if [ "$branch" = "master" ]; then + yarn check:types yarn lint fi diff --git a/.husky/pre-push b/.husky/pre-push index 6cdaab7b..c1564a84 100755 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -1,4 +1,5 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" +yarn check:types yarn lint diff --git a/package.json b/package.json index 986e2bcd..2e7ed2df 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,10 @@ "license": "MIT", "private": true, "scripts": { + "check:types": "concurrently 'yarn:check:types:*'", + "check:types:dashboard": "cd packages/dashboard && yarn check:types", + "check:types:common": "cd packages/common && yarn check:types", + "check:types:daemon": "cd packages/daemon && yarn check:types", "lint": "prettier -c \"./**/*.{ts,js,cjs,svelte,json}\"", "lint:fix": "prettier -w \"./**/*.{ts,js,cjs,svelte,json}\"", "build": "concurrently 'yarn:build:*'", diff --git a/packages/common/package.json b/packages/common/package.json index 0c92959d..e5f67635 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -4,7 +4,8 @@ "main": "src/index.ts", "license": "MIT", "scripts": { - "postinstall": "cd ../.. && patch-package" + "postinstall": "cd ../.. && patch-package", + "check:types": "tsc --noEmit" }, "dependencies": { "ajv": "^8.11.2", diff --git a/packages/daemon/package.json b/packages/daemon/package.json index 331dac1a..99d3fc7a 100644 --- a/packages/daemon/package.json +++ b/packages/daemon/package.json @@ -3,6 +3,7 @@ "version": "0.0.1", "license": "MIT", "scripts": { + "check:types": "tsc --noEmit --skipLibCheck", "build": "concurrently 'yarn:build:*'", "build:docker": "cd src/services/PocketBaseService && docker build -t pockethost/pocketbase .", "build:hooks": "tsup --target es5 ./src/hooks/src/*.ts -d ./pb_hooks && prettier -w \"./pb_hooks/*\"", diff --git a/packages/dashboard/package.json b/packages/dashboard/package.json index 30a12b92..4488887a 100644 --- a/packages/dashboard/package.json +++ b/packages/dashboard/package.json @@ -3,6 +3,7 @@ "version": "0.4.1", "private": true, "scripts": { + "check:types": "svelte-check", "preview": "npx http-server@latest ./build -P \"http://localhost:8080?\"", "dev": "DEBUG=1 source ../../.env && vite dev --force", "build": "vite build", @@ -45,6 +46,7 @@ "@types/d3-scale": "^4.0.3", "@types/d3-scale-chromatic": "^3.0.0", "@types/js-cookie": "^3.0.2", - "@types/marked": "^4.0.8" + "@types/marked": "^4.0.8", + "svelte-check": "^3.5.2" } } diff --git a/packages/dashboard/src/global.d.ts b/packages/dashboard/src/global.d.ts index cb469ed8..45071171 100644 --- a/packages/dashboard/src/global.d.ts +++ b/packages/dashboard/src/global.d.ts @@ -1,4 +1,5 @@ import type { Tooltip } from 'bootstrap' +import 'vite/client' declare global { interface Window { diff --git a/packages/dashboard/tsconfig.json b/packages/dashboard/tsconfig.json index 73be5333..13901910 100644 --- a/packages/dashboard/tsconfig.json +++ b/packages/dashboard/tsconfig.json @@ -4,8 +4,11 @@ "baseUrl": "", "allowJs": true, "checkJs": true, + "preserveValueImports": false, + "importsNotUsedAsValues": "preserve", "esModuleInterop": true, "forceConsistentCasingInFileNames": true, + "noUncheckedIndexedAccess": true, "resolveJsonModule": true, "skipLibCheck": true, "sourceMap": true, @@ -16,7 +19,10 @@ "$src/*": ["./src/*"] }, "types": ["./src/global.d.ts"] - } + }, + "include": ["src/*"], + "exclude": ["node_modules", "**/node_modules/*"] + // Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias // // If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes