adrienverge / yamllint

A linter for YAML files.
GNU General Public License v3.0
2.86k stars 273 forks source link

Consider automatically changing the settings based on yaml version #587

Closed SubaruArai closed 1 year ago

SubaruArai commented 1 year ago

Yaml's spec is quite complicated, and has evolved over time.

There are also some confusion around what version yamllint supports (#101), and default config between different yaml versions (#559, #540, #430, #344, #232, #247, #158).

May I suggest to add:

  1. A config key to specify the targeted yaml version e.g. yaml-version: 1.1
  2. Automatically change the default rules based on the yaml version e.g. if ver>=1.2, truthy.check-keys = true
  3. (Optionally) add an option to automatically change rules based on the individual file's directive e.g. if %YAML 1.2, change config to 1.2.2

1 and 2 should be relatively easy, but 3 needs some consideration on how to implement.

Information: yaml spec changelog

adrienverge commented 1 year ago

Hello,

Although it's not 100% accurate, yamllint aims to support the latest version of the YAML specification (1.2.2). I believe that supporting multiple versions based on tags would be complicated, and cumbersome to most users.

PS: I don't see how the issues you pointed out (#559, #540, #430, #344, #232, #247, #158) are related to the YAML spec version.

SubaruArai commented 1 year ago

I believe that supporting multiple versions based on tags would be complicated, and cumbersome to most users.

Fair enough.

I don't see how the issues you pointed out (#559, #540, #430, #344, #232, #247, #158) are related to the YAML spec version.

I thought truthy's intend was to detect potential error between yaml 1.1/1.2 parsers. The example {y: 1, yes: 2, on: 3, true: 4, True: 5} -> {y: 1, true: 5} will only happen in yaml<=1.1 parsers.

adrienverge commented 8 months ago

I thought truthy's intend was to detect potential error between yaml 1.1/1.2 parsers. The example {y: 1, yes: 2, on: 3, true: 4, True: 5} -> {y: 1, true: 5} will only happen in yaml<=1.1 parsers.

@SubaruArai you're right. I've opened https://github.com/adrienverge/yamllint/pull/650 to implement your 3rd suggestion (and while I disagree with the 2nd one, I like the 1st :+1:).