Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional Git hook to run lint before pushing #175

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ See our documentation:

### 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 @@ -22,9 +22,13 @@
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write && yarn lint:dependencies && yarn lint:changelog",
"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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer this to be pre-commit. If you separate the commands a little bit, it could run eslint --fix and prettier --write as well, using lint-staged. See snaps-monorepo for example.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If changing to pre-commit, maybe we can add a note in README.md on the existence of git commit -n to make onboarding smoother?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely agree with using some kind of mechanism to lint fewer files. That would go a long way in improving the developer experience, I believe, and would possibly remove the concerns I have about using a pre-commit hook. lint-staged requires that you use a .prettierignore file which I'd like to avoid. I figured out some other way of doing this for another project, however, so I'll see if I can find that.

This comment was marked as spam.

},
"devDependencies": {
"@lavamoat/allow-scripts": "^2.0.3",
"@metamask/auto-changelog": "^3.1.0",
Expand All @@ -49,6 +53,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 @@ -64,7 +69,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