Skip to content

Commit

Permalink
Revert notify related checks, errors, transforms for listen and tests (
Browse files Browse the repository at this point in the history
  • Loading branch information
audgirka committed Jun 4, 2024
1 parent d1ff289 commit 3f6f87f
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
env:
# Number of expected test passes, safety measure for accidental skip of
# tests. Update value if you add/remove tests.
PYTEST_REQPASS: 882
PYTEST_REQPASS: 881
steps:
- uses: actions/checkout@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion examples/playbooks/become.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
become: true
become_user: nobody
notify:
- Restart apache2
- restart apache2
34 changes: 0 additions & 34 deletions examples/playbooks/name_case_notify_fail.yml

This file was deleted.

45 changes: 0 additions & 45 deletions src/ansiblelint/rules/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,6 @@ def matchtask(
),
)

notify = task.get("notify")
if notify:
if isinstance(notify, str):
notify = [notify]

results.extend(
[
self.create_matcherror(
message=f"Task notify '{handler}' should start with an uppercase letter.",
lineno=task[LINE_NUMBER_KEY],
tag="name[casing]",
filename=file,
)
for handler in notify
if check_handler_case(handler)
],
)
return results

def _prefix_check(
Expand Down Expand Up @@ -268,27 +251,10 @@ def update_task_name(task_name: str) -> str:
if orig_task_name == task["notify"][idx]:
task["notify"][idx] = updated_task_name

if isinstance(item, dict) and "handlers" in item:
for task in item["handlers"]:
listener_task_name = task.get("listen", None)
if (
listener_task_name
and listener_task_name == orig_task_name
):
task["listen"] = updated_task_name

target_task["name"] = updated_task_name
match.fixed = True


def check_handler_case(handler: str) -> bool:
"""Check the casing of a handler."""
# Handlers may be prefixed with "role_name : " to indicate a handler from a specific role
# Strip this before checking
handler = handler.split(" : ", 1)[-1]
return handler[0].isalpha() and handler[0].islower() and not handler[0].isupper()


if "pytest" in sys.modules:
from ansiblelint.rules import RulesCollection
from ansiblelint.runner import Runner
Expand Down Expand Up @@ -381,17 +347,6 @@ def test_rule_name_lowercase() -> None:
assert errs[0].tag == "name[casing]"
assert errs[0].rule.id == "name"

def test_rule_notify_lowercase() -> None:
"""Negative test for a task notify that starts with lowercase."""
collection = RulesCollection()
collection.register(NameRule())
failure = "examples/playbooks/name_case_notify_fail.yml"
bad_runner = Runner(failure, rules=collection)
errs = bad_runner.run()
assert len(errs) == 5
assert all(err.tag == "name[casing]" for err in errs)
assert all(err.rule.id == "name" for err in errs)

def test_name_play() -> None:
"""Positive test for name[play]."""
collection = RulesCollection()
Expand Down
1 change: 0 additions & 1 deletion test/test_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def fixture_runner_result(
id="strings",
),
pytest.param("examples/playbooks/vars/empty.yml", 1, False, True, id="empty"),
pytest.param("examples/playbooks/name-case.yml", 6, True, True, id="name_case"),
pytest.param("examples/playbooks/fqcn.yml", 3, True, True, id="fqcn"),
pytest.param(
"examples/playbooks/multi_yaml_doc.yml",
Expand Down

0 comments on commit 3f6f87f

Please sign in to comment.