-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
🌟 Let's talk about "formatters" #5296
Comments
This is great! We like to run gofumpt + gci prior to other linters, since these are reliable and the suggested fixes of other linters require greater scrutiny. |
My idea is to create a This command should work as This is completely different from the Note, this command will not have the same flag option as the
There is no major problem with browsing and formatting all the files (I have a working POC). But there is a need for exclusions and those exclusions should be "compatible" with the current exclusion system as the formatters are also run as linters. So I will need to create a dedicated section This implies:
I don't want to introduce an option that we will deprecate (i.e. This requires creating the new option The conversion will not be Also You may think that creating the I also need to check what is the right name |
Very excited!
After that this in place, there are a few other formatters that might be added that were never in golangci-lint before because they don't act as linters. For instance, https://github.com/segmentio/golines also, gofumpt currently has an environment variable |
FYI I created a local implementation for golines. But I will open a PR after the work on this topic. |
I already have 3 branches for this topic (command, exclude-path, golines), and after more thinking, I need to handle the exclusions section before everything 😢. |
Ok, btw, not sure if plugins will be able to signal that they are formatters so they could be included in this or if that's something separate. |
We should keep things "simple", so no formatters plugins for now, there are enough challenges with the current roadmap of the v2. Maybe, if we are able to have an MRR over 5000€, we will add some items to the roadmap 😸 @StevenACoffman Thank you for your engagement and the donation, I hope that more people will follow this way. I will wait until the end of the month, but if the situation doesn't change, I will have to be more pushy with the sponsorship. For golangci-lint users, if you read this comment:
|
Important
This is a proposal: I don't know if it is possible and what the impact could be inside the code.
The proposal may evolve.
Inside golangci-lint there are 4 "linters" that are not real linters/analyzers but "formatters":
gofmt
,goimports
,gofumpt
, andgci
.Their standard outputs are
[]byte
and notDiagnostic
, internally golangci-lint produces diff patches based on[]byte
and converts them intoDiagnostic
.Also
goimports
andgci
are not "import formatters": they format all the code and not only imports.gofmt
goimports
gofumpt
gci
⛑️ The Problems
Types
The formatters don't require types, but when they are run with other linters that require types, the possibilities of formaters to apply format and fix the code are limited.
Today, for example, you can use the following command to apply the format without being constraint by the other linters:
golangci-lint run --enable-only="gofumpt,goimports" --fix
It works but this is limited.
💭 The Proposal
The idea is to create a dedicated section
formatters
likelinters
(internally they will be used as the other linters).And adds a specific command
fmt
that runs only the formatters defined inside the configuration, like a variant of therun
command but limited to formatters and with "autofix" always enabled, so no reports.It allows us to clarify the difference between the formatters and the linters.
Also, we can set up a dedicated default for this section.
I suggest
goimports
as default because this is an official Go tool, more powerful thangofmt
, and fits the needs of many projects.Enabling all the formatters make no sense as they provide the same base functionality (format) with some variants but their changes could be incompatible (mainly on imports) unless they are run in a specific order and without incompatible settings. So no need for
enable-all
and/or adisable
section.The text was updated successfully, but these errors were encountered: