golangci-lint icon indicating copy to clipboard operation
golangci-lint copied to clipboard

config file json schema

Open zepatrik opened this issue 3 years ago • 21 comments

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

zepatrik avatar Oct 15 '20 22:10 zepatrik

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

boring-cyborg[bot] avatar Oct 15 '20 22:10 boring-cyborg[bot]

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.

pierrre avatar Nov 03 '20 14:11 pierrre

Hm right, seems like I missed that. Feel free to fix it in the schema store, they respond quickly

zepatrik avatar Nov 03 '20 14:11 zepatrik

one more place to update after any changes in the configurations

SVilgelm avatar Jan 11 '21 01:01 SVilgelm

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.

zepatrik avatar Jan 11 '21 09:01 zepatrik

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.

SVilgelm avatar Jan 11 '21 15:01 SVilgelm

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?).

zepatrik avatar Jan 11 '21 16:01 zepatrik

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

  1. to fork schema repo to @golangci org
  2. see what can be automated while updating it manually ( govet analyzers, go-critic rules, etc)

Thoughts?

butuzov avatar Jan 13 '21 05:01 butuzov

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.

zepatrik avatar Jan 13 '21 08:01 zepatrik

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?

butuzov avatar Jan 13 '21 08:01 butuzov

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?

zepatrik avatar Jan 13 '21 09:01 zepatrik

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)

butuzov avatar Jan 13 '21 13:01 butuzov

Nice, we can definitely work on that together. Feel free to ping me at any point ;).

zepatrik avatar Jan 13 '21 13:01 zepatrik

@butuzov @zepatrik sure, do anything you need

SVilgelm avatar Jan 13 '21 15:01 SVilgelm

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?

AlekSi avatar Aug 09 '21 11:08 AlekSi

hello @AlekSi this point is explained here: https://github.com/golangci/golangci-lint/pull/1749#issuecomment-782673828

ldez avatar Aug 09 '21 12:08 ldez

@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?

AlekSi avatar Aug 09 '21 13:08 AlekSi

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.

ldez avatar Aug 09 '21 14:08 ldez

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.

butuzov avatar Jan 20 '22 07:01 butuzov

I just have a problem with schema:

image image

nsemikov avatar Oct 13 '23 14:10 nsemikov

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 :(

bifshteks avatar Dec 26 '23 21:12 bifshteks

Would also love to see this

trajan0x avatar Mar 10 '24 11:03 trajan0x

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.

ldez avatar Mar 11 '24 19:03 ldez