Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support no warnings in config #348

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
15 changes: 15 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 3 additions & 2 deletions yamllint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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']:
Expand Down
7 changes: 7 additions & 0 deletions yamllint/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down