Split autoformatters and linters into different workflows and CI jobs
See original GitHub issueStatus quo
Currently we mix formatters and linters with pre-commit
:
formatters
linters
In addition we have a separate CI job that lints with mypy
Proposal
I propose we change the rationale from the two CI jobs from pre-commit
and mypy
to code format and lint. That means, we would only keep autoformatters in our pre-commit
configuration and move all linters to what is currently the mypy
job.
Pros
- We could use
pre-commit
as “single source of truth” for formatting code. Currently they mentioned as “purely optional” in our contribution guide. Sincepre-commit
supports running the hooks manually, we can simply treat it as our way to bundle all autoformatters while the user does not need to know or care what exactly is run. - We could simply add new autoformatters if they are available through
pre-commit
, e.g. #5158. If anyone applies code formatting throughpre-commit
anyway, that won’t break any workflow.
Cons
- We would loose the ability to run linters in a bundled manner. I don’t think this is a strong con, since linters such as
flake8
orpydocstyle
trigger very seldom anyway due to the auto-formatting. Plus, we already need to runmypy
separately.
cc @seemethere
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Split up checks into smaller checks for each linter #7 - GitHub
It looks to me like the natural path here is to use multiple "jobs" inside the GH Actions "workflow" to achieve each linter...
Read more >Automating dbt Development Workflows with Pre-commit
In this tutorial, we'll be using pre-commit as a specific technology to learn more about some of these concepts. This step, combined with...
Read more >Run jobs in parallel with workflows to decrease your build times
Learn how to use parallelism and workflows in your continuous integration and delivery (CI/CD) pipelines on CircleCI to improve efficiency ...
Read more >Advanced Visual Studio Code for Python Developers
In this tutorial, you'll learn how you can configure, extend, and optimize Visual Studio Code for a more effective and productive Python development ......
Read more >Linting and Auto-formatting Ruby Code With RuboCop
Of course, linters and auto-formatters have other benefits, ... also learn how to make it a part of your continuous integration workflow.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
From personal experience the one thing that black doesn’t pick up is
xyz imported but not used
. This happens often when refactoring (or just writing) code.I see value in allowing pre-commits, but I wouldn’t make this mandatory either. It’s just sugar on top of the more low-level tools, and I think it’s important to keep them. To answer a question from @pmeier from another thread https://github.com/pytorch/vision/issues/5168#issuecomment-1007263427
IMHO yes, if only for educational purpose. It’s important that they know what’s happening under the hood, for example to resolve errors more efficiently.
~That is not true~ (EDIT: I missed the word “import” in @datumbox’s statement. I agree, unused imports is one of the few things that
ufmt
will not handle). Especially in combination withusort
, there are very few things that are left for it to pick up. Quoting from our contribution guidelines:It basically comes down to stuff that cannot be fixed automatically, e.g.
from foo import *
.That can’t happen. If you have the hooks installed,
git commit
something, and hook fails, it is as if thegit commit
has never happened. You will see all changes made by the hooks as unstaged changes that you need to manually stage again. Only if no hook fails,git commit
is actually executed.Besides, just using the
pre-commit
framework does not mean you have to use the hooks. You can simply dopre-commit run
, which will execute all formatters on the staged files. If you don’tpre-commit install
, you will have no changes whatsoever to thegit
behavior. Thus, without installing the hooks,pre-commit
basically acts as grouper for all formatters while also handling setting them up in their own environments.