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 for ignoring test / directories by fqcn[deep] rule #4320

Merged
merged 4 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -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: 891
PYTEST_REQPASS: 892
steps:
- uses: actions/checkout@v4
with:
Expand Down
43 changes: 43 additions & 0 deletions examples/.collection/plugins/modules/tests/gamma.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""An ansible test module."""

DOCUMENTATION = """
module: mod_1
author:
- test
short_description: This is a test module
description:
- This is a test module
version_added: 1.0.0
options:
foo:
description:
- Dummy option I(foo)
type: str
bar:
description:
- Dummy option I(bar)
default: candidate
type: str
choices:
- candidate
- running
aliases:
- bam
notes:
- This is a dummy module
"""

EXAMPLES = """
- name: test task-1
company_name.coll_1.mod_1:
foo: some value
bar: candidate
"""

RETURN = """
baz:
description: test return 1
returned: success
type: list
sample: ['a','b']
"""
10 changes: 9 additions & 1 deletion src/ansiblelint/rules/fqcn.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def matchyaml(self, file: Lintable) -> list[MatchError]:
i = file.path.resolve().parts.index("plugins")
plugin_type = file.path.resolve().parts[i : i + 2]
short_path = file.path.resolve().parts[i + 2 :]
if len(short_path) > 1:
if len(short_path) > 1 and "test" not in str(file.path):
result.append(
self.create_matcherror(
message=f"Deep plugins directory is discouraged. Move '{file.path}' directly under '{'/'.join(plugin_type)}' folder.",
Expand Down Expand Up @@ -298,3 +298,11 @@ def test_fqcn_deep_pass() -> None:
success = "examples/.collection/plugins/modules/alpha.py"
results = Runner(success, rules=collection).run()
assert len(results) == 0

def test_fqcn_deep_test_dir_pass() -> None:
"""Test rule does not match."""
collection = RulesCollection()
collection.register(FQCNBuiltinsRule())
success = "examples/.collection/plugins/modules/tests/gamma.py"
results = Runner(success, rules=collection).run()
assert len(results) == 0
Loading