From b0eab230b5b15c28e8e89faaa136f97b25a784fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20J=C3=A4gle?= Date: Fri, 22 Nov 2024 17:52:01 +0100 Subject: [PATCH 1/3] =?UTF-8?q?adds=20Husky=20=F0=9F=90=B6=20for=20pre-com?= =?UTF-8?q?mit=20linting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .husky/pre-commit | 1 + package.json | 4 +++- pnpm-lock.yaml | 12 +++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 .husky/pre-commit diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 000000000..23b9a8065 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1 @@ +pnpm lint:fix diff --git a/package.json b/package.json index 16c59f748..71627c9c6 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,8 @@ "dockerbuild": "docker build -t bolt-ai:development -t bolt-ai:latest --target bolt-ai-development .", "typecheck": "tsc", "typegen": "wrangler types", - "preview": "pnpm run build && pnpm run start" + "preview": "pnpm run build && pnpm run start", + "prepare": "husky" }, "engines": { "node": ">=18.18.0" @@ -101,6 +102,7 @@ "@types/react": "^18.2.20", "@types/react-dom": "^18.2.7", "fast-glob": "^3.3.2", + "husky": "9.1.7", "is-ci": "^3.0.1", "node-fetch": "^3.3.2", "prettier": "^3.3.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 951d1a4ff..f483b57b6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -231,6 +231,9 @@ importers: fast-glob: specifier: ^3.3.2 version: 3.3.2 + husky: + specifier: 9.1.7 + version: 9.1.7 is-ci: specifier: ^3.0.1 version: 3.0.1 @@ -2482,7 +2485,7 @@ packages: resolution: {integrity: sha512-HpGFw18DgFWlncDfjTa2rcQ4W88O1mC8e8yZ2AvQY5KDaktSTwo+KRf6nHK6FRI5FyRyb/5T6+TSxfP7QyGsmQ==} bytes@3.0.0: - resolution: {integrity: sha512-pMhOfFDPiv9t5jjIXkHosWmkSyQbvsgEVNkz0ERHbuLh2T/7j4Mqqpz523Fe8MVY89KC6Sh/QfS2sM+SjgFDcw==} + resolution: {integrity: sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=} engines: {node: '>= 0.8'} bytes@3.1.2: @@ -3382,6 +3385,11 @@ packages: resolution: {integrity: sha512-AXcZb6vzzrFAUE61HnN4mpLqd/cSIwNQjtNWR0euPm6y0iqx3G4gOXaIDdtdDwZmhwe82LA6+zinmW4UBWVePQ==} engines: {node: '>=16.17.0'} + husky@9.1.7: + resolution: {integrity: sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==} + engines: {node: '>=18'} + hasBin: true + iconv-lite@0.4.24: resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==} engines: {node: '>=0.10.0'} @@ -9278,6 +9286,8 @@ snapshots: human-signals@5.0.0: {} + husky@9.1.7: {} + iconv-lite@0.4.24: dependencies: safer-buffer: 2.1.2 From 17d0902d2aba454c4449948410299ec3e45aeaed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20J=C3=A4gle?= Date: Fri, 22 Nov 2024 18:02:21 +0100 Subject: [PATCH 2/3] Add information about the linting pre-commit to the contributions guideline --- CONTRIBUTING.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0f7744ab6..3ec673fc5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -56,6 +56,8 @@ We're looking for dedicated contributors to help maintain and grow this project. - Comment complex logic - Keep functions focused and small - Use meaningful variable names +- Lint your code. This repo contains a pre-commit-hook that will verify your code is linted properly, +so set up your IDE to do that for you! ## Development Setup From ad511db0fe618ba4bc8f3615f104da0ae35fedf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20J=C3=A4gle?= Date: Sat, 23 Nov 2024 10:08:14 +0100 Subject: [PATCH 3/3] Don't fix linting-issues pre-commit I figured that lint:fix might not be the best experience: If there are linting errors and the pre-commit fixes them, those changes will stay in the staging area but will not be automatically commited. Thus, a subsequent pre-commit check would succeed without these changes included. --- .husky/pre-commit | 18 +++++++++++++++++- app/lib/.server/llm/stream-text.ts | 4 ++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 23b9a8065..966a4ad6b 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1 +1,17 @@ -pnpm lint:fix +#!/bin/sh + +echo "🔍 Running pre-commit hook to check the code looks good... 🔍" + +if ! pnpm typecheck; then + echo "❌ Type checking failed! Please review TypeScript types." + echo "Once you're done, don't forget to add your changes to the commit! 🚀" + exit 1 +fi + +if ! pnpm lint; then + echo "❌ Linting failed! 'pnpm lint:check' will help you fix the easy ones." + echo "Once you're done, don't forget to add your beautification to the commit! 🤩" + exit 1 +fi + +echo "👍 All good! Committing changes..." diff --git a/app/lib/.server/llm/stream-text.ts b/app/lib/.server/llm/stream-text.ts index 86e285c10..3ef879219 100644 --- a/app/lib/.server/llm/stream-text.ts +++ b/app/lib/.server/llm/stream-text.ts @@ -1,11 +1,11 @@ // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-nocheck – TODO: Provider proper types -import { streamText as _streamText, convertToCoreMessages } from 'ai'; +import { convertToCoreMessages, streamText as _streamText } from 'ai'; import { getModel } from '~/lib/.server/llm/model'; import { MAX_TOKENS } from './constants'; import { getSystemPrompt } from './prompts'; -import { MODEL_LIST, DEFAULT_MODEL, DEFAULT_PROVIDER, MODEL_REGEX, PROVIDER_REGEX } from '~/utils/constants'; +import { DEFAULT_MODEL, DEFAULT_PROVIDER, MODEL_LIST, MODEL_REGEX, PROVIDER_REGEX } from '~/utils/constants'; interface ToolResult { toolCallId: string;