diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 0000000..d24fdfc --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +npx lint-staged diff --git a/.lintstagedrc.js b/.lintstagedrc.js new file mode 100644 index 0000000..61cb241 --- /dev/null +++ b/.lintstagedrc.js @@ -0,0 +1,10 @@ +const path = require('path'); + +module.exports = { + './src/**/*' : (filenames) => [ + `next lint --fix --file ${filenames + .map((file) => path.relative(process.cwd(), file)) + .join(' --file ')}`, + `yarn prettier --write ${filenames.join(' ')}`, + ], +}; diff --git a/package.json b/package.json index 03113a1..f51cd22 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "dev": "next dev", "build": "next build", "start": "next start --port ${PORT:-3000}", - "lint": "next lint" + "lint": "next lint", + "prepare": "husky install" }, "dependencies": { "@emotion/cache": "^11.9.3", @@ -36,6 +37,8 @@ "eslint": "8.19.0", "eslint-config-next": "12.2.2", "eslint-config-prettier": "^8.5.0", + "husky": "^8.0.0", + "prettier": "^2.7.1", "typescript": "4.7.4" } } diff --git a/yarn.lock b/yarn.lock index 13ab808..d424876 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1460,6 +1460,11 @@ html-tokenize@^2.0.0: readable-stream "~1.0.27-1" through2 "~0.4.1" +husky@^8.0.0: + version "8.0.1" + resolved "https://registry.yarnpkg.com/husky/-/husky-8.0.1.tgz#511cb3e57de3e3190514ae49ed50f6bc3f50b3e9" + integrity sha512-xs7/chUH/CKdOCs7Zy0Aev9e/dKOMZf3K1Az1nar3tzlv0jfqnYtu235bstsWTmXOR0EfINrPa97yy4Lz6RiKw== + ignore@^5.2.0: version "5.2.0" resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.2.0.tgz#6d3bac8fa7fe0d45d9f9be7bac2fc279577e345a" @@ -2020,6 +2025,11 @@ prelude-ls@^1.2.1: resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396" integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g== +prettier@^2.7.1: + version "2.7.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.7.1.tgz#e235806850d057f97bb08368a4f7d899f7760c64" + integrity sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g== + process-nextick-args@~2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"