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

comments-indentation: false positive with commented dictionary in list #384

Open
ssbarnea opened this issue May 21, 2021 · 4 comments
Open

Comments

@ssbarnea
Copy link
Sponsor Contributor

ssbarnea commented May 21, 2021

Here is an example where yamllint reports an error, even if based on the documented examples it should work fine:

---
platforms:
  # - name: centos7
  - name: centos
    version: 8
  # - name: debian
  #   version: 10

The first commented section is correctly considered well idented but the last one is not. I do mention that this identation is the default one that is applied by IDEs like vscode and assures full reversal via shortcuts (Cmd+/).

As we can see the editor did insert the comment at correct indentation.

I observed that if I removed the line with version: 8, yamllint no longer complains about wrong indentation, this should also explain where the bug comes from (assumption that commented line must be part of the previous identation level).

This is why you have no problems commenting an entire sequence item at start but not if previous line was a mapping.

ssbarnea added a commit to ansible/ansible-lint that referenced this issue May 21, 2021
In order to avoid false positive results about comment identation,

Keep in mind that these settings are used only if there is no
.yamllint config inside the current repository. Users still have
the option to override the default value and reactivate the rule
if they want.

Related: adrienverge/yamllint#384
ssbarnea added a commit to ansible/ansible-lint that referenced this issue May 21, 2021
In order to avoid false positive results about comment identation,

Keep in mind that these settings are used only if there is no
.yamllint config inside the current repository. Users still have
the option to override the default value and reactivate the rule
if they want.

Related: adrienverge/yamllint#384
@ssbarnea ssbarnea changed the title comments-identation: false positive with commented dictionary in list comments-indentation: false positive with commented dictionary in list May 21, 2021
ssbarnea added a commit to ansible/ansible-lint that referenced this issue May 22, 2021
In order to avoid false positive results about comment identation,

Keep in mind that these settings are used only if there is no
.yamllint config inside the current repository. Users still have
the option to override the default value and reactivate the rule
if they want.

Related: adrienverge/yamllint#384
@adrienverge
Copy link
Owner

Thanks for the report @ssbarnea. Any help to find the cause and fix it (with non-regression tests) would be welcome.

@ssbarnea
Copy link
Sponsor Contributor Author

I was aware of this bug for longer period of time but I had the impression that you wanted that behavior so I did not bother to investigate a fix. For the moment I changed the defaults of ansible-lint to disable this specific rule.

I am glad that you confirm it as a false-positive, we can now look into addressing it (if we can find time).

@adrienverge
Copy link
Owner

As you point out, this behavior could be wanted in some cases, for example to detect the wrongly-indented comment here:

# List of platforms:
platforms:
  - name: centos
    version: 8
  # List of structures:
structures:
  - struct1

But since the yamllint error disappears when removing the line version: 8, I agree this doesn't really make sense to keep this behavior.

@vl-kp
Copy link

vl-kp commented Jun 30, 2023

any workaournd

notok added a commit to notok/templates that referenced this issue Mar 31, 2024
Fixed yamllint error excluding following rules.
- line-length: Default limit 80 is too small
- comments-indentation: This rule is being discussed at adrienverge/yamllint#141 and adrienverge/yamllint#384
notok added a commit to notok/templates that referenced this issue Apr 2, 2024
Fixed yamllint error excluding following rules.
- line-length: Default limit 80 is too small
- comments-indentation: This rule is being discussed at adrienverge/yamllint#141 and adrienverge/yamllint#384
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

3 participants