Skip to content

Commit

Permalink
Add optional Git hook to run lint before pushing
Browse files Browse the repository at this point in the history
Say you've completed work on your branch and now you want to create a
pull request, but unbeknownst to you, some code doesn't pass the lint
step. It's nice to address those lint violations now, otherwise you will
end up waiting until CI runs and puts an X on your PR.

Some of us on the Shared Libraries team have been testing using a Git
hook to run the lint step in the `core` repo, and it has been working
well so far, so this commit brings the same idea over. The Git hook runs
before each push, allowing commit creation to remain speedy, and it is a
completely optional part of setting up your development environment. You
can install it by running `yarn sync-git-hooks`.
  • Loading branch information
mcmire committed Feb 15, 2023
1 parent bab6a04 commit 1721174
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ _Add examples here_

### Setup

- Install [Node.js](https://nodejs.org) version 14
- If you are using [nvm](https://github.com/creationix/nvm#installation) (recommended) running `nvm use` will automatically choose the right node version for you.
- Install [Yarn v3](https://yarnpkg.com/getting-started/install)
- Run `yarn install` to install dependencies and run any required post-install scripts
- Install [Node.js](https://nodejs.org) version 16.
- If you're using [NVM](https://github.com/creationix/nvm#installation) (recommended), `nvm use` will ensure that the right version is installed.
- Install [Yarn v3](https://yarnpkg.com/getting-started/install).
- Run `yarn install` to install dependencies and run any required post-install scripts.
- Run `yarn sync-git-hooks` to add a [Git hook](https://github.com/toplenboren/simple-git-hooks#what-is-a-git-hook) which ensures that all files pass lint before you push a commit.

### Testing and Linting

Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write && yarn lint:dependencies",
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern",
"prepack": "./scripts/prepack.sh",
"sync-git-hooks": "simple-git-hooks",
"test": "jest && jest-it-up",
"test:watch": "jest --watch"
},
"simple-git-hooks": {
"pre-push": "yarn lint"
},
"devDependencies": {
"@lavamoat/allow-scripts": "^2.0.3",
"@metamask/auto-changelog": "^3.1.0",
Expand All @@ -48,6 +52,7 @@
"prettier": "^2.7.1",
"prettier-plugin-packagejson": "^2.3.0",
"rimraf": "^3.0.2",
"simple-git-hooks": "^2.8.1",
"ts-jest": "^28.0.7",
"ts-node": "^10.7.0",
"typedoc": "^0.23.15",
Expand All @@ -63,7 +68,8 @@
},
"lavamoat": {
"allowScripts": {
"@lavamoat/preinstall-always-fail": false
"@lavamoat/preinstall-always-fail": false,
"simple-git-hooks": false
}
}
}
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,7 @@ __metadata:
prettier: ^2.7.1
prettier-plugin-packagejson: ^2.3.0
rimraf: ^3.0.2
simple-git-hooks: ^2.8.1
ts-jest: ^28.0.7
ts-node: ^10.7.0
typedoc: ^0.23.15
Expand Down Expand Up @@ -6437,6 +6438,15 @@ __metadata:
languageName: node
linkType: hard

"simple-git-hooks@npm:^2.8.1":
version: 2.8.1
resolution: "simple-git-hooks@npm:2.8.1"
bin:
simple-git-hooks: cli.js
checksum: 920d8b3122a102d4790b511a2f033202511f6a08d5105b4e05f05907d407d99f25490da1037643280d622c1951e0d10abacfbeaee64d5f69f1d0e29cf914141f
languageName: node
linkType: hard

"sisteransi@npm:^1.0.4":
version: 1.0.5
resolution: "sisteransi@npm:1.0.5"
Expand Down

0 comments on commit 1721174

Please sign in to comment.