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

Write mode introduces too many spaces inside braces #2076

Closed
ziegenberg opened this issue Apr 27, 2022 · 3 comments · Fixed by #2077
Closed

Write mode introduces too many spaces inside braces #2076

ziegenberg opened this issue Apr 27, 2022 · 3 comments · Fixed by #2077
Assignees
Labels
bug new Triage required

Comments

@ziegenberg
Copy link
Contributor

ziegenberg commented Apr 27, 2022

Summary

ansible-lint --write introduces extra spaces inside braces and complains about it afterwards

Issue Type
  • Bug Report
Ansible and Ansible Lint details
ansible --version
ansible [core 2.12.4]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/daniel/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/daniel/.local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/daniel/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/daniel/.local/bin/ansible
  python version = 3.8.13 (default, Mar 17 2022, 00:00:00) [GCC 11.2.1 20220127 (Red Hat 11.2.1-9)]
  jinja version = 3.1.1
  libyaml = True

ansible-lint --version
WARNING: PATH altered to include /usr/bin
ansible-lint 6.0.2 using ansible 2.12.4
  • ansible installation method: pip
  • ansible-lint installation method: pip
STEPS TO REPRODUCE

Run ansible-lint --write on a document already adhering to standardized spacing, quotes, etc.

Desired Behavior

ansible-lint --write should not format a document already adhering to standardized spacing, quotes, etc.

The following document should not be changed.

---
- hosts: web
  vars:
    config_ini:
      - {section: General, option: force_ssl, value: 1}
      - {section: General, option: "proxy_client_headers[]", value: HTTP_X_FORWARDED_FOR}
Actual Behavior

Using the following example playbook:

---
- hosts: web
  vars:
    config_ini:
      - {section: General, option: force_ssl, value: 1}
      - {section: General, option: "proxy_client_headers[]", value: HTTP_X_FORWARDED_FOR}

and running just ansible-lint --write it reports:

ansible-lint --write
WARNING: PATH altered to include /usr/bin

Modified 1 files.
Finished with 0 failure(s), 0 warning(s) on 1 files.

The file now looks like this:

---
- hosts: web
  vars:
    config_ini:
      - { section: General, option: force_ssl, value: 1 }
      - { section: General, option: "proxy_client_headers[]", value: HTTP_X_FORWARDED_FOR }

Note the extra spaces inside the curly braces.

Running just ansible-lint --write again it now complains:

ansible-lint --write
WARNING: PATH altered to include /usr/bin
WARNING  Listing 2 violation(s) that are fatal
yaml: too many spaces inside braces (braces)
playbook.yml:5

yaml: too many spaces inside braces (braces)
playbook.yml:6

You can skip specific rules or tags by adding them to your configuration file:
# .config/ansible-lint.yml
warn_list:  # or 'skip_list' to silence them completely
  - yaml  # Violations reported by yamllint.

Finished with 2 failure(s), 0 warning(s) on 1 files.
@ziegenberg ziegenberg added bug new Triage required labels Apr 27, 2022
@ziegenberg
Copy link
Contributor Author

yamllint defaults to the following rule for flow mappings: braces: {min-spaces-inside: 0, max-spaces-inside: 0}. See documentation: https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.braces

@cognifloyd cognifloyd self-assigned this Apr 27, 2022
@cognifloyd
Copy link
Member

I made it add the space because that's how prettier does it and we're trying not to have the linters fight.

Are you using a custom yamllint file? If not then we need to adjust the internal yamllint config.

@ziegenberg
Copy link
Contributor Author

I'm not aware of using a custom yamllint config.

ziegenberg added a commit to ziegenberg/ansible-lint that referenced this issue Apr 27, 2022
Fixes: ansible#2076

Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>
ziegenberg added a commit to ziegenberg/ansible-lint that referenced this issue Apr 27, 2022
Fixes: ansible#2076

Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>
ziegenberg added a commit to ziegenberg/ansible-lint that referenced this issue Apr 27, 2022
Fixes: ansible#2076

Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>
ziegenberg added a commit to ziegenberg/ansible-lint that referenced this issue Apr 28, 2022
Fixes: ansible#2076

Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>
ziegenberg added a commit to ziegenberg/ansible-lint that referenced this issue Apr 29, 2022
Fixes: ansible#2076

Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>
ziegenberg added a commit to ziegenberg/ansible-lint that referenced this issue Apr 29, 2022
Fixes: ansible#2076

Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>
ziegenberg added a commit to ziegenberg/ansible-lint that referenced this issue Apr 29, 2022
Fixes: ansible#2076

Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>
cognifloyd pushed a commit that referenced this issue May 2, 2022
…2077)

* relax the yamllint rules on spaces inside braces for flow mappings

Fixes: #2076

Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>

* add testcase for too many space

Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>

* fix path to tool for regenerating test fixtures

Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>

* fixup! relax the yamllint rules on spaces inside braces for flow mappings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug new Triage required
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants