Skip to content

Commit

Permalink
Require at least one known subfolder for roles (#3303)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Apr 19, 2023
1 parent 80e2be3 commit fd23b3a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 20 deletions.
1 change: 1 addition & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ ssbarnea
stylesheet
subdir
subelements
subfolders
subresults
subschema
subschemas
Expand Down
10 changes: 9 additions & 1 deletion src/ansiblelint/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,15 @@ def kind_from_path(path: Path, base: bool = False) -> FileType:
return ""

if path.is_dir():
return "role"
known_role_subfolders = ("tasks", "meta", "vars", "defaults", "handlers")
for filename in known_role_subfolders:
if (path / filename).is_dir():
return "role"
_logger.debug(
"Folder `%s` does not look like a role due to missing any of the common subfolders such: %s.",
path,
", ".join(known_role_subfolders),
)

if str(path) == "/dev/stdin":
return "playbook"
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,8 +1017,8 @@ def _extend_with_roles(lintables: list[Lintable]) -> None:
while role.parent.name != "roles" and role.name:
role = role.parent
if role.exists() and not role.is_file():
lintable = Lintable(role, kind="role")
if lintable not in lintables:
lintable = Lintable(role)
if lintable.kind == "role" and lintable not in lintables:
_logger.debug("Added role: %s", lintable)
lintables.append(lintable)

Expand Down
Empty file.
8 changes: 7 additions & 1 deletion test/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ def test_runner_unicode_format(
formatter.format(matches[0])


@pytest.mark.parametrize("directory_name", ("test/", os.path.abspath("test")))
@pytest.mark.parametrize(
"directory_name",
(
pytest.param("test/fixtures/verbosity-tests", id="rel"),
pytest.param(os.path.abspath("test/fixtures/verbosity-tests"), id="abs"),
),
)
def test_runner_with_directory(
default_rules_collection: RulesCollection,
directory_name: str,
Expand Down
30 changes: 14 additions & 16 deletions test/test_verbosity.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,61 @@
@pytest.mark.parametrize(
("verbosity", "substrs"),
(
(
pytest.param(
"",
[
("WARNING Listing 1 violation(s) that are fatal", False),
("DEBUG ", True),
("INFO ", True),
],
id="default",
),
(
pytest.param(
"-q",
[
("WARNING ", True),
("DEBUG ", True),
("INFO ", True),
],
id="q",
),
(
pytest.param(
"-qq",
[
("WARNING ", True),
("DEBUG ", True),
("INFO ", True),
],
id="qq",
),
(
pytest.param(
"-v",
[
("WARNING Listing 1 violation(s) that are fatal", False),
("INFO Set ANSIBLE_LIBRARY=", False),
("DEBUG ", True),
],
id="v",
),
(
pytest.param(
"-vv",
[
("WARNING Listing 1 violation(s) that are fatal", False),
("INFO Set ANSIBLE_LIBRARY=", False),
],
id="really-loquacious",
),
(
"-vvvvvvvvvvvvvvvvvvvvvvvvv",
pytest.param(
"-vv",
[
("WARNING Listing 1 violation(s) that are fatal", False),
("INFO Set ANSIBLE_LIBRARY=", False),
],
id="vv",
),
),
ids=(
"default-verbosity",
"quiet",
"really-quiet",
"loquacious",
"really-loquacious",
'really-loquacious but with more "v"s -- same as -vv',
),
)
def test_default_verbosity(verbosity: str, substrs: list[tuple[str, bool]]) -> None:
def test_verbosity(verbosity: str, substrs: list[tuple[str, bool]]) -> None:
"""Checks that our default verbosity displays (only) warnings."""
# Piggyback off the .yamllint in the root of the repo, just for testing.
# We'll "override" it with the one in the fixture, to produce a warning.
Expand Down

0 comments on commit fd23b3a

Please sign in to comment.