Skip to content

Commit 5c3d9e9

Browse files
authored
Add --ignore-warnings argument (#46)
1 parent 8a4491e commit 5c3d9e9

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

relint/__main__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ def parse_args(args=None):
4242
parser.add_argument(
4343
"-W", "--fail-warnings", action="store_true", help="Fail for warnings."
4444
)
45+
parser.add_argument(
46+
"--ignore-warnings",
47+
action="store_true",
48+
help="Do not output warnings. Could be useful when using relint in CI.",
49+
)
4550
parser.add_argument(
4651
"--msg-template",
4752
metavar="MSG_TEMPLATE",
@@ -66,7 +71,7 @@ def main(args=None):
6671
for path in glob.iglob(glob.escape(file), recursive=True)
6772
}
6873

69-
tests = list(load_config(args.config, args.fail_warnings))
74+
tests = list(load_config(args.config, args.fail_warnings, args.ignore_warnings))
7075

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

relint/config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
)
1919

2020

21-
def load_config(path, fail_warnings):
21+
def load_config(path, fail_warnings, ignore_warnings):
2222
with open(path) as fs:
2323
try:
2424
for test in yaml.safe_load(fs):
25+
if ignore_warnings and not test.get("error", True):
26+
continue
27+
2528
file_pattern = test.get("filePattern", ".*")
2629
file_pattern = re.compile(file_pattern)
2730
yield Test(

tests/test_main.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ def test_raise_for_warnings(self, tmpdir, fixture_dir):
7171

7272
assert exc_info.value.code == 1
7373

74+
def test_ignore_warnings(self, tmpdir, fixture_dir):
75+
with (fixture_dir / ".relint.yml").open() as fs:
76+
config = fs.read()
77+
tmpdir.join(".relint.yml").write(config)
78+
tmpdir.join("dummy.py").write("# TODO do something")
79+
with tmpdir.as_cwd():
80+
with pytest.raises(SystemExit) as exc_info:
81+
main(["relint.py", "dummy.py", "--ignore-warnings"])
82+
83+
assert exc_info.value.code == 0
84+
7485
def test_main_execution_with_diff(self, capsys, mocker, tmpdir, fixture_dir):
7586
with (fixture_dir / ".relint.yml").open() as fs:
7687
config = fs.read()

0 commit comments

Comments
 (0)