Skip to content

Commit

Permalink
fix: husky and lint-stage work properly when hooks are installed (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
CjHare authored Sep 10, 2021
1 parent 7fd0ea9 commit 8cc50dd
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
8 changes: 6 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"ignorePatterns": ["dist", "typechain"],
"ignorePatterns": [
"dist",
"node_modules",
"typechain"
],
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
Expand All @@ -15,6 +19,6 @@
"rules": {
"no-console": 2,
"prettier/prettier": 2,
"strict" : 2
"strict": 2
}
}
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Ignore artifacts:
node_modules
dist
typechain
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,10 @@ npm run build
npm run test
```

#### Husky Git Commit Hooks
To enable Husky commit hooks to trigger the lint-staged behaviour of formatting and linting the staged files prior
before committing, prepare your repo with `prepare`.

```shell
npm run prepare
```
12 changes: 4 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
"scripts": {
"build": "hardhat compile",
"clean": "hardhat clean",
"lint": "eslint . --ext .ts",
"format": "prettier ./**/*.ts --write",
"lint": "eslint . --ext .ts",
"prepare": "husky install",
"test": "mocha --exit --recursive --require ts-node/register 'test/**/*.test.ts'"
},
"devDependencies": {
Expand Down Expand Up @@ -48,15 +49,10 @@
"dependencies": {
"bunyan": "^1.8.15"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.ts": [
"eslint --cache --fix",
"prettier --write"
"npm run format",
"npm run lint --fix"
]
}
}

0 comments on commit 8cc50dd

Please sign in to comment.