-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlinter.py
43 lines (34 loc) · 1.34 KB
/
linter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#
# linter.py
# Linter for SublimeLinter3, a code checking framework for Sublime Text 3
#
# Written by NotSqrt
# Copyright (c) 2013 NotSqrt
#
# License: MIT
#
"""This module exports the Pyyaml plugin class."""
from SublimeLinter.lint import PythonLinter, persist
class Pyyaml(PythonLinter):
"""Provides an interface to pyyaml."""
syntax = 'yaml'
cmd = None
regex = r'^:(?P<line>\d+):(?P<col>\d+): (?P<message>.+)'
line_col_base = (0, 0) # the lines and columns are 0-based
module = 'yaml'
def check(self, code, filename):
"""
Call directly the yaml module, and handles the exception. Return str.
Very similar to the SublimeLinter-json linter, except yaml is not in the python core library.
"""
yaml = self.module
try:
list(yaml.parse(code, Loader=yaml.BaseLoader))
except yaml.error.YAMLError as exc:
if persist.settings.get('debug'):
persist.printf('{} - {} : {}'.format(self.name, type(exc), exc))
message = '{} : {} {}'.format(type(exc).__name__, exc.problem, exc.context)
return ':{}:{}: {}\n'.format(exc.problem_mark.line, exc.problem_mark.column, message)
except Exception as exc:
persist.printf('{} - uncaught exception - {} : {}'.format(self.name, type(exc), exc))
return ''