diff --git a/tests/test_cli.py b/tests/test_cli.py index 0cb300ad..169990e8 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -614,6 +614,16 @@ def test_run_no_warnings(self): 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') diff --git a/tests/test_config.py b/tests/test_config.py index 70a73e0e..039bb054 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -28,6 +28,21 @@ 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) + + 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' diff --git a/yamllint/cli.py b/yamllint/cli.py index cb87350f..5845e9a6 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) + 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) + no_warn=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 a42e7448..7d4b0107 100644 --- a/yamllint/config.py +++ b/yamllint/config.py @@ -36,6 +36,7 @@ def __init__(self, content=None, file=None): '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 @@ def parse(self, raw_content): '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: