From f2022bd23bde08578085ace24eaa656a4d1d56ea Mon Sep 17 00:00:00 2001 From: AbdulSnk Date: Wed, 25 Feb 2026 12:09:10 +0100 Subject: [PATCH] chore/linting-prettier-husky-setup --- .eslintignore | 5 +++++ .eslintrc.json | 9 +++++++-- .husky/pre-commit | 5 +++++ .prettierignore | 8 ++++++++ .prettierrc | 12 ++++++++++++ lint-staged.config.js | 9 +++++++++ package.json | 10 +++++++++- src/eslint.config.mjs | 3 ++- 8 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 .eslintignore create mode 100644 .husky/pre-commit create mode 100644 .prettierignore create mode 100644 .prettierrc create mode 100644 lint-staged.config.js diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..8704216 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,5 @@ +node_modules/ +.next/ +public/ +build/ +coverage/ diff --git a/.eslintrc.json b/.eslintrc.json index 152dc55..50418fb 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,10 +1,15 @@ { "extends": [ "next/core-web-vitals", - "next/typescript" + "next/typescript", + "prettier" + ], + "plugins": [ + "prettier" ], "rules": { "@typescript-eslint/no-unused-vars": "off", - "@typescript-eslint/no-explicit-any": "off" + "@typescript-eslint/no-explicit-any": "off", + "prettier/prettier": "error" } } \ No newline at end of file diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 0000000..449b73e --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,5 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +# Run lint-staged +npx --no -- lint-staged diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..7638067 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,8 @@ +node_modules/ +.next/ +dist/ +build/ +coverage/ +public/ +*.min.js +*.log diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..adac1a2 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,12 @@ +{ + "printWidth": 100, + "tabWidth": 2, + "useTabs": false, + "semi": true, + "singleQuote": true, + "trailingComma": "all", + "bracketSpacing": true, + "arrowParens": "always", + "endOfLine": "lf", + "plugins": [] +} diff --git a/lint-staged.config.js b/lint-staged.config.js new file mode 100644 index 0000000..42f0ada --- /dev/null +++ b/lint-staged.config.js @@ -0,0 +1,9 @@ +module.exports = { + '*.{js,jsx,ts,tsx}': (filenames) => [ + // run eslint --fix on changed files + `eslint --max-warnings=0 --fix ${filenames.join(' ')}`, + // then format with prettier + `prettier --write ${filenames.join(' ')}` + ], + '*.{json,md,css,scss,html}': [`prettier --write ${filenames.join(' ')}`] +}; diff --git a/package.json b/package.json index 44f94c8..591da0a 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,10 @@ "dev": "next dev --turbopack", "build": "next build", "start": "next start", - "lint": "next lint", + "lint": "next lint --max-warnings=0", + "lint:fix": "eslint --ext .ts,.tsx,.js,.jsx . --fix", + "format": "prettier --write .", + "prepare": "husky install", "test": "vitest run", "test:coverage": "vitest run --coverage", "test:ui": "vitest --ui", @@ -65,6 +68,11 @@ "@vitejs/plugin-react-swc": "^3.10.2", "eslint": "^9", "eslint-config-next": "15.3.1", + "eslint-config-prettier": "^8.8.0", + "eslint-plugin-prettier": "^4.2.1", + "prettier": "^2.8.8", + "husky": "^8.0.3", + "lint-staged": "^14.3.0", "fast-check": "^3.22.0", "jsdom": "^26.1.0", "postcss": "^8.5.6", diff --git a/src/eslint.config.mjs b/src/eslint.config.mjs index a20a4ef..8e522a0 100644 --- a/src/eslint.config.mjs +++ b/src/eslint.config.mjs @@ -19,7 +19,8 @@ const eslintConfig = [ "**/form-management/**/*.test.ts", ], }, - ...compat.extends("next/core-web-vitals", "next/typescript"), + // include Prettier at the end to avoid rule conflicts + ...compat.extends("next/core-web-vitals", "next/typescript", "prettier"), { rules: { "@typescript-eslint/no-unused-vars": "off",