question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[style] automate reformatting with pre-commit hooks

See original GitHub issue

šŸš€ Feature request

I was just reading how make style can be automated with pre-commit hooks. Noticing how often I run and even more often forget to run make style before committing, perhaps others are in the same boat - and therefore I thought to propose to the dev community to (mostly) automate this process. The only cons is that each dev will still have to run pre-commit install once after cloning the project. This is a security feature of git, so it won’t run anything automatically unless you take action to enable such thing.

If I understand it correctly, if an individual dev doesn’t run pre-commit install inside the repo, things are just as normal as they are now. That dev will just run make style manually. i.e. the proposed feature is optional for those who want it.

I read about it here, please scroll down to the section: ā€œBlack as a Git pre-commit hookā€. And it links to the whole detailed website: https://pre-commit.com/

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
sguggercommented, Sep 2, 2020

I personally wouldn’t like having a pre-commit hook change all my commits without me being able to see the end result. On my setup, I have a pre-push hook that aborts a push if make quality fails. I think if we had an install script, we could handle both options?

1reaction
stas00commented, Mar 12, 2022

Even though I originally created this thread 1.5 years later I now agree with @sgugger, that I don’t want format changes done while pushing - I need to see what has been changed since sometimes the autoformatter messes things up badly and I need to rewrite things to make the end result readable.

If this can be done as an option and not a requirement then I’m not against it, but there needs to be a way to validate/reformat files before git is involved.

BTW, precommit can be run manually as well and not via git, which doesn’t require pre-commit install:

pre-commit run --all-files

And we have 2 ways to reformat files: fixup (fast - only modified files) - style (slow)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Automate Your Coding Style With Pre-Commit
Flake8 is a hook checking that the code format is compliant with PEP8. Trim-Trailing is a hook detecting extra whitespaces. Here the YAML...
Read more >
Automatically format and lint code with pre-commit - Interrupt
How to use pre-commit for automated linting, formatting, and styling firmware code by using Python, clang-format, clang-tidy, and prettier.
Read more >
Git Pre-commit Hooks for Automatic Python Code Formatting
Pre -commit hooks are helpful git scripts that run automatically before a git commit. If a pre-commit hook fails, the git push will...
Read more >
Pre-commit Hook - Prettier
You can use Prettier with a pre-commit tool. This can re-format your files that are marked as ā€œstagedā€ via `git add` before you...
Read more >
Automatic Code Formatting with Git Hooks - Stage Right Labs
There are two primary options available to us: 1) We can configure our code editor to format code automatically, or 2) We can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found