adrienverge / yamllint

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

hyphen: Add min-spaces-after and check-scalars options #606

Open sbaudoin opened 10 months ago

sbaudoin commented 10 months ago

This permits checking style when people want sequences to have a fixed number of spaces greater than 1 for example. We may also use these options to identify typos where we expect everything starting with an hyphen to be a sequence.

coveralls commented 10 months ago

Coverage Status

coverage: 99.401% (+0.005%) from 99.396% when pulling 15dbaed5cd5f27a94e0e714b87d5fcf3a4615f4d on sbaudoin:hyphen-min-spaces into 8713140e99914c0cb6e07364daedfb140847c3c5 on adrienverge:master.

sbaudoin commented 9 months ago

I'm going to push additional commits. For a cleaner history, will you do the rebase or should I do it on my side?

About the rational behind check-scalars, this came from the same code extract as the one you give:

foo:
     -broken

From a YAML point of view this is a valid scalar syntax but as we see that the scalar starts with an hyphen we may think this syntax is a typo. On the first sight we may think that hyphen-min-spaces will identify that but not as we are not considering a sequence because this is a scalar. So I added check-scalars to be able to check such situations. But I agree that this might lead to poor performances and may trigger a lot of false positive (that's explain in the doc).

From my point of view, hyphen-min-spaces would be incomplete without this additional option; we can go without it but we must be clear about such situations not being taken into account.

adrienverge commented 9 months ago

I'm going to push additional commits. For a cleaner history, will you do the rebase or should I do it on my side?

OK! The best would be to rebase and squash into one commit with a nice title, ready to be merged.

From my point of view, hyphen-min-spaces would be incomplete without this additional option; we can go without it but we must be clear about such situations not being taken into account.

Thanks for the explanation. I'm +1 to be more clear about such situations not taken into account (and the reason is simple: they are valid YAML). The quoted-strings rule can also be enabled to avoid such problems.