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

--fix incompatible with yamllint max line-length #4233

Open
ddeepwell opened this issue Jun 26, 2024 · 2 comments
Open

--fix incompatible with yamllint max line-length #4233

ddeepwell opened this issue Jun 26, 2024 · 2 comments
Labels

Comments

@ddeepwell
Copy link

Summary

ansible-lint --fix does not respect the maximum yaml line length in a repo where the line length is specified in a .yamllint file and multi-line strings use double quotes with a \ to wrap onto the next line.

When running ansible-lint --fix twice, the double quotes and line split are removed on the first pass, followed by a line-length error on the second pass.

Issue Type
  • Bug Report
OS / ENVIRONMENT

MacOS Sonoma 14.5

ansible-lint --version
ansible-lint 24.6.1 using ansible-core:2.17.1 ansible-compat:24.6.1 ruamel-yaml:0.18.6 ruamel-yaml-clib:0.2.8
  • ansible installation method: pip
  • ansible-lint installation method: pip
STEPS TO REPRODUCE

A minimum test repo contains two files:

  1. .yamllint file:
---
rules:
  line-length:
    max: 88

and 2) a roles/arole/tasks/main.yml file:

---
- name: Download tarball
  ansible.builtin.get_url:
    url: "https://download.samba.org/pub/application/src/\
      application-application.version.tar.gz"
    dest: /tmp/app.tar.gz
    mode: "644"

Then run ansible-lint --fix twice.

Desired Behavior

I expected the multi-line string to be ignored since the a fix might combined the multiline string into a single line thereby surpassing the max line length limit.

Actual Behavior

The second iteration of running ansible-lint --fix returns the following line too long error, even though it was fine before running ansible-lint:

ERROR    Rule specific fix not applied for: yaml/yaml roles/arole/tasks/main.yml:4
WARNING  Listing 1 violation(s) that are fatal
yaml[line-length]: Line too long (94 > 88 characters)
roles/arole/tasks/main.yml:4

Read documentation for instructions on how to ignore specific rule violations.

                Rule Violation Summary                
 count tag               profile rule associated tags 
     1 yaml[line-length] basic   formatting, yaml     

Failed: 1 failure(s), 0 warning(s) on 4 files. Last profile that met the validation criteria was 'min'.
@ddeepwell ddeepwell added bug new Triage required labels Jun 26, 2024
@ddeepwell
Copy link
Author

This seems to be related to #4118.

@ddeepwell
Copy link
Author

For additional information, I noticed today that the Ansible lint yaml documentation makes the following recommendation:

Adhering to yaml[line-length] rule, for writing multiline strings we recommend using Block Style Indicator: literal style indicated by a pipe (|) or folded style indicated by a right angle bracket (>), instead of escaping the newlines with backslashes.

I'd agree with this statement except for when it is not applicable to a long line that cannot have spaces in them (such as a URL) and therefore invalidates the use of Block Scalars.

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

No branches or pull requests

2 participants