adrienverge / yamllint

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

"string value is redundantly quoted with single quotes" when string is a timestamp #665

Open dorak88783 opened 3 months ago

dorak88783 commented 3 months ago

I have a dependabot.yml file with

schedule:
  interval: daily
  time: "06:00"

The quotes around the time value are really needed, as dependabot expects a string here. Dropping the quotes gives an error

The property '#/updates/0/schedule/time' of type integer did not match the following type: string.

It seems that, without the quote, the field value is parsed as a base-60 integer: https://yaml.org/type/int.html. In theory, dependabot could accept integers as time values, but currently it only accepts string values.

yamllint suggests "string value is redundantly quoted with single quotes", which isn't correct: without the quotes, it would not be a string value.

adrienverge commented 3 months ago

Hello and thanks for the report!

The quotes around the time value are really needed

It depends whether your YAML file is YAML 1.1 or YAML 1.2. With version 1.2, sexagesimal numbers (base 60) like 06:00 or 190:20:30 don't exist anymore, so these resolve to simple strings, hence don't need quotes. If surrounded with quotes, they would be redundantly quoted.

Since yamllint tries to support the newer YAML version (1.2), its current behavior seems appropriate.

However, there is an ongoing effort to make yamllint adaptative depending on the detected YAML version. See for example https://github.com/adrienverge/yamllint/issues/587 and https://github.com/adrienverge/yamllint/pull/650.

To conclude, I see 2 solutions:

  1. Make dependabot YAML parser default to YAML 1.2 by default (so time: 06:00 resolves to a string, not a number).
  2. Enhance yamllint to change behavior depending on the YAML version of the document (would you like to develop such a change?) and start your YAML file with an explicit %YAML 1.1 directive.