pull/348/merge
Joel Baranick 2 years ago committed by GitHub
commit 161c477d82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -654,6 +654,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')

@ -28,6 +28,21 @@ 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)
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'

@ -226,6 +226,7 @@ def run(argv=None):
sys.exit(0)
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
@ -236,7 +237,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
@ -247,7 +248,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']:

@ -36,6 +36,7 @@ class YamlLintConfig:
'gitwildmatch', ['*.yaml', '*.yml', '.yamllint'])
self.locale = None
self.no_warnings = False
if file is not None:
with open(file) as f:
@ -138,6 +139,12 @@ class YamlLintConfig:
'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:

Loading…
Cancel
Save