From 27a82412f3f7341a7a7d4898cbac1efb1addecbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=A2=E6=9E=9C=E6=B1=81?= Date: Mon, 30 Jan 2023 18:16:47 +0800 Subject: [PATCH] Fix/format (#945) * build: add husky hook for pre-commit * fix: code format * fix: change lint-staged only used by prettier * revert: code format * build: remove script husky-hook * ci: fix npm7 run scripts bug --- .github/workflows/main.yml | 2 +- .husky/pre-commit | 4 ++++ package.json | 13 +++++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100755 .husky/pre-commit diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5839a123f..a13a97238 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,7 +24,7 @@ jobs: key: lock-${{ github.sha }} - name: create package-lock.json - run: npm i --package-lock-only + run: npm i --package-lock-only --ignore-scripts - name: hack for singe file run: | diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 000000000..cf0c46b93 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +npx --no-install lint-staged diff --git a/package.json b/package.json index 80a968d1c..cdfb945a8 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,8 @@ "prepublishOnly": "npm run compile && np --no-cleanup --yolo --no-publish", "lint": "eslint src/ --ext .tsx,.ts", "lint:tsc": "tsc -p tsconfig.json --noEmit", - "now-build": "npm run docs:build" + "now-build": "npm run docs:build", + "prepare": "husky install" }, "peerDependencies": { "react": ">=16.9.0", @@ -74,8 +75,10 @@ "father": "^4.0.0", "gh-pages": "^3.1.0", "glob": "^7.1.6", + "husky": "^8.0.3", "immutability-helper": "^3.0.0", "less": "^3.10.3", + "lint-staged": "^13.1.0", "np": "^7.0.0", "prettier": "^2.0.1", "rc-animate": "^3.0.0", @@ -93,5 +96,11 @@ "regenerator-runtime": "^0.13.7", "styled-components": "^5.0.1", "typescript": "^4.8.4" + }, + "lint-staged": { + "**/*.{js,jsx,tsx,ts,md,json}": [ + "prettier --write", + "git add" + ] } -} +} \ No newline at end of file