Skip to content

Commit

Permalink
Fix for ignoring test / directories by fqcn[deep] rule (#4320)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
tanwigeetika1618 and pre-commit-ci[bot] authored Sep 13, 2024
1 parent 25f783c commit 07c05e9
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 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: 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

0 comments on commit 07c05e9

Please sign in to comment.