Skip to content

Conversation

ldez
Copy link
Member

@ldez ldez commented Mar 18, 2024

This PR adds a new command config verify.

This command allows to verify a configuration file against a JSON Schema.

The JSON schema is obtained based on this approach:

  • there is a version -> it uses https://golangci-lint.run/jsonschema/golangci.v<major>.<minor>.jsonschema.json
  • there is a commit hash/revision -> it uses https://raw.githubusercontent.com/golangci/golangci-lint/<commit>/jsonschema/golangci.next.jsonschema.json
  • there is no valid information -> error

The make target website_copy_jsonschema has been modified to create https://golangci-lint.run/jsonschema/golangci.v<major>.<minor>.jsonschema.json.

Fixes #2645


Why we will not use JSON Schema to validate .golangci.reference.yml or .golangci.next.reference.yml?

.golangci.reference.yml and .golangci.next.reference.yml are invalid by nature: they contain the exhaustive list of options but those options can be incompatible.

$ go run ./cmd/golangci-lint config verify -c .golangci.next.reference.yml --schema ./jsonschema/golangci.next.jsonschema.json
jsonschema: linters-settings.goheader does not validate with /properties/linters-settings/properties/goheader/oneOf: valid against schemas at indexes 0 and 1
jsonschema: linters-settings.custom.example does not validate with /properties/linters-settings/properties/custom/patternProperties/%5E.%2A$/oneOf: valid against schemas at indexes 0 and 1

Same thing for the configuration loading:

$ go run ./cmd/golangci-lint run -c .golangci.next.reference.yml                                       
ERRO [linter] thelper: at least one option must be enabled 
exit status 3

How many versions of the JSON schema we will support?

The build of golangci-lint using a specific official commit will use the schema related to its commit (https://raw.githubusercontent.com/golangci/golangci-lint/<commit>/jsonschema/golangci.next.jsonschema.json).

For the "real" versions, for now, we will support only the current stable version.

The system has been made to support more versions if needed: if a schema is inside the directory jsonschema/ it will be published as the other schema.
If we want to follow this way, I think we should limit the support to the 2 latest stable versions.

Why we don't embed the JSON Schema?

The usage of remote JSON schema allows us to fix the schema without releasing golangci-lint.

I think IDEs or text editors, that use JSON schema, will be always better than a command line to quickly identify syntax errors.
It is not worth to increase the binary size only for a niche.

@ldez ldez added enhancement New feature or improvement area: CLI Related to CLI area: JSON schema labels Mar 18, 2024
@ldez ldez added this to the next milestone Mar 18, 2024
@ldez ldez force-pushed the feat/verify-cmd branch 7 times, most recently from 335820d to 38b7222 Compare March 19, 2024 01:06
@ldez
Copy link
Member Author

ldez commented Mar 19, 2024

@Antonboom do you have an opinion about this one?

@ldez ldez force-pushed the feat/verify-cmd branch from 38b7222 to 060b3e9 Compare March 19, 2024 13:52
@ldez ldez force-pushed the feat/verify-cmd branch from 060b3e9 to 18cea9f Compare March 19, 2024 15:42
@alexandear alexandear self-requested a review March 19, 2024 17:10
Copy link
Contributor

@Antonboom Antonboom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Antonboom do you have an opinion about this one?

🙏 I try to review as soon as possible

Let's consider the feature with validator in golangci website, like

@ldez
Copy link
Member Author

ldez commented Mar 19, 2024

Let's consider the feature with validator in golangci website

Before doing that the website should be changed.
I'm not sure about the additional value for golangci-lint: the links you provided are mainly related to tools that users don't have on their computers. golangci-lint is installed and runs on computers.

🙏 I try to review as soon as possible

Sorry, I never know if anyone has seen a PR or not, so I friendly ping, I don't want to be too pushy.

@ldez ldez merged commit eaafdf3 into golangci:master Mar 19, 2024
@ldez ldez deleted the feat/verify-cmd branch March 19, 2024 20:35
@ldez ldez mentioned this pull request Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: CLI Related to CLI area: JSON schema enhancement New feature or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Verify the .golangci.yaml config
3 participants