Skip to content

Commit 8583092

Browse files
committed
feat: added exit code 8 for successfully fixed violations (#4674)
1 parent 901003b commit 8583092

File tree

5 files changed

+33
-6
lines changed

5 files changed

+33
-6
lines changed

src/ansiblelint/app.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ def report_outcome(
198198
) -> int:
199199
"""Display information about how to skip found rules.
200200
201-
Returns exit code, 2 if errors were found, 0 when only warnings were found.
201+
Returns exit code:
202+
- 0: when no errors were found
203+
- 2: if errors were found
204+
- 8: if all errors were fixed automatically
202205
"""
203206
msg = ""
204207

@@ -260,6 +263,8 @@ def report_outcome(
260263
files_count,
261264
is_success=mark_as_success,
262265
)
266+
if not summary.failures and changed_files_count > 0:
267+
return RC.FIXED_VIOLATIONS
263268
if mark_as_success:
264269
if not files_count:
265270
# success without any file being analyzed is reported as failure

src/ansiblelint/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class RC: # pylint: disable=too-few-public-methods
3737
INVALID_CONFIG = 3
3838
LOCK_TIMEOUT = 4
3939
NO_FILES_MATCHED = 5
40+
FIXED_VIOLATIONS = 8
4041
EXIT_CONTROL_C = 130
4142

4243

src/ansiblelint/schemas/__store__.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/ansible-lint-config.json"
55
},
66
"ansible-navigator-config": {
7-
"etag": "730a0572f872af3ce271fb5116bc9d4609da10dc2e35448b5ec1050f12b72e2b",
7+
"etag": "5f454fdaeb3d92c4bb2cc15dcc48faa67925fecfbdb72efffeddee01860d6bcb",
88
"url": "https://raw.githubusercontent.com/ansible/ansible-navigator/main/src/ansible_navigator/data/ansible-navigator.json"
99
},
1010
"changelog": {
@@ -24,7 +24,7 @@
2424
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/inventory.json"
2525
},
2626
"meta": {
27-
"etag": "fa83d61b00b254d54a7c9a69e4fb8b722f356adec906da7beb733cadda1342bc",
27+
"etag": "2f5c7deb174136b48a4bc1d8d4399b1a175379dd4b8a863baa9c9bd56ffda489",
2828
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/meta.json"
2929
},
3030
"meta-runtime": {

src/ansiblelint/schemas/ansible-navigator-config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema",
33
"additionalProperties": false,
4-
"description": "See https://docs.ansible.com/projects/navigator/settings/",
4+
"description": "See https://ansible.readthedocs.io/projects/navigator/settings/",
55
"properties": {
66
"ansible-navigator": {
77
"additionalProperties": false,
@@ -525,7 +525,7 @@
525525
"required": [
526526
"ansible-navigator"
527527
],
528-
"title": "ansible-navigator settings v25",
528+
"title": "ansible-navigator settings v26",
529529
"type": "object",
530-
"version": "25"
530+
"version": "26"
531531
}

test/test_app.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,24 @@ def test_with_inventory_concurrent_syntax_checks(tmp_path: Path) -> None:
5252
# https://github.com/ansible/ansible-lint/issues/4446.
5353
assert "AttributeError" not in result.stderr
5454
counter += 1
55+
56+
57+
def test_app_fixed_violations(tmp_path: Path) -> None:
58+
"""Validate that linter returns RC.FIXED_VIOLATIONS (8) when all issues are fixed."""
59+
# 1. Create a playbook with an auto-fixable error (FQCN)
60+
# Note: We include 'changed_when: false' so no unfixable errors remain
61+
lintable = Lintable(tmp_path / "fixable_playbook.yml")
62+
lintable.content = """---
63+
- name: Test Autofix
64+
hosts: localhost
65+
tasks:
66+
- name: Use shell instead of FQCN
67+
command: echo "Hello World"
68+
changed_when: false
69+
"""
70+
lintable.write(force=True)
71+
72+
result = run_ansible_lint(lintable.filename, "--fix", cwd=tmp_path)
73+
74+
assert result.returncode == RC.FIXED_VIOLATIONS
75+
assert "Modified 1 file." in result.stderr

0 commit comments

Comments
 (0)