golangci-lint
golangci-lint copied to clipboard
config file json schema
Is your feature request related to a problem? Please describe.
I have written a JSON Schema for golangci-lint's config file. Maybe someone can check or even improve it? Some of the descriptions could be improved upon also :wink: https://github.com/SchemaStore/schemastore/pull/1312
This will enable autocompletion, tooltips and validation in IDEs like VSCode or JetBrains.
Describe the solution you'd like
A second (or even more) pair of eyes to check the schema. Maybe you have some example config files that the schema can be tested against.
I can also add a PR in this repository to add the schema. In other projects I already utilize documentation generation of pages like your https://golangci-lint.run/usage/configuration/#config-file page from the schema.
Describe alternatives you've considered
Just add it as is to the schemastore.
Additional context
One of the auto generated docs pages from one of my projects: https://www.ory.sh/kratos/docs/reference/configuration
Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.
Hello !
It seems to be used by vscode, and it's reporting an issue for me.
The field linters-settings.depguard.packages-with-error-message
should be an array of objects, not an object.
Hm right, seems like I missed that. Feel free to fix it in the schema store, they respond quickly
one more place to update after any changes in the configurations
That's why I suggested to take the json schema as the single source of truth and render the documentation from that. In JSONSchemaStore you can also point the schema to a different place, so it would always be fetched from this repo. But if nobody responds whether this is something you would merge I can't do anything about that, sorry.
I mean, if we can make all update automatically, then yes, let's do it. Any PRs are welcome. But right now the only source of true is go code, so it would be great to keep it and generate the json scheme from go code.
I don't know of any project that would do that, but I will have a look. But https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml is manually maintained right? I could auto generate that from the schema, so there are still two places to update. Will draft something in the next days then. Validation within the config package would be way easier with the schema (it looks like many values are not validated at all?).
I was searching for this issue yesterday but haven't found it. @zepatrik nice job you did, even with depguard bothering :).
I have updated yesterday a list of govet analyzers, but now its complaining on go-critic checks ;)
What i would suggest is
- to fork schema repo to @golangci org
- see what can be automated while updating it manually ( govet analyzers, go-critic rules, etc)
Thoughts?
We can just host the schema in this repo and point the schemastore to it, then automate stuff in this repo. That's what I have done with other projects and would propose for this one as well. It worked great so far. All the IDEs take the schemas from schemastore, so we have to bring it back there somehow.
I like this idea more. Can you provide an example or steps I/we/team needs to do in order to host schema in our repository?
This schema: https://github.com/ory/kratos/blob/master/.schema/version.schema.json (which again maps to the correct schema by version) was added by: https://github.com/SchemaStore/schemastore/pull/1173 Then we auto-generate this docs page: https://www.ory.sh/kratos/docs/reference/configuration from that using this script: https://github.com/ory/kratos/blob/master/docs/scripts/config.js which we can do here in the exact same way to generate this file: https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml
Sounds good?
it does!
@SVilgelm can I assign this to myself?
(I can work on this with slow pace, considering huge amount of work done by @zepatrik)
Nice, we can definitely work on that together. Feel free to ping me at any point ;).
@butuzov @zepatrik sure, do anything you need
The field linters-settings.depguard.packages-with-error-message should be an array of objects, not an object.
The field linters-settings.depguard.packages-with-error-message should be an array of objects, not an object.
The golangci-lint code is not clear about it:
- An array of objects: https://github.com/golangci/golangci-lint/blob/a07b1fa26b5ea8cb4840dcb4db0c5fbe54604308/.golangci.yml#L9
- An array of objects: https://github.com/golangci/golangci-lint/blob/a07b1fa26b5ea8cb4840dcb4db0c5fbe54604308/.golangci.example.yml#L424
- Object: https://github.com/golangci/golangci-lint/blob/a07b1fa26b5ea8cb4840dcb4db0c5fbe54604308/test/testdata/configs/depguard.yml#L7
- Object (?): https://github.com/golangci/golangci-lint/blob/6c295e404247459f9b5e0f50c587f60e2f467ac1/pkg/config/linters_settings.go#L152
And why is that an array of single field objects? What's the point?
hello @AlekSi this point is explained here: https://github.com/golangci/golangci-lint/pull/1749#issuecomment-782673828
@ldez Thank you. Can golangci-lint use https://pkg.go.dev/github.com/spf13/viper#KeyDelimiter (viper.KeyDelimiter("::")
) as suggested in https://github.com/spf13/viper/issues/324, https://github.com/spf13/viper/issues/977, and other issues?
For golangci-lint, the change of the separator produces side effects. I don't think we have to fix something, because it's a minor problem.
I spend some time pocking around json schema of golangci-lint
recently. Changes already should be available to everyone. Please let me know if anything you see in .golangci.yml
validated correctly.
I have added or updated most of the new linters settings.
I just have a problem with schema:
It would be really nice to have a config schema always up-to-date. It seems as a good idea to at least validate all the configurations used as examples in documentation against currently published schema in CICD. It becomes frustrating when you setting up your config using examples from docs, but linter says that some parameter does not exist :(
Would also love to see this
Hello,
With PR #4457, the documentation only displays linters and settings related to the current stable version.
The JSON schema follows this stable version.
Currently, we cannot generate the schema from the code because:
- large and "dynamic" enums (e.g. more than 110 linters, linter rules, etc.)
- some linter configurations are just raw maps
- some elements need to be defined by hand because there is no easy reference.
But, there are again possible improvements that we will try to add.