From a10abb535b805f7f01a3306a4aed663c9144f1f0 Mon Sep 17 00:00:00 2001 From: Amith Mohanan Date: Wed, 29 Dec 2021 14:00:11 +0530 Subject: [PATCH] chore(git): `pre-commit` hook to lint & fmt Run `npm i` or `npm up` for this hook to start working. --- .dockerignore | 9 +++++---- .eslintrc.cjs | 6 +++++- .gitignore | 6 +++++- .husky/.gitignore | 1 + .husky/pre-commit | 4 ++++ package.json | 9 ++++++++- 6 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 .husky/.gitignore create mode 100755 .husky/pre-commit diff --git a/.dockerignore b/.dockerignore index 4914fe6fc8..69777fd36b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,12 +1,13 @@ -.git +.git/ .gitignore .env .env.example -.github -.vscode -.prettierrc +.github/ +.vscode/ +.prettierrc.json .prettierignore .eslintrc.cjs +.eslintcache node_modules/ worker/ diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 0f95ec7e72..ff3708162e 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -7,6 +7,7 @@ module.exports = { }, extends: [ + // Google JS Style Guide Rules // See: https://github.com/google/eslint-config-google "google", ], @@ -18,6 +19,9 @@ module.exports = { plugins: ["prettier"], rules: { + // Google JS rules, missing in "eslint-config-google" package + "eqeqeq": ["error", "smart"], + // Rules disabled to avoid conflicts with prettier // See: https://github.com/prettier/eslint-config-prettier "indent": 0, @@ -34,6 +38,6 @@ module.exports = { // Enforces rules from .prettierrc file. // These should be fixed automatically with formatting. // See: https://github.com/prettier/eslint-plugin-prettier - "prettier/prettier": "warn", + "prettier/prettier": "error", }, }; diff --git a/.gitignore b/.gitignore index e7d46aa845..737bb49029 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,8 @@ dist/ node_modules/ worker/ -test/data/cache +test/data/cache/ + package-lock.json # IDE @@ -10,3 +11,6 @@ package-lock.json # Local enviroment variables .env + +# Cache +.eslintcache diff --git a/.husky/.gitignore b/.husky/.gitignore new file mode 100644 index 0000000000..31354ec138 --- /dev/null +++ b/.husky/.gitignore @@ -0,0 +1 @@ +_ diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000000..36af219892 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +npx lint-staged diff --git a/package.json b/package.json index 474595791f..baed8122a2 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "clean": "npm run clean:wrangler", "clean:node": "rm -rf node_modules/ package-lock.json", "clean:wrangler": "rm -rf worker/ dist/", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepare": "husky install" }, "repository": { "type": "git", @@ -33,6 +34,12 @@ "eslint": "^8.5.0", "eslint-config-google": "^0.14.0", "eslint-plugin-prettier": "^4.0.0", + "husky": "^7.0.4", + "lint-staged": "^12.1.4", + "prettier": "2.5.1", "webpack": "^5.65.0" + }, + "lint-staged": { + "*.js": "eslint --cache --fix" } }