From 179e9593845763204604cd8738c48b12aa6348f1 Mon Sep 17 00:00:00 2001 From: ren <18050944+renintw@users.noreply.github.com> Date: Tue, 28 Mar 2023 02:59:04 +0800 Subject: [PATCH] Add pre-commit linter hook --- settings/.husky/pre-commit | 5 +++++ settings/package.json | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100755 settings/.husky/pre-commit diff --git a/settings/.husky/pre-commit b/settings/.husky/pre-commit new file mode 100755 index 00000000..597e5a9a --- /dev/null +++ b/settings/.husky/pre-commit @@ -0,0 +1,5 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +cd settings +npx lint-staged diff --git a/settings/package.json b/settings/package.json index 010df8ef..0cfa7e54 100644 --- a/settings/package.json +++ b/settings/package.json @@ -13,7 +13,8 @@ "packages-update": "wp-scripts packages-update", "start": "wp-scripts start --webpack-copy-php", "test:unit": "wp-scripts test-unit-js", - "test:unit:watch": "wp-scripts test-unit-js --watch" + "test:unit:watch": "wp-scripts test-unit-js --watch", + "prepare": "cd .. && husky install settings/.husky" }, "dependencies": { "@automattic/generate-password": "^0.1.0" @@ -27,6 +28,16 @@ "@wordpress/data": "^8.4.0", "@wordpress/element": "^5.4.0", "@wordpress/icons": "^9.18.0", - "@wordpress/scripts": "^24.6.0" + "@wordpress/scripts": "^24.6.0", + "lint-staged": "^13.2.0", + "husky": "^8.0.0" + }, + "lint-staged": { + "*.js": [ + "npm run lint:js" + ], + "*.{css,scss}": [ + "npm run lint:css" + ] } }