Skip to content

Commit

Permalink
Add --ignore-warnings argument (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
amureki authored Mar 7, 2023
1 parent 8a4491e commit 5c3d9e9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
7 changes: 6 additions & 1 deletion relint/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def parse_args(args=None):
parser.add_argument(
"-W", "--fail-warnings", action="store_true", help="Fail for warnings."
)
parser.add_argument(
"--ignore-warnings",
action="store_true",
help="Do not output warnings. Could be useful when using relint in CI.",
)
parser.add_argument(
"--msg-template",
metavar="MSG_TEMPLATE",
Expand All @@ -66,7 +71,7 @@ def main(args=None):
for path in glob.iglob(glob.escape(file), recursive=True)
}

tests = list(load_config(args.config, args.fail_warnings))
tests = list(load_config(args.config, args.fail_warnings, args.ignore_warnings))

matches = chain.from_iterable(lint_file(path, tests) for path in paths)

Expand Down
5 changes: 4 additions & 1 deletion relint/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
)


def load_config(path, fail_warnings):
def load_config(path, fail_warnings, ignore_warnings):
with open(path) as fs:
try:
for test in yaml.safe_load(fs):
if ignore_warnings and not test.get("error", True):
continue

file_pattern = test.get("filePattern", ".*")
file_pattern = re.compile(file_pattern)
yield Test(
Expand Down
11 changes: 11 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ def test_raise_for_warnings(self, tmpdir, fixture_dir):

assert exc_info.value.code == 1

def test_ignore_warnings(self, tmpdir, fixture_dir):
with (fixture_dir / ".relint.yml").open() as fs:
config = fs.read()
tmpdir.join(".relint.yml").write(config)
tmpdir.join("dummy.py").write("# TODO do something")
with tmpdir.as_cwd():
with pytest.raises(SystemExit) as exc_info:
main(["relint.py", "dummy.py", "--ignore-warnings"])

assert exc_info.value.code == 0

def test_main_execution_with_diff(self, capsys, mocker, tmpdir, fixture_dir):
with (fixture_dir / ".relint.yml").open() as fs:
config = fs.read()
Expand Down

0 comments on commit 5c3d9e9

Please sign in to comment.