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

Use Husky pre-push hooks to run linters #1215

Open
anubh-v opened this issue Apr 5, 2020 · 6 comments
Open

Use Husky pre-push hooks to run linters #1215

anubh-v opened this issue Apr 5, 2020 · 6 comments

Comments

@anubh-v
Copy link
Contributor

anubh-v commented Apr 5, 2020

There are often cases when we:

  • Push our work to our remote repo
  • Realise the CI checks failed due to a code style issue
  • Resolve the style issues locally and push to the remote repo again

This process can be avoided if we automatically run the linters before git push is executed.
We can use a git hook for this

@anubh-v
Copy link
Contributor Author

anubh-v commented Apr 11, 2020

@JYLee-GIT @fzdy1914 what do you think about this suggestion?

@dcshzj
Copy link
Member

dcshzj commented Mar 26, 2021

Let's abandon this. I think that it is better if such errors appear on GitHub itself instead of locally as a Git hook, so that it is easier for senior developers to guide newcomers if necessary. In other cases, code style issues are minor and does not affect the review workflow.

Having this hook requires writing a custom script which adds additional maintenance burden.

@gerhean
Copy link
Contributor

gerhean commented Mar 29, 2021

Pretty sure that when code style issues are detected the CI tests would just fail, and senior developers usually do not look at PR with failed tests. I think a hook which checks for code style would be nice since if I forgot to run the linter before I push, I get reminded of my mistakes immediately instead of 5min later when the CI fails.

@damithc
Copy link
Collaborator

damithc commented Mar 29, 2021

We don't use this technique in our other projects. Which means we can survive without it. But I don't mind giving it a try just to see how it goes. There might be some value if not a lot. Let's keep it, but with a low priority.

@dcshzj dcshzj moved this to For existing developers in RepoSense Roadmap Aug 22, 2022
@yhtMinceraft1010X
Copy link
Contributor

I think one possible reason why this issue is relevant is because of the different abstraction level for Run environmental checks in integration.yml compared to other linters:

- name: Run environmental checks
run: ./config/gh-actions/run-checks.sh

Most other linters are run in Gradle (lintFrontend and checkstyleAll), so developers are likely to forget about the existence of (and need to run) ./config/gh-actions/run-checks.sh. If we make it a Gradle task (and mention it in the Developer Guide), developers are more likely to know about this particular check.

@ckcherry23
Copy link
Member

Considering the adoption of git hooks in other NUS-OSS projects like MarkBind and CATcher, it's worth exploring implementing pre-commit and pre-push hooks in RepoSense for linting. Notably, Markbind uses the pre-commit package and CATcher uses Husky for this. Considering that Husky (1) is actively maintained, (2) is the more popular tool, and (3) has easier configuration scripts, let us introduce Husky pre-push hooks to lint (and auto-fix) code in RepoSense.

Furthermore, if we only want to run the linters on staged files, we can make use of lint-staged.

Source: npm trends for git hook packages

@ckcherry23 ckcherry23 changed the title Consider using a git hook to run the linters before git push is executed Use Husky pre-push hooks to run linters May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: For developers
Development

No branches or pull requests

6 participants