golangci-lint
golangci-lint copied to clipboard
Verify the .golangci.yaml config
Your feature request related to a problem? Please describe.
Crafting the .golangci.yaml can be a little challenging as the config grows or just getting right the first time. For example, I was crafting a config and had my indention off for the linters-settings:
and rather than error'ing, the linter-settings were just not applied.
Describe the solution you'd like.
I propose a verify
command is added to the golangci-lint
CLI tool that will verify the config schema.
Describe alternatives you've considered.
Alternatively, golangci-lint run
could throw an error when the config does not conform to the top-level schema.
Additional context.
No response
Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.
Maybe related to this issue https://github.com/golangci/golangci-lint/issues/1453
I was trying to do this by a separate command, but found problems.
the idea was to use https://github.com/santhosh-tekuri/jsonschema with https://json.schemastore.org/golangci-lint.json (per https://github.com/golangci/golangci-lint/discussions/4247#discussioncomment-7812027)
Example of command
jv -output detailed https://json.schemastore.org/golangci-lint.json ./.golangci.yaml
But https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/golangci-lint.json is not up to date with https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml (missing fields, like output.sort-results
, and I think validations to do not allow properties outside from declared ones). If an automation could be created to update that file on each release from this repo, maybe this idea could be used in verify
command.
Also, if verify
command could check if user is using deprecated linters and is using last release of golangci-lint
, would be awesome!
But https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/golangci-lint.json is not up to date with https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml (missing fields, like output.sort-results, and I think validations to do not allow properties outside from declared ones). If an automation could be created to update that file on each release from this repo, maybe this idea could be used in verify command.
The branch master
is not the latest stable release, it's the current dev branch.
The JSON schema is related to the latest release (v1.55.2).
I update the JSON schema after each release.
https://github.com/SchemaStore/schemastore/pulls?q=is%3Apr+author%3Aldez+is%3Aclosed
Checked the file in the release tag https://github.com/golangci/golangci-lint/blob/e3c2265f4939976874989e159386b3bb7dcf8e1f/.golangci.reference.yml and it really has output.sort-results
, which https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/golangci-lint.json does not have. How is the process of updating this file is SchemaStore/schemastore
repo? I would like to help with it :smile:
It's just a mistake. I fixed the problem https://github.com/SchemaStore/schemastore/pull/3438
The contribution guide to SchemaStore repo is here: https://github.com/SchemaStore/schemastore/blob/master/CONTRIBUTING.md If you create a PR on this repo you can ping me for the review.
@ldez opened a PR with more fixes https://github.com/SchemaStore/schemastore/pull/3440
I will wait you approve it to undraft it
just an update, https://json.schemastore.org/golangci-lint.json is now up to date with last release.
So, the idea of using https://github.com/santhosh-tekuri/jsonschema with https://json.schemastore.org/golangci-lint.json for checking latest release config file is valid. Example
jv -output detailed https://json.schemastore.org/golangci-lint.json ./.golangci.yaml
If this schema could be shipped with each release, we could add similar solution for each release, and not only latest.
A idea for next release is to run this command against https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml prior to release. If can catch missing fields in the schema
Is the issue to be able to verify the .golangci.yaml
config resolved by having a JSON schema (given that it's up to date, which it should be) or do we need to keep this issue open for other reasons?
The issue is about a CLI command to verify the configuration, even if I thing it's better to use JSON schema inside an IDE or text editor, we can do something. It's one of the topic I'm working on, but several steps are required before doing that.