Skip to content

golangci-lint linters should have an output that is formattable #2648

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

Closed
georgettica opened this issue Mar 16, 2022 · 18 comments
Closed

golangci-lint linters should have an output that is formattable #2648

georgettica opened this issue Mar 16, 2022 · 18 comments
Labels
enhancement New feature or improvement feedback required Requires additional feedback

Comments

@georgettica
Copy link

Your feature request related to a problem? Please describe.

I wanted to get all of the fast linters, and to do that I need to grep the data I retrieve.

Describe the solution you'd like.

I would want the --out-format to be respected here and if it's json it'll output the data in a json struct

if any other data is provided it'll push a warning it cannot parse in that type and continue with the default output.

Describe alternatives you've considered.

  1. keep as is and show grep out of it: possible but not portable
  2. use json: preferred

Additional context.

No response

@georgettica georgettica added the enhancement New feature or improvement label Mar 16, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Mar 16, 2022

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@georgettica
Copy link
Author

Looked at the guide and this is a general question before implementation

@ldez
Copy link
Member

ldez commented Mar 16, 2022

Hello,

Your issue is unclear, can you describe your suggestion a bit more?

@ldez ldez added the feedback required Requires additional feedback label Mar 16, 2022
@georgettica
Copy link
Author

georgettica commented Mar 16, 2022

We could

  1. change printLinterConfigs https://github.com/golangci/golangci-lint/blob/ef928947b59010016d4626566798b2fc21189476/pkg/commands/help.go#L40to recieve also the output format and print according to it
  2. Wrap calls with if statement and print differently based on it
    printLinterConfigs(enabledLinters)

It's just I want to

$ golangci-lint command ... | jq '.[] | select(.speed == "fast")'

@georgettica
Copy link
Author

The implementation of this in the run.go is

func (e *Executor) createPrinter(format string, w io.Writer) (printers.Printer, error) {

And I raised this issue because the flag was also present on this command (run golangci-lint linters --help for information)

@georgettica

This comment was marked as off-topic.

@ldez
Copy link
Member

ldez commented Mar 16, 2022

Why do you want to filter the output of golangci-lint linters --help to get fast linters?

@georgettica
Copy link
Author

I meant that

$ golangci-lint linters --help | grep out-format
      --out-format string              Format of output: colored-line-number|line-number|json|tab|checkstyle|code-climate|html|junit-xml|github-actions (default "colored-line-number")

so the local command has the out-format flag, but it's unused

@ldez
Copy link
Member

ldez commented Mar 16, 2022

Why do you want to filter the output of golangci-lint linters --help to get fast linters?

@georgettica
Copy link
Author

I want to run:

golangci-lint linters --out-format json | jq '.[] | select(.speed == "fast")'

@ldez
Copy link
Member

ldez commented Mar 16, 2022

Why?

@georgettica
Copy link
Author

so I can have a dynamic list of the fast ones and run all of them

@ldez
Copy link
Member

ldez commented Mar 16, 2022

ok so you want the behavior described here: #1909 (comment)

@georgettica
Copy link
Author

so you would say it's better to:

golangci-lint run --no-config --enable-all --fast

or the right permutation that is described in the issue mentioned?

@ldez
Copy link
Member

ldez commented Mar 16, 2022

I suppose because you don't provide a clear context, you want to filter on fast linters to be able to run only fast linters on your CI.
So the configuration file must be used for those linters.
If the --fast flag is able to only run the linters defined in the configuration file that are fast then your problem will be solved.

Note: It's important in an issue to explain the "why" instead of the "how" and provide a clear context, like that we can discuss solutions instead of implementation proposal.

@georgettica
Copy link
Author

sorry I just read the contribution guide, and it didn't allow me the section of "Why do you want this change?"

felt it was directing me to be explicit on the "how"

@georgettica
Copy link
Author

so yes, I wanted to take this command I put up top as a useful one-liner that takes a few seconds to run (based on the codebase)

for obvious reasons having all of these linters may be too much, but this might be something useful to drill down and fix :)

@georgettica
Copy link
Author

I can close this card as the answer is to "use golangci-lint run" as it's where most of the logic is anyways :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement feedback required Requires additional feedback
Projects
None yet
Development

No branches or pull requests

2 participants