ansible / ansible-lint

ansible-lint checks playbooks for practices and behavior that could potentially be improved and can fix some of the most common ones for you
https://ansible.readthedocs.io/projects/lint/
GNU General Public License v3.0
3.39k stars 642 forks source link

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

Open ddeepwell opened 6 days ago

ddeepwell commented 6 days ago
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
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
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 commented 6 days ago

This seems to be related to #4118.