Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indentation issue with inline comments in sequences #704

Open
kyle-figure opened this issue Dec 6, 2024 · 2 comments
Open

Indentation issue with inline comments in sequences #704

kyle-figure opened this issue Dec 6, 2024 · 2 comments

Comments

@kyle-figure
Copy link

Hello,

When an inline comment is in a sequence, Yaml formatters like Prettier and the Redhat YAML VSCode extension format it like so:

---
foo: [
    1, # Comment
  ]

However, this produces the following warning and error from yamllint 1.35.1.

Command: yamllint test.yaml
Output:

test.yaml
  3:8       warning  too few spaces before comment  (comments)
  4:3       error    wrong indentation: expected 0 but found 2  (indentation)

I confirmed that test.yaml can be loaded with Python's Yaml package.

Is yamllint using an overly strict indentation check here? Or is it the formatters' fault for not aligning the closing brace with the previous block of code?

@andrewimeson
Copy link
Contributor

Why use the compact/JSON notation if you're going to break it into multiple lines anyway? This is more concise and the more "YAML" way of doing the same thing.

---
foo:
  - 1  # Comment

@kyle-figure
Copy link
Author

That is a good tip. We can just change it to:

foo:
  - [1, 2, 3, 4, 5, 6, 7] # Descriptive comment 1
  - [1, 2, 3, 4, 5, 6, 7] # Descriptive comment 2

Now we only get warnings about there being too few spaces before the comments.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants