adrienverge / yamllint

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

Expected <document start> but found <scalar> syntax error wrt comment line between scalars #661

Open jude opened 9 months ago

jude commented 9 months ago

I have a test.yml that is

a
#
b

that is returning an 'error syntax error: expected '', but found '' (syntax)' error.:

$ yamllint test.yml 
test.yml
  3:1       error    syntax error: expected '<document start>', but found '<scalar>' (syntax)

It looks like the error is only happenign when a comment line is in the middle of the file:

My .yamllint file is

extends: default
rules:
  document-start: disable

I'm using yamllint 1.33.0 from https://dl.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/y/yamllint-1.33.0-1.el8.noarch.rpm

My workaround was to change the file as per below, converting the scalars to empty maps.

a:
#
b:
adrienverge commented 9 months ago

Hello,

I don't think your example is valid YAML, which explains the error that yamllint outputs.

You can try different YAML parsers on https://play.yaml.io/main/parser. I tried the Python parser (PyYAML) and the JavaScript one (yaml) and both report a syntax error.