From 00b362ab60ead4588d99d141978679b615922fc0 Mon Sep 17 00:00:00 2001 From: M-Scott-Lassiter Date: Tue, 26 Apr 2022 14:55:47 -0700 Subject: [PATCH] build: configure lint-staged and pre-commit hook Adds a Husky pre-commit hook that runs lint-staged, which has been configured to run 'lint' and 'format' on the file types specified in .lintstagedrc. This helps the developer by only running the lint and format scripts on files they have changed and staged, and keeps unlinted and unformatted commits out of the code base. Resolves: #26 --- .husky/pre-commit | 1 + .lintstagedrc | 3 ++- package-lock.json | 2 +- package.json | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 939418c..51e5b62 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,5 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" +npx lint-staged exit 1 \ No newline at end of file diff --git a/.lintstagedrc b/.lintstagedrc index 8e54a1e..510bb91 100644 --- a/.lintstagedrc +++ b/.lintstagedrc @@ -1,3 +1,4 @@ { - "*.(js|ts)": "eslint --fix" + "*.{js,ts}": ["npm run lint"], + "**/*.{js,jsx,ts,tsx,json,html,css,scss,md}": ["npm run format"] } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index cf0bffa..ee69b5d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,7 @@ "eslint-plugin-import": "^2.26.0", "eslint-plugin-jest": "^26.1.4", "eslint-plugin-prettier": "^4.0.0", - "husky": "^7.0.0", + "husky": "^7.0.4", "jest": "^27.5.1", "lint-staged": "^12.4.1", "markdown-toc": "^1.2.0", diff --git a/package.json b/package.json index e4baf47..8ecea23 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "eslint-plugin-import": "^2.26.0", "eslint-plugin-jest": "^26.1.4", "eslint-plugin-prettier": "^4.0.0", - "husky": "^7.0.0", + "husky": "^7.0.4", "jest": "^27.5.1", "lint-staged": "^12.4.1", "markdown-toc": "^1.2.0", @@ -68,7 +68,7 @@ }, "husky": { "hooks": { - "pre-commit": "npm run test && exit 1" + "pre-commit": "npx lint-staged" } } }