Goddard-Fortran-Ecosystem / yaFyaml

Yet Another Fortran YAML
Apache License 2.0
13 stars 8 forks source link

Possibly reject files with trailing spaces? #60

Closed mathomp4 closed 2 years ago

mathomp4 commented 2 years ago

This is something from using yamllint now in some CI in GEOS (e.g., https://github.com/GEOS-ESM/GOCART/pull/164) (which could be added here too).

The CI runs essentially:

yamllint -d relaxed --no-warnings file.yaml

and even in "relaxed" mode, one of the things it returns an error on is "trailing spaces". For example:

❯ yamllint -d relaxed --no-warnings ./Examples/Iterators/iterator.yaml
./Examples/Iterators/iterator.yaml
  15:1      error    trailing spaces  (trailing-spaces)
  16:1      error    trailing spaces  (trailing-spaces)

I'm not exactly sure what triggers this in the YAML spec but perhaps this (emphasis mine):

7.3.3. Plain Style The plain (unquoted) style has no identifying indicators and provides no form of escaping. It is therefore the most readable, most limited and most context sensitive style. In addition to a restricted character set, a plain scalar must not be empty or contain leading or trailing white space characters. It is only possible to break a long plain line where a space character is surrounded by non-spaces.

Not sure.

mathomp4 commented 2 years ago

NOTE: That if we go from "relaxed and no warnings" (like used on CI) to "strict" things get fun. From no issues, to a lot of errors:

❯ yamllint -d relaxed --no-warnings ./Examples/Simple/simple2.yaml
❯ yamllint  ./Examples/Simple/simple2.yaml
./Examples/Simple/simple2.yaml
  2:1       warning  missing document start "---"  (document-start)
  2:4       error    too many spaces after colon  (colons)
  4:7       warning  truthy value should be one of [false, true]  (truthy)
  7:13      error    too many spaces after colon  (colons)
  7:15      error    too many spaces inside brackets  (brackets)
  7:17      error    too many spaces before comma  (commas)
  7:21      error    too many spaces before comma  (commas)
  7:25      error    too many spaces before comma  (commas)
  7:29      error    too many spaces inside brackets  (brackets)
  22:13     error    too many spaces inside braces  (braces)
  22:21     error    too many spaces before comma  (commas)
  22:31     error    too many spaces inside braces  (braces)
  23:1      error    too many blank lines (1 > 0)  (empty-lines)

Though maybe the files here in yaFyaml should be strictly judged?

tclune commented 2 years ago

I say start with relaxed and we'll up our game. Can you check to see if pyyaml chokes on trailing spaces?

mathomp4 commented 2 years ago

Looks like pyyaml and ruamel.yaml are okay with a file that relaxed yamllint doesn't like:

❯ yamllint -d relaxed --no-warnings categories.yaml
categories.yaml
  10:13     error    trailing spaces  (trailing-spaces)

❯ python3 test.pyyaml.py
{'sports': ['soccer', 'football', 'basketball', 'cricket', 'hockey', 'table tennis'], 'countries': ['Pakistan', 'USA', 'India', 'China', 'Germany', 'France', 'Spain']}
❯ python3 test.ruamel.py
{'sports': ['soccer', 'football', 'basketball', 'cricket', 'hockey', 'table tennis'], 'countries': ['Pakistan', 'USA', 'India', 'China', 'Germany', 'France', 'Spain']}
mathomp4 commented 2 years ago

That said, it does seem to be something YAML 1.2 is not happy about, but if PyYAML is happy, then yaFyaml can be as well.