Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13a0f11e7c | ||
|
|
43b95e99d1 | ||
|
|
8fa9eb3ced |
@@ -1,6 +1,12 @@
|
|||||||
Changelog
|
Changelog
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
1.20.0 (2019-12-26)
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
- Add --no-warnings option to suppress warning messages
|
||||||
|
- Use 'syntax' as rule name upon syntax errors
|
||||||
|
|
||||||
1.19.0 (2019-11-19)
|
1.19.0 (2019-11-19)
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
|||||||
@@ -116,6 +116,9 @@ return code will be:
|
|||||||
* ``1`` if one or more errors occur
|
* ``1`` if one or more errors occur
|
||||||
* ``2`` if no errors occur, but one or more warnings occur
|
* ``2`` if no errors occur, but one or more warnings occur
|
||||||
|
|
||||||
|
If the script is invoked with the ``--no-warnings`` option, it won't output
|
||||||
|
warning level problems, only error level ones.
|
||||||
|
|
||||||
YAML files extensions
|
YAML files extensions
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
|
|||||||
@@ -530,5 +530,40 @@ class CommandLineTestCase(unittest.TestCase):
|
|||||||
out, err = sys.stdout.getvalue(), sys.stderr.getvalue()
|
out, err = sys.stdout.getvalue(), sys.stderr.getvalue()
|
||||||
self.assertEqual(out, (
|
self.assertEqual(out, (
|
||||||
'stdin:2:10: [error] syntax error: '
|
'stdin:2:10: [error] syntax error: '
|
||||||
'mapping values are not allowed here\n'))
|
'mapping values are not allowed here (syntax)\n'))
|
||||||
self.assertEqual(err, '')
|
self.assertEqual(err, '')
|
||||||
|
|
||||||
|
def test_run_no_warnings(self):
|
||||||
|
file = os.path.join(self.wd, 'a.yaml')
|
||||||
|
|
||||||
|
sys.stdout, sys.stderr = StringIO(), StringIO()
|
||||||
|
with self.assertRaises(SystemExit) as ctx:
|
||||||
|
cli.run((file, '--no-warnings', '-f', 'auto'))
|
||||||
|
|
||||||
|
self.assertEqual(ctx.exception.code, 1)
|
||||||
|
|
||||||
|
out, err = sys.stdout.getvalue(), sys.stderr.getvalue()
|
||||||
|
self.assertEqual(out, (
|
||||||
|
'%s\n'
|
||||||
|
' 2:4 error trailing spaces (trailing-spaces)\n'
|
||||||
|
' 3:4 error no new line character at the end of file '
|
||||||
|
'(new-line-at-end-of-file)\n'
|
||||||
|
'\n' % file))
|
||||||
|
self.assertEqual(err, '')
|
||||||
|
|
||||||
|
file = os.path.join(self.wd, 'warn.yaml')
|
||||||
|
|
||||||
|
sys.stdout, sys.stderr = StringIO(), StringIO()
|
||||||
|
with self.assertRaises(SystemExit) as ctx:
|
||||||
|
cli.run((file, '--no-warnings', '-f', 'auto'))
|
||||||
|
|
||||||
|
self.assertEqual(ctx.exception.code, 0)
|
||||||
|
|
||||||
|
def test_run_no_warnings_and_strict(self):
|
||||||
|
file = os.path.join(self.wd, 'warn.yaml')
|
||||||
|
|
||||||
|
sys.stdout, sys.stderr = StringIO(), StringIO()
|
||||||
|
with self.assertRaises(SystemExit) as ctx:
|
||||||
|
cli.run((file, '--no-warnings', '-s'))
|
||||||
|
|
||||||
|
self.assertEqual(ctx.exception.code, 2)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ indentation, etc."""
|
|||||||
|
|
||||||
|
|
||||||
APP_NAME = 'yamllint'
|
APP_NAME = 'yamllint'
|
||||||
APP_VERSION = '1.19.0'
|
APP_VERSION = '1.20.0'
|
||||||
APP_DESCRIPTION = __doc__
|
APP_DESCRIPTION = __doc__
|
||||||
|
|
||||||
__author__ = u'Adrien Vergé'
|
__author__ = u'Adrien Vergé'
|
||||||
|
|||||||
@@ -84,11 +84,14 @@ class Format(object):
|
|||||||
return line
|
return line
|
||||||
|
|
||||||
|
|
||||||
def show_problems(problems, file, args_format):
|
def show_problems(problems, file, args_format, no_warn):
|
||||||
max_level = 0
|
max_level = 0
|
||||||
first = True
|
first = True
|
||||||
|
|
||||||
for problem in problems:
|
for problem in problems:
|
||||||
|
max_level = max(max_level, PROBLEM_LEVELS[problem.level])
|
||||||
|
if no_warn and (problem.level != 'error'):
|
||||||
|
continue
|
||||||
if args_format == 'parsable':
|
if args_format == 'parsable':
|
||||||
print(Format.parsable(problem, file))
|
print(Format.parsable(problem, file))
|
||||||
elif args_format == 'colored' or \
|
elif args_format == 'colored' or \
|
||||||
@@ -102,7 +105,6 @@ def show_problems(problems, file, args_format):
|
|||||||
print(file)
|
print(file)
|
||||||
first = False
|
first = False
|
||||||
print(Format.standard(problem, file))
|
print(Format.standard(problem, file))
|
||||||
max_level = max(max_level, PROBLEM_LEVELS[problem.level])
|
|
||||||
|
|
||||||
if not first and args_format != 'parsable':
|
if not first and args_format != 'parsable':
|
||||||
print('')
|
print('')
|
||||||
@@ -133,6 +135,9 @@ def run(argv=None):
|
|||||||
action='store_true',
|
action='store_true',
|
||||||
help='return non-zero exit code on warnings '
|
help='return non-zero exit code on warnings '
|
||||||
'as well as errors')
|
'as well as errors')
|
||||||
|
parser.add_argument('--no-warnings',
|
||||||
|
action='store_true',
|
||||||
|
help='output only error level problems')
|
||||||
parser.add_argument('-v', '--version', action='version',
|
parser.add_argument('-v', '--version', action='version',
|
||||||
version='{} {}'.format(APP_NAME, APP_VERSION))
|
version='{} {}'.format(APP_NAME, APP_VERSION))
|
||||||
|
|
||||||
@@ -176,7 +181,8 @@ def run(argv=None):
|
|||||||
except EnvironmentError as e:
|
except EnvironmentError as e:
|
||||||
print(e, file=sys.stderr)
|
print(e, file=sys.stderr)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
prob_level = show_problems(problems, file, args_format=args.format)
|
prob_level = show_problems(problems, file, args_format=args.format,
|
||||||
|
no_warn=args.no_warnings)
|
||||||
max_level = max(max_level, prob_level)
|
max_level = max(max_level, prob_level)
|
||||||
|
|
||||||
# read yaml from stdin
|
# read yaml from stdin
|
||||||
@@ -186,7 +192,8 @@ def run(argv=None):
|
|||||||
except EnvironmentError as e:
|
except EnvironmentError as e:
|
||||||
print(e, file=sys.stderr)
|
print(e, file=sys.stderr)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
prob_level = show_problems(problems, 'stdin', args_format=args.format)
|
prob_level = show_problems(problems, 'stdin', args_format=args.format,
|
||||||
|
no_warn=args.no_warnings)
|
||||||
max_level = max(max_level, prob_level)
|
max_level = max(max_level, prob_level)
|
||||||
|
|
||||||
if max_level == PROBLEM_LEVELS['error']:
|
if max_level == PROBLEM_LEVELS['error']:
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ def get_syntax_error(buffer):
|
|||||||
except yaml.error.MarkedYAMLError as e:
|
except yaml.error.MarkedYAMLError as e:
|
||||||
problem = LintProblem(e.problem_mark.line + 1,
|
problem = LintProblem(e.problem_mark.line + 1,
|
||||||
e.problem_mark.column + 1,
|
e.problem_mark.column + 1,
|
||||||
'syntax error: ' + e.problem)
|
'syntax error: ' + e.problem + ' (syntax)')
|
||||||
problem.level = 'error'
|
problem.level = 'error'
|
||||||
return problem
|
return problem
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user