Skip to content

Commit

Permalink
Improve transformation when '=' sign is used for no-free-form rule
Browse files Browse the repository at this point in the history
  • Loading branch information
audgirka committed Dec 14, 2023
2 parents 930b747 + 555dbb2 commit eb8ac51
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 20 deletions.
1 change: 1 addition & 0 deletions .config/requirements-lock.txt
2 changes: 1 addition & 1 deletion .github/workflows/redirects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5

- name: Upgrade Python toolchain
run: python3 -m pip install --upgrade pip setuptools wheel
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:

steps:
- name: Switch to using Python 3.10 by default
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.10"

Expand Down
10 changes: 5 additions & 5 deletions .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 Expand Up @@ -97,7 +97,7 @@ jobs:

- name: Set up Python ${{ matrix.python_version || '3.10' }}
if: "!contains(matrix.shell, 'wsl')"
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
cache: pip
python-version: ${{ matrix.python_version || '3.10' }}
Expand Down Expand Up @@ -178,7 +178,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -189,10 +189,10 @@ jobs:
# queries: security-extended,security-and-quality

- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"

Expand Down
6 changes: 3 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"evenBetterToml.formatter.alignComments": false,
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": true,
"source.fixAll": true
}
"source.organizeImports": "explicit",
"source.fixAll": "explicit"
}
}
}
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ runs:
- name: Set up Python
if: inputs.setup_python == 'true'
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
cache: pip
cache-dependency-path: ${{ steps.inputs.outputs.working_directory }}/.git/ansible-lint-requirements.txt
Expand Down
2 changes: 1 addition & 1 deletion docs/philosophy.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ only when a major version is released.
Not really. The certification process is likely to use only a subset of rules.
At this time, we are working on building that list.

### Why lots of official Ansible docs examples are not passing linting?
### Why do many official Ansible docs examples fail to pass linting?

Most of the official examples are written to exemplify specific features, and
some might conflict with our rules. Still, we plan to include linting of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
requires_ansible: "2.13.0,<2.15"
requires_ansible: "2.14.0,<2.16"
2 changes: 1 addition & 1 deletion examples/playbooks/transform-no-free-form.transformed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
executable: /bin/bash
changed_when: false

- name: Example task with fqcn and no-free-form errors
- name: Example task with usage for '=' as module params
ansible.builtin.debug:
msg: "'Hello there world'"
2 changes: 1 addition & 1 deletion examples/playbooks/transform-no-free-form.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
ansible.builtin.raw: executable=/bin/bash echo foo # <-- don't use executable=
changed_when: false

- name: Example task with fqcn and no-free-form errors
- name: Example task with usage for '=' as module params
ansible.builtin.debug: msg='Hello there world'
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
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/meta_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CheckRequiresAnsibleVersion(AnsibleLintRule):

# Refer to https://access.redhat.com/support/policy/updates/ansible-automation-platform
# Also add devel to this list
supported_ansible = ["2.13.", "2.14.", "2.15."]
supported_ansible = ["2.14.", "2.15.", "2.16."]
_ids = {
"meta-runtime[unsupported-version]": "'requires_ansible' key must be set to a supported version - 2.13.x, 2.14.x, 2.15.x",
"meta-runtime[invalid-version]": "'requires_ansible' is not a valid requirement specification",
Expand Down
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
2 changes: 1 addition & 1 deletion src/ansiblelint/schemas/__store__.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/execution-environment.json"
},
"galaxy": {
"etag": "0c5cc710484efd1710e4edce8201005cab93c21275dd743f67318f771afe98b6",
"etag": "2a8e7fa2a186af391ad599f90dac7a4b7705e803f4ea3b7e4b3b8c334462b1ac",
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/galaxy.json"
},
"inventory": {
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

0 comments on commit eb8ac51

Please sign in to comment.