From a9ea6485e3cd2902daef8b3e1a25978c1fde3611 Mon Sep 17 00:00:00 2001 From: Joel Baranick Date: Mon, 21 Dec 2020 09:00:40 -0800 Subject: [PATCH 1/5] Support no-warnings specified in config --- yamllint/cli.py | 4 ++-- yamllint/config.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/yamllint/cli.py b/yamllint/cli.py index cb87350..3bb35c8 100644 --- a/yamllint/cli.py +++ b/yamllint/cli.py @@ -208,7 +208,7 @@ def run(argv=None): print(e, file=sys.stderr) sys.exit(-1) prob_level = show_problems(problems, file, args_format=args.format, - no_warn=args.no_warnings) + no_warn=args.no_warnings or conf.no_warnings) max_level = max(max_level, prob_level) # read yaml from stdin @@ -219,7 +219,7 @@ def run(argv=None): print(e, file=sys.stderr) sys.exit(-1) prob_level = show_problems(problems, 'stdin', args_format=args.format, - no_warn=args.no_warnings) + no_warn=args.no_warnings or conf.no_warnings) max_level = max(max_level, prob_level) if max_level == PROBLEM_LEVELS['error']: diff --git a/yamllint/config.py b/yamllint/config.py index a42e744..7d4b010 100644 --- a/yamllint/config.py +++ b/yamllint/config.py @@ -36,6 +36,7 @@ class YamlLintConfig(object): 'gitwildmatch', ['*.yaml', '*.yml', '.yamllint']) self.locale = None + self.no_warnings = False if file is not None: with open(file) as f: @@ -119,6 +120,12 @@ class YamlLintConfig(object): 'invalid config: locale should be a string') self.locale = conf['locale'] + if 'no-warnings' in conf: + if not isinstance(conf['no-warnings'], bool): + raise YamlLintConfigError( + 'invalid config: no-warnings should be a bool') + self.no_warnings = bool(conf['no-warnings']) + def validate(self): for id in self.rules: try: From de09a23b2c80ee1d22f60cda8881498ffd664074 Mon Sep 17 00:00:00 2001 From: Joel Baranick Date: Mon, 21 Dec 2020 09:04:08 -0800 Subject: [PATCH 2/5] Add config test --- tests/test_config.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_config.py b/tests/test_config.py index 70a73e0..23d905c 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -28,6 +28,16 @@ from yamllint import config class SimpleConfigTestCase(unittest.TestCase): + def test_no_warnings_config(self): + new = config.YamlLintConfig('extends: default') + self.assertFalse(new.no_warnings) + + new = config.YamlLintConfig('no-warnings: false') + self.assertFalse(new.no_warnings) + + new = config.YamlLintConfig('no-warnings: true') + self.assertTrue(new.no_warnings) + def test_parse_config(self): new = config.YamlLintConfig('rules:\n' ' colons:\n' From 20011e75541df818abea3e603dda15bc6f72994e Mon Sep 17 00:00:00 2001 From: Joel Baranick Date: Mon, 21 Dec 2020 09:09:46 -0800 Subject: [PATCH 3/5] Add no-warnings cli test --- tests/test_cli.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index 0cb300a..169990e 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -614,6 +614,16 @@ class CommandLineTestCase(unittest.TestCase): cli.run((path, '--no-warnings', '-f', 'auto')) self.assertEqual(ctx.returncode, 0) + def test_run_no_warnings_from_config(self): + with open(os.path.join(self.wd, 'config'), 'w') as f: + f.write('no-warnings: true') + + path = os.path.join(self.wd, 'warn.yaml') + + with RunContext(self) as ctx: + cli.run((path, '-c', f.name, '-f', 'auto')) + self.assertEqual(ctx.returncode, 0) + def test_run_no_warnings_and_strict(self): path = os.path.join(self.wd, 'warn.yaml') From cef89cf69f1ec735a5b87d1c94cf69c3276444bf Mon Sep 17 00:00:00 2001 From: Joel Baranick Date: Mon, 21 Dec 2020 09:13:08 -0800 Subject: [PATCH 4/5] Reduce line length --- yamllint/cli.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/yamllint/cli.py b/yamllint/cli.py index 3bb35c8..5845e9a 100644 --- a/yamllint/cli.py +++ b/yamllint/cli.py @@ -198,6 +198,7 @@ def run(argv=None): locale.setlocale(locale.LC_ALL, conf.locale) max_level = 0 + no_warnings = args.no_warnings or conf.no_warnings for file in find_files_recursively(args.files, conf): filepath = file[2:] if file.startswith('./') else file @@ -208,7 +209,7 @@ def run(argv=None): print(e, file=sys.stderr) sys.exit(-1) prob_level = show_problems(problems, file, args_format=args.format, - no_warn=args.no_warnings or conf.no_warnings) + no_warn=no_warnings) max_level = max(max_level, prob_level) # read yaml from stdin @@ -219,7 +220,7 @@ def run(argv=None): print(e, file=sys.stderr) sys.exit(-1) prob_level = show_problems(problems, 'stdin', args_format=args.format, - no_warn=args.no_warnings or conf.no_warnings) + no_warn=no_warnings) max_level = max(max_level, prob_level) if max_level == PROBLEM_LEVELS['error']: From 5de2fffd414fe87726ac71fed104d8897d55acbc Mon Sep 17 00:00:00 2001 From: Joel Baranick Date: Mon, 21 Dec 2020 09:17:27 -0800 Subject: [PATCH 5/5] Add test to verify no-warnings config option fails when not boolean --- tests/test_config.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_config.py b/tests/test_config.py index 23d905c..039bb05 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -38,6 +38,11 @@ class SimpleConfigTestCase(unittest.TestCase): new = config.YamlLintConfig('no-warnings: true') self.assertTrue(new.no_warnings) + with self.assertRaisesRegex( + config.YamlLintConfigError, + 'invalid config: no-warnings should be a bool'): + config.YamlLintConfig('no-warnings: foobar') + def test_parse_config(self): new = config.YamlLintConfig('rules:\n' ' colons:\n'