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 git pre-commit hook to lint and test staged files #18230

Closed
germain-gg opened this issue Jul 26, 2021 · 16 comments · Fixed by element-hq/element-desktop#1973
Closed

Add git pre-commit hook to lint and test staged files #18230

germain-gg opened this issue Jul 26, 2021 · 16 comments · Fixed by element-hq/element-desktop#1973
Assignees
Labels
A-Developer-Experience A-Testing Testing, code coverage, etc. O-Occasional Affects or can be seen by some users regularly or most users rarely S-Minor Impairs non-critical functionality or suitable workarounds exist T-Enhancement

Comments

@germain-gg
Copy link
Contributor

No description provided.

@jryans
Copy link
Collaborator

jryans commented Jul 26, 2021

Personally, I dislike workflows that add latency to committing, so it would be nice if there's a way to opt-out somehow.

@Palid
Copy link
Contributor

Palid commented Jul 29, 2021

@jryans with husky you can use -n or --no-verify flag while commiting to ignore hooks. Would that be good enough?
Seems setting HUSKY=0 as env variable also works!

@jryans
Copy link
Collaborator

jryans commented Aug 25, 2021

@jryans with husky you can use -n or --no-verify flag while commiting to ignore hooks. Would that be good enough?
Seems setting HUSKY=0 as env variable also works!

Sure, it's good enough for me at least.

I do wonder if there's some way to know how desired this actually is, so we would know if it should be opt-in vs opt-out...

@andybalaam andybalaam added S-Minor Impairs non-critical functionality or suitable workarounds exist T-Enhancement O-Occasional Affects or can be seen by some users regularly or most users rarely labels May 18, 2022
@SimonBrandner SimonBrandner added the A-Testing Testing, code coverage, etc. label Jul 23, 2022
@Johennes
Copy link
Contributor

@vector-im/element-web how do folks feel about this proposal?

@richvdh
Copy link
Member

richvdh commented Oct 24, 2023

pre-commit hooks are strictly opt-in anyway, because they require setup in the local git workdir. So this would amount to a recommendation for contributors rather than anything enforced.

I used a pre-commit hook in Synapse to do some linting. It was often useful. But also I often did --no-verify because I was in a rush.

So generally +1 to making it easy to set up a pre-commit hook.

@germain-gg
Copy link
Contributor Author

Using things like husky do set up the commit hooks automatically.
And using lint-staged runs commands only against staged files, it won't be foolproof but is proven very useful for prettier checks.
I would always argue against doing a full codebase type check, but doing fast and easy linting will definitely alleviate some issues that would otherwise be caught by the slow CI

@richvdh
Copy link
Member

richvdh commented Oct 26, 2023

husky == https://typicode.github.io/husky/, ftr

@Johennes
Copy link
Contributor

We've discussed this in the EW weekly today and concluded that having linting available as a pre-commit hook would be valuable. There was no consensus on also running tests on staged files as that might blow up the hook runtime quite a bit.

To move this forward, we'd like for somebody to set up a commit hook script that triggers the linter on staged files and add documentation on how to install (and skip) it.

@Palid
Copy link
Contributor

Palid commented Oct 26, 2023

Considering that I've been a huge champion on the solution and I'm still getting notifications for it, I'll get it done today within the next few hours. 😄

@Palid
Copy link
Contributor

Palid commented Oct 26, 2023

@t3chguy @Johennes solved by:
matrix-js-sdk: matrix-org/matrix-js-sdk#3835 (1/3)
element-web: #26453 (2/3)
matrix-react-sdk: matrix-org/matrix-react-sdk#11806 (3/3)
elemen-desktop: element-hq/element-desktop#1294 (4/3)

@Palid Palid removed their assignment Oct 26, 2023
@t3chguy
Copy link
Member

t3chguy commented Oct 26, 2023

To close this issue we'll also need to do similar for https://github.com/vector-im/element-desktop/

@t3chguy
Copy link
Member

t3chguy commented Oct 26, 2023

Thanks @Palid for kicking this off

@Palid
Copy link
Contributor

Palid commented Oct 26, 2023

@t3chguy on it!

@Palid
Copy link
Contributor

Palid commented Oct 26, 2023

Will be continued on Monday, unless someone takes over. Some stuff came out.

@Johennes
Copy link
Contributor

@Palid thanks again for kick starting this. Were you still planning on wrapping up those PRs?

@Palid
Copy link
Contributor

Palid commented Nov 22, 2023

@Johennes yeah, just been busy and didn't get pinged 😅
I'll try to get this done today!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Developer-Experience A-Testing Testing, code coverage, etc. O-Occasional Affects or can be seen by some users regularly or most users rarely S-Minor Impairs non-critical functionality or suitable workarounds exist T-Enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants