YAML formatting not compliant with yamllint "spaces before comments" requirement
See original GitHub issueDescribe the bug
yamllint
, a linter used by many projects and companies, has a different requirement on the number of spaces before comments than what the YAML formatter in this plugin provides:
What yamllint
requires is two spaces before the comment #
:
timeout: 1800 # value in seconds ~ 30m
Formatting of this plugin results in a single space:
timeout: 1800 # value in seconds ~ 30m
Thus, YAML files saved (with Format on Save activated) with VS Code and this plugin enabled results in YAML files that are rejected by systems using yamllint
to check for compliance (e.g. CI systems).
Expected Behavior
Files are formatted according to the yamllint
requirements, e.g. double space before comments.
OR
Option to specify formatting requirements is given.
Current Behavior
Files are not formatted according to yamllint
requirements, e.g. single space before comments.
Steps to Reproduce
- Create file
test.yaml
with contents:
- job:
name: some-job
timeout: 1800 # value in seconds ~ 30m
- Run
yamllint test.yaml
--> pass - Apply formatting in VS Code which will reduce double-space to single-space
- Run
yamllint test.yaml
--> fail
Environment
- Windows
- Mac
- Linux
- other (please specify)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:22
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Rules — yamllint 1.28.0 documentation
When linting a document with yamllint, a series of rules (such as line-length , trailing-spaces , etc.) are checked against.
Read more >Yaml Files Linting and Formatting - - jarrousse.org
yamllint is an open-source command line tool written by Adrien Vergé in python ... trailing spaces, indentation, spaces before the comments.
Read more >Make all yaml inside project root compliant with Yamllint - GitLab
The Yaml across the project root is inconsistent in style and formatting. This should follow a consistent style making it easier to successfully ......
Read more >yamllint
yamllint does not only check for syntax validity, ... file.yml:6:2: [warning] missing starting space in comment (comments).
Read more >10 YAML tips for people who hate YAML | Enable Sysadmin
yamllint errorprone.yaml errorprone.yaml 23:10 error syntax error: mapping values are not allowed here 23:11 error trailing spaces ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello, not a definitive solution but a workaround to use “prettier” format with https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.comments
It will do the job of “not breaking the yamlint” but will still use a spacing of 1.
@MarkusTeufelberger you forgot that prettier is not a linter, it is just a formatter. If you do not like its behavior I would invite you to raise a bug with it.
Based on popularity of prettier (42k stars) versus yamllint (1.9k) and the fact that this project has zero python code in it, I would say that what yamllint does by default, does not matter so much.
On the other hand we do have an example where yamllint (sole) maintainer refused to use indented sequences in its default settings, even if they are more popular around. So you do already have to change yamllint config if you want to also use it.
Keep in mind that this extension has nothing to do with Ansible or Python. Shortly if you don’t like its formatting, disable it. I doubt we see a change in this area on the foreseeable future, especially as I am aware of far more pressing bugs that need to be addressed.