Automatic fixing by plugins
So there had been a request for this previously (by @joe-gordon0 if my memory is serving me well) but I just cannot find it. I've reached out to GitLab about it (https://twitter.com/sigmavirus24/status/811238094271840261).
I believe the original issue was #84 but that is, for some reason, lost.
tl;dr There is immense interest in having Flake8 provide fixes for the violations it reports in the style of go-fmt, either by doing the fixing in-place or allowing plugins to print out how to apply the fix.
The Problem/Reasoning
Most people use Flake8, presently, to prevent style issues from being introduced and to force collaborators to follow a specific style. People, however, want to begin using Flake8 to just correct that style without human intervention. When Flake8 3.0 was written (from scratch) I implemented the ability for plugins to register and be notified of specific violations happening. The idea was for this architecture to then be utilized for plugins to fix a specific violation for users.
Since then, I've realized that we also need to have the ability to prioritize which violations notify plugins first. On top of that, we need some good interface for plugins to modify a file. For this, I've been looking at RedBaron. The problems with this, right now, are:
- RedBaron is slow (for now)
- Passing around a mutable FST representation might not be the best way of doing this and @ambv has somewhat recommended against it
On top of that, we'll be reimplementing (to a degree) in a far less opinionated manner what Google has already built and it might just be better to collaborate with them to make their system pluggable.
Why make things pluggable?
A lot of PEP-0008 is written ambiguously and allows different styles as "valid". That means that pycodestyle has a lot of things it accepts as valid and just as many it accepts as invalid. Further, that means each person can use a style they prefer and still have it be valid. All of this combined means that if one plugin fixes one style violation one way, people are going to complain it doesn't fix it the way they like. As such, they should be able to swap these out for each other and have it simply work the way they want. There can be 5 ways to not cause Exxx and so there are likely an equal number of people who use each of those 5 ways. If Flake8 said "This is the one way to do it" we'd get so much hatemail that I'd probably quit. I'd rather just let people do what they want than come down with one opinion.