-
Notifications
You must be signed in to change notification settings - Fork 672
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load rule ignores from external text file (#3004)
- Loading branch information
Showing
12 changed files
with
133 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# See https://ansible-lint.readthedocs.io/configuring/#ignoring-rules-for-entire-files | ||
playbook2.yml package-latest # comment | ||
playbook2.yml foo-bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"""Test for app module.""" | ||
from pathlib import Path | ||
|
||
from ansiblelint.file_utils import Lintable | ||
from ansiblelint.testing import run_ansible_lint | ||
|
||
|
||
def test_generate_ignore(tmp_path: Path) -> None: | ||
"""Validate that --generate-ignore dumps expected ignore to the file.""" | ||
lintable = Lintable(tmp_path / "playbook.yaml") | ||
lintable.content = "foo: bar" | ||
lintable.write(force=True) | ||
assert not (tmp_path / ".ansible-lint-ignore").exists() | ||
result = run_ansible_lint(lintable.filename, "--generate-ignore", cwd=str(tmp_path)) | ||
assert result.returncode == 2 | ||
assert (tmp_path / ".ansible-lint-ignore").exists() | ||
with open(tmp_path / ".ansible-lint-ignore", encoding="utf-8") as f: | ||
assert "playbook.yaml syntax-check[specific]\n" in f.readlines() | ||
# Run again and now we expect to succeed as we have an ignore file. | ||
result = run_ansible_lint(lintable.filename, cwd=str(tmp_path)) | ||
assert result.returncode == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"""Tests for loaders submodule.""" | ||
from ansiblelint.loaders import load_ignore_txt | ||
|
||
|
||
def test_load_ignore_txt() -> None: | ||
"""Test load_ignore_txt.""" | ||
result = load_ignore_txt(".ansible-lint-ignore") | ||
assert result == {"playbook2.yml": {"foo-bar", "package-latest"}} |