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 auto capitalization for name[prefix] rule #3922

Merged
merged 16 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
231a720
Add play level autofix for key-order rule
audgirka Oct 5, 2023
811b7db
Merge branch 'main' of github.com:ansible/ansible-lint
audgirka Oct 9, 2023
e72fdc4
Merge branch 'main' of github.com:ansible/ansible-lint
audgirka Oct 11, 2023
413c572
Merge branch 'main' of github.com:ansible/ansible-lint
audgirka Oct 11, 2023
7e66dca
Merge branch 'main' of github.com:ansible/ansible-lint
audgirka Oct 12, 2023
aed3fb9
Merge branch 'main' of github.com:ansible/ansible-lint
audgirka Oct 13, 2023
8fe3a4b
Merge branch 'main' of github.com:ansible/ansible-lint
audgirka Oct 17, 2023
ff74b2e
Merge branch 'main' of github.com:ansible/ansible-lint
audgirka Oct 25, 2023
23e3abd
Merge branch 'main' of github.com:ansible/ansible-lint
audgirka Nov 13, 2023
fbeed6a
Merge branch 'main' of github.com:ansible/ansible-lint
audgirka Nov 21, 2023
4bd6f65
Merge branch 'main' of github.com:ansible/ansible-lint
audgirka Nov 30, 2023
28e24df
Fix auto cap for name[prefix] rule
audgirka Dec 1, 2023
c1b926d
Merge branch 'main' of github.com:ansible/ansible-lint into fix/name_…
audgirka Dec 4, 2023
2f4fab7
Updated number of expected test passes
audgirka Dec 4, 2023
0a732ba
Merge branch 'main' of github.com:ansible/ansible-lint into fix/name_…
audgirka Dec 5, 2023
1c21e27
chore: auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
env:
# Number of expected test passes, safety measure for accidental skip of
# tests. Update value if you add/remove tests.
PYTEST_REQPASS: 849
PYTEST_REQPASS: 850
steps:
- uses: actions/checkout@v4
with:
Expand Down
8 changes: 8 additions & 0 deletions examples/roles/name_prefix/tasks/test.transformed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: test | Not cap
ansible.builtin.debug:
msg: not cap

- name: test | Cap
ansible.builtin.debug:
msg: Cap
8 changes: 8 additions & 0 deletions examples/roles/name_prefix/tasks/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: test | not cap
ansible.builtin.debug:
msg: not cap

- name: test | Cap
ansible.builtin.debug:
msg: Cap
13 changes: 10 additions & 3 deletions src/ansiblelint/rules/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,16 @@ def transform(
if match.tag == "name[casing]":
target_task = self.seek(match.yaml_path, data)
# Not using capitalize(), since that rewrites the rest of the name to lower case
target_task[
"name"
] = f"{target_task['name'][:1].upper()}{target_task['name'][1:]}"
task_name = target_task["name"]
if "|" in task_name: # if using prefix
[file_name, update_task_name] = task_name.split("|")
target_task[
"name"
] = f"{file_name.strip()} | {update_task_name.strip()[:1].upper()}{update_task_name.strip()[1:]}"
else:
target_task[
"name"
] = f"{target_task['name'][:1].upper()}{target_task['name'][1:]}"
match.fixed = True


Expand Down
7 changes: 7 additions & 0 deletions test/test_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ def fixture_runner_result(
True,
id="invalid_transform",
),
pytest.param(
"examples/roles/name_prefix/tasks/test.yml",
1,
True,
True,
id="name_case_with_prefix",
),
),
)
@mock.patch.dict(os.environ, {"ANSIBLE_LINT_WRITE_TMP": "1"}, clear=True)
Expand Down