Add Git Hooks to run lint (#1788)

* + Add package @arkweid/lefthook

* Add git hook pre-commit for linting changed files only

* Update lefthook.yml about `glob`

Co-authored-by: absidue <48293849+absidue@users.noreply.github.com>

* Update lefthook.yml to use `yarn run` instead of `npx`

Co-authored-by: absidue <48293849+absidue@users.noreply.github.com>

Co-authored-by: absidue <48293849+absidue@users.noreply.github.com>
This commit is contained in:
PikachuEXE 2022-08-12 11:41:32 +08:00 committed by GitHub
parent 180a89d7c6
commit ba0bcee2fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 0 deletions

46
lefthook.yml Normal file
View File

@ -0,0 +1,46 @@
# Refer for explanation to following link:
# https://github.com/evilmartians/lefthook/blob/master/docs/full_guide.md
pre-commit:
parallel: true
commands:
lint:
# Only runs when any file with filename
# matching the glob is being committed
glob: "*.{js,vue}"
run: yarn run eslint --no-color {staged_files}
# EXAMPLE USAGE
#
# pre-push:
# commands:
# packages-audit:
# tags: frontend security
# run: yarn audit
# gems-audit:
# tags: backend security
# run: bundle audit
#
# pre-commit:
# parallel: true
# commands:
# eslint:
# glob: "*.{js,ts}"
# run: yarn eslint {staged_files}
# rubocop:
# tags: backend style
# glob: "*.rb"
# exclude: "application.rb|routes.rb"
# run: bundle exec rubocop --force-exclusion {all_files}
# govet:
# tags: backend style
# files: git ls-files -m
# glob: "*.go"
# run: go vet {files}
# scripts:
# "hello.js":
# runner: node
# "any.go":
# runner: go run

View File

@ -84,6 +84,7 @@
"ytsr": "^3.8.0"
},
"devDependencies": {
"@arkweid/lefthook": "^0.7.7",
"@babel/core": "^7.17.10",
"@babel/plugin-proposal-class-properties": "^7.16.7",
"@babel/preset-env": "^7.17.10",

View File

@ -15,6 +15,11 @@
"@jridgewell/gen-mapping" "^0.1.0"
"@jridgewell/trace-mapping" "^0.3.9"
"@arkweid/lefthook@^0.7.7":
version "0.7.7"
resolved "https://registry.yarnpkg.com/@arkweid/lefthook/-/lefthook-0.7.7.tgz#12951b09b955d8054885ffe929aa07a49f39027c"
integrity sha512-Eq30OXKmjxIAIsTtbX2fcF3SNZIXS8yry1u8yty7PQFYRctx04rVlhOJCEB2UmfTh8T2vrOMC9IHHUvvo5zbaQ==
"@babel/code-frame@7.12.11":
version "7.12.11"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.12.11.tgz#f4ad435aa263db935b8f10f2c552d23fb716a63f"