pull/114/merge
Anton Ohorodnyk 7 years ago committed by GitHub
commit 35cbbc4537
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -31,6 +31,7 @@ class YamlLintConfig(object):
assert (content is None) ^ (file is None) assert (content is None) ^ (file is None)
self.ignore = None self.ignore = None
self.syntax_checker = {'enabled': True, 'level': 'error'}
if file is not None: if file is not None:
with open(file) as f: with open(file) as f:
@ -91,6 +92,24 @@ class YamlLintConfig(object):
self.ignore = pathspec.PathSpec.from_lines( self.ignore = pathspec.PathSpec.from_lines(
'gitwildmatch', conf['ignore'].splitlines()) 'gitwildmatch', conf['ignore'].splitlines())
if 'syntax-checker' in conf:
if type(conf['syntax-checker']) != dict:
raise YamlLintConfigError('invalid config: syntax-checker should be dict')
syntax_checker = conf['syntax-checker']
if 'enabled' not in syntax_checker:
syntax_checker['enabled'] = True
elif type(syntax_checker['enabled']) != bool:
raise YamlLintConfigError('invalid config: syntax-checker.enabled should should be true or false')
if 'level' not in syntax_checker:
syntax_checker['level'] = 'error'
elif syntax_checker['level'] not in ['error', 'warning']:
raise YamlLintConfigError('invalid config: syntax-checker.level should be "error" or "warning"')
self.syntax_checker = syntax_checker
def validate(self): def validate(self):
for id in self.rules: for id in self.rules:
try: try:

@ -174,15 +174,16 @@ def get_cosmetic_problems(buffer, conf, filepath):
cache = [] cache = []
def get_syntax_error(buffer): def get_syntax_error(buffer, conf):
try: try:
list(yaml.parse(buffer, Loader=yaml.BaseLoader)) list(yaml.parse(buffer, Loader=yaml.BaseLoader))
except yaml.error.MarkedYAMLError as e: except yaml.error.MarkedYAMLError as e:
problem = LintProblem(e.problem_mark.line + 1, if conf.syntax_checker['enabled']:
e.problem_mark.column + 1, problem = LintProblem(e.problem_mark.line + 1,
'syntax error: ' + e.problem) e.problem_mark.column + 1,
problem.level = 'error' 'syntax error: ' + e.problem)
return problem problem.level = conf.syntax_checker['level']
return problem
def _run(buffer, conf, filepath): def _run(buffer, conf, filepath):
@ -191,7 +192,7 @@ def _run(buffer, conf, filepath):
# If the document contains a syntax error, save it and yield it at the # If the document contains a syntax error, save it and yield it at the
# right line # right line
syntax_error = get_syntax_error(buffer) syntax_error = get_syntax_error(buffer, conf)
for problem in get_cosmetic_problems(buffer, conf, filepath): for problem in get_cosmetic_problems(buffer, conf, filepath):
# Insert the syntax error (if any) at the right place... # Insert the syntax error (if any) at the right place...

Loading…
Cancel
Save