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

Fix bad developer experience due to Husky pre-commit hooks #20246

Closed
HonkingGoose opened this issue Feb 6, 2023 · 13 comments · Fixed by #22294
Closed

Fix bad developer experience due to Husky pre-commit hooks #20246

HonkingGoose opened this issue Feb 6, 2023 · 13 comments · Fixed by #22294
Assignees
Labels
priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others status:in-progress Someone is working on implementation type:refactor Refactoring or improving of existing code

Comments

@HonkingGoose
Copy link
Collaborator

HonkingGoose commented Feb 6, 2023

Describe the proposed change(s).

Currently

Right now we use husky to run this script before each git commit:

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"


yarn lint-staged
yarn ls-lint


BRANCH_NAME=$(git branch --show-current)


if [ "$BRANCH_NAME" = "main" ]; then
  echo
  echo "Aborting commit."
  echo "You're committing to the main branch, usually this is not what you want to do."
  echo "Did you forget to make a new feature branch to put your work on?"
  echo
  echo "Use git checkout -b <new_branch> to create a new feature branch."
  echo
  echo "If you're sure you want to commit to the main branch, run git commit with the --no-verify flag."
  echo


  exit 1
fi

The pre-commmit hook running the linters adds friction, for example:

  1. Write new code for problem
  2. Try to create commit -> Husky runs linters -> Prettier error
  3. Run Prettier to fix formatting
  4. Create in-between commit
  5. Try another approach -> try to commit -> husky complains again -> fix code -> commit
  6. And so on

This friction can stop people from becoming regular contributors, or just plain be annoying for the maintainers.

So here are some options to fix the problem, let's discuss! 😄

Option 1: drop yarn lint-staged and yarn ls-lint commands

Maybe we want to drop the yarn lint-staged and yarn ls-lint commands, and let our CI tests on the PR branch catch those errors. We keep the check to prevent wrong pushes to main.

Option 2: use pre-push commit instead

We keep the current script, but change when it runs. When you run the script before git push you can commit "badly" as often as you want. But when it's time to push you need to clean up your work before pushing it to the PR branch.

If we do this option, we should change the log message for the script so it uses "pushes to main" instead of "committing to main". 😉

Option 3: drop husky fully

I don't think this is a good idea, most every commit should land into main via a PR, so that all the tests are run first. Only in rare cases do we want a maintainer to push to main directly.

@HonkingGoose HonkingGoose added type:refactor Refactoring or improving of existing code status:requirements Full requirements are not yet known, so implementation should not be started priority-5-triage labels Feb 6, 2023
@viceice
Copy link
Member

viceice commented Feb 6, 2023

🤔 prettier shouldn't complain, it should normally just fix the issue.

developers should also use a good idea, which shows lint Errors while you type. like free vscode.

for a maintainer it's more work to review and request changes because of failed prettier.

@HonkingGoose
Copy link
Collaborator Author

HonkingGoose commented Feb 6, 2023

Some more background information. We tried fixing bad stuff on the contributors' PR branches automatically, for more context read the issue and PR:

Summary: we rejected the PR to auto-fix stuff. This is because of security concerns with using pull_request_target in the GitHub Action workflow.

@rarkins
Copy link
Collaborator

rarkins commented Feb 6, 2023

I prefer 2 or 3.

The commit linting takes too long today.

@HonkingGoose
Copy link
Collaborator Author

HonkingGoose commented Feb 13, 2023

I prefer 2 or 3.

You were happy with my PR to "block accidental pushes to main" to the Husky checks:

This is a great idea. I shouldn't commit to main very often anyway so having to do it with a manual flag is fine. Let's make sure the error message is useful and wouldn't discourage any first time contributor to give up. 1

Related PR:

If you go with option 3 we also drop the check for commits/pushes to main, do you really want that? Did something change in the meantime, where you would maybe rather have no husky checks at all? Or do you no longer care about preventing accidental pushes to main? I'm trying to get a feel for the reasoning behind the choices. 😉

Footnotes

  1. https://github.com/renovatebot/renovate/issues/11091#issuecomment-892557775

@rarkins
Copy link
Collaborator

rarkins commented Feb 13, 2023

Not pushing to main is good. Perhaps it's more about the time it takes rather than whether it's on or off?

@HonkingGoose
Copy link
Collaborator Author

I think the big thing is that we need to decide who to bother with the time loss:

  • Linters run locally: contributor gets the time loss
  • Linter run on GitHub: contributor gets to do something else, but maintainers get bothered by failed lints

@rarkins
Copy link
Collaborator

rarkins commented Feb 14, 2023

I think unfortunately the linting is too slow right now. If it were maybe <5s, it might be manageable

@viceice
Copy link
Member

viceice commented Feb 16, 2023

it's probably the markdown lint which always scans all files. 🤔

maybe it's eslint because of the circular dep check i added some time ago.

@HonkingGoose HonkingGoose added priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others and removed priority-5-triage labels Feb 18, 2023
@HonkingGoose
Copy link
Collaborator Author

Not pushing to main is good.

GitHub can now block direct pushes when you have required workflows: 1

Blocking direct push: Direct pushes are now blocked on branches of the repositories where required workflows are enforced. To push to a branch where required workflows are enforced at the organizational level, create a pull request to make the necessary changes. If you want to allow direct pushes for a particular repository, you must remove the repository as a target from respective required workflows.

Does this mean that we can drop the part of the Husky script that blockes pushes to main? The feature is still in beta, and I don't know if we enabled it yet.

Footnotes

  1. GitHub Blog about GitHub Actions – Required workflows improvements

@rarkins
Copy link
Collaborator

rarkins commented Mar 13, 2023

GitHub can now block direct pushes when you have required workflows

I don't think that will stop users from committing to their own main branch

@HonkingGoose
Copy link
Collaborator Author

Oh yeah. Let's keep that check then. 🙂

@rarkins
Copy link
Collaborator

rarkins commented May 18, 2023

See #22224 (comment)

lint-staged is ESM-only and now causing problems

rarkins added a commit that referenced this issue May 18, 2023
@rarkins rarkins self-assigned this May 18, 2023
@rarkins rarkins added status:in-progress Someone is working on implementation and removed status:requirements Full requirements are not yet known, so implementation should not be started labels May 18, 2023
@renovate-release
Copy link
Collaborator

🎉 This issue has been resolved in version 35.95.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others status:in-progress Someone is working on implementation type:refactor Refactoring or improving of existing code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants