From afe2cb978ef4260d88835fc5f62db69164aa2fb2 Mon Sep 17 00:00:00 2001 From: Stig Ofstad Date: Wed, 5 Jun 2024 10:46:09 +0200 Subject: [PATCH] feat: replace prettier and eslint with biome --- .pre-commit-config.yaml | 52 +++++----------------------- api/pyproject.toml | 15 -------- api/src/common/exception_handlers.py | 4 +-- web/.eslintignore | 6 ---- web/.eslintrc.json | 39 --------------------- web/.prettierignore | 6 ---- web/.prettierrc.js | 7 ---- web/biome.json | 34 ++++++++++++++++++ web/package.json | 6 +--- web/vite.config.ts | 4 +-- 10 files changed, 47 insertions(+), 126 deletions(-) delete mode 100644 web/.eslintignore delete mode 100644 web/.eslintrc.json delete mode 100644 web/.prettierignore delete mode 100644 web/.prettierrc.js create mode 100644 web/biome.json diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3321a49d..d16b1659 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,58 +37,22 @@ repos: - id: conventional-pre-commit stages: [commit-msg] - - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: "v0.0.289" + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: "v0.4.7" hooks: - id: ruff - name: Code linting + name: Python format files: ^api/.*\.py$ args: - --fix - - repo: https://github.com/ambv/black - rev: 23.9.1 + - repo: https://github.com/biomejs/pre-commit + rev: v0.2.0 hooks: - - id: black - name: Code formatting - language_version: python3.10 - args: [--config=api/pyproject.toml] - files: ^api/src/.*\.py$ - - - repo: https://github.com/econchick/interrogate - rev: 1.5.0 - hooks: - - id: interrogate - language_version: python3.10 - types: [python] - args: [--config=api/pyproject.toml] - files: ^api/.*\.py$ + - id: biome-check + additional_dependencies: [ "@biomejs/biome@1.8.0" ] + args: ["--config-path", "web"] - - repo: https://github.com/pre-commit/mirrors-prettier - rev: v3.0.3 - hooks: - - id: prettier - files: ^web/src/.*\.(ts|tsx|js|css|html|json)$ - args: - ["--config=web/.prettierrc.js", "--ignore-path=web/.prettierignore"] - - - repo: https://github.com/pre-commit/mirrors-eslint - rev: "v8.49.0" - hooks: - - id: eslint - additional_dependencies: - - eslint - - typescript - - "@typescript-eslint/parser" - - "@typescript-eslint/eslint-plugin" - - eslint-config-prettier # turns off all rules that might conflict with prettier - - eslint-plugin-jsx-a11y # checks accessibility rules on jsx elements - - eslint-plugin-prettier # runs prettier as an eslint rule - - eslint-plugin-react # react specific linting rules - - eslint-plugin-react-hooks # enforces the rules of hooks - files: ^web/src/.*\.[jt]sx?$ # *.js, *.jsx, *.ts and *.tsx - types: [file] - args: ["--config=web/.eslintrc.json", "--ignore-path=web/.eslintignore"] - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.5.1 diff --git a/api/pyproject.toml b/api/pyproject.toml index 643a6023..b9dc8c46 100644 --- a/api/pyproject.toml +++ b/api/pyproject.toml @@ -24,21 +24,6 @@ pre-commit = ">=3" pytest = "^7.2.2" mongomock = "^4.1.2" -[tool.black] -line-length = 119 -target-version = ['py310'] -include = '\.pyi?$' -exclude = ''' -/( - \.eggs - | \.git - | \.hg - | \.mypy_cache - | \.tox - | \.venv -)/ -''' - [tool.interrogate] ignore-init-method = true ignore-init-module = true diff --git a/api/src/common/exception_handlers.py b/api/src/common/exception_handlers.py index 50753093..3e875a33 100644 --- a/api/src/common/exception_handlers.py +++ b/api/src/common/exception_handlers.py @@ -29,8 +29,8 @@ def add_exception_handlers(app: FastAPI) -> None: app.add_exception_handler(MissingPrivilegeException, generic_exception_handler) # Override built-in default handler - app.add_exception_handler(RequestValidationError, validation_exception_handler) - app.add_exception_handler(HTTPStatusError, http_exception_handler) + app.add_exception_handler(RequestValidationError, validation_exception_handler) # type: ignore + app.add_exception_handler(HTTPStatusError, http_exception_handler) # type: ignore # Fallback exception handler for all unexpected exceptions app.add_exception_handler(Exception, fall_back_exception_handler) diff --git a/web/.eslintignore b/web/.eslintignore deleted file mode 100644 index 7395a54b..00000000 --- a/web/.eslintignore +++ /dev/null @@ -1,6 +0,0 @@ -**/gen/* -web/src/api/generated - -build -coverage -web/src/components/TodoApp.tsx diff --git a/web/.eslintrc.json b/web/.eslintrc.json deleted file mode 100644 index 8c4db454..00000000 --- a/web/.eslintrc.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "root": true, - "env": { - "browser": true, - "es2021": true, - "node": true - }, - "extends": [ - "eslint:recommended", - "plugin:react/recommended", - "plugin:react/jsx-runtime", - "plugin:jsx-a11y/recommended", - "plugin:@typescript-eslint/recommended", - "prettier", - "plugin:prettier/recommended" - ], - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaFeatures": { - "jsx": true - }, - "ecmaVersion": "latest", - "sourceType": "module" - }, - "plugins": [ - "react", - "@typescript-eslint", - "react-hooks", - "jsx-a11y", - "prettier" - ], - "rules": { - "react-hooks/rules-of-hooks": "error", - "react-hooks/exhaustive-deps": "warn", - "react/boolean-prop-naming": "warn", - "prettier/prettier": "error", - "@typescript-eslint/ban-ts-comment": "warn" - } -} diff --git a/web/.prettierignore b/web/.prettierignore deleted file mode 100644 index 1b1197cd..00000000 --- a/web/.prettierignore +++ /dev/null @@ -1,6 +0,0 @@ -**/gen/* -src/api/generated - -build -coverage -src/components/TodoApp.tsx diff --git a/web/.prettierrc.js b/web/.prettierrc.js deleted file mode 100644 index 361bbb89..00000000 --- a/web/.prettierrc.js +++ /dev/null @@ -1,7 +0,0 @@ -// default config -module.exports = { - trailingComma: 'es5', - tabWidth: 2, - semi: false, - singleQuote: true, -} diff --git a/web/biome.json b/web/biome.json new file mode 100644 index 00000000..d33463cd --- /dev/null +++ b/web/biome.json @@ -0,0 +1,34 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.8.0/schema.json", + "files": { + "ignore": ["documentation/*", "api/*", "web/src/api/generated"] + }, + "javascript": { + "formatter": { + "indentStyle": "space", + "indentWidth": 2, + "jsxQuoteStyle": "single", + "quoteStyle": "single", + "trailingCommas": "es5", + "lineWidth": 119, + "semicolons": "asNeeded" + } + }, + "json": { + "formatter": { + "indentStyle": "space", + "indentWidth": 2 + } + }, + "linter": { + "rules": { + "a11y": { + "useButtonType": "off" + }, + "correctness": { + "useExhaustiveDependencies": "off", + "noVoidTypeReturn": "off" + } + } + } +} diff --git a/web/package.json b/web/package.json index bda774a7..75d9fada 100644 --- a/web/package.json +++ b/web/package.json @@ -10,11 +10,7 @@ "lint": "yarn eslint --fix --ext .ts,.tsx ." }, "browserslist": { - "production": [ - ">0.2%", - "not dead", - "not op_mini all" - ], + "production": [">0.2%", "not dead", "not op_mini all"], "development": [ "last 1 chrome version", "last 1 firefox version", diff --git a/web/vite.config.ts b/web/vite.config.ts index 03c7b6fe..15581bf5 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -1,8 +1,8 @@ +import react from '@vitejs/plugin-react' import { defineConfig } from 'vite' import checker from 'vite-plugin-checker' -import react from '@vitejs/plugin-react' -import viteTsConfigPaths from 'vite-tsconfig-paths' import svgrPlugin from 'vite-plugin-svgr' +import viteTsConfigPaths from 'vite-tsconfig-paths' export default defineConfig({ plugins: [