Permalink
Browse files

adding support for gjslint and jshint at the same time

  • Loading branch information...
Mike Tanaka
Mike Tanaka committed Mar 19, 2013
1 parent f1f3a9f commit cc2b92624f5d29a0aa47368aaeb6e15097dc678e
Showing with 30 additions and 0 deletions.
  1. +30 −0 sublimelinter/modules/javascript.py
@@ -14,6 +14,7 @@
class Linter(BaseLinter):
GJSLINT_RE = re.compile(r'Line (?P<line>\d+),\s*E:(?P<errnum>\d+):\s*(?P<message>.+)')
JSHINT_RE = re.compile(r'.+\.js:\sline\s(?P<line>\d+),\scol\s(?P<col>\d+),\s*(?P<message>.+)')
def __init__(self, config):
super(Linter, self).__init__(config)
@@ -32,6 +33,15 @@ def get_executable(self, view):
return (True, path, 'using gjslint')
except OSError:
return (False, '', 'gjslint cannot be found')
elif (self.linter == 'both'):
try:
path = self.get_mapped_executable(view, 'both')
subprocess.call([path], startupinfo=self.get_startupinfo())
self.input_method = INPUT_METHOD_TEMP_FILE
return (True, path, path + ' using both')
except OSError:
return (False, '', 'gjslint cannot be found')
else:
return (False, '', '"{0}" is not a valid javascript linter'.format(self.linter))
@@ -44,6 +54,10 @@ def get_lint_args(self, view, code, filename):
return args
elif (self.linter in ('jshint', 'jslint')):
return self.get_javascript_args(view, self.linter, code)
elif (self.linter == 'both'):
args = []
args.extend([filename])
return args
else:
return []
@@ -68,6 +82,22 @@ def parse_errors(self, view, errors, lines, errorUnderlines, violationUnderlines
if (int(errnum) not in ignore):
self.add_message(int(line), lines, message, errorMessages)
elif (self.linter == 'both'):
ignore = view.settings().get('gjslint_ignore', [])
for line in errors.splitlines():
match = self.GJSLINT_RE.match(line)
if match:
line, errnum, message = match.group('line'), match.group('errnum'), match.group('message')
if (int(errnum) not in ignore):
self.add_message(int(line), lines, message, errorMessages)
match_jshint = self.JSHINT_RE.match(line)
if match_jshint:
line, col, message = match_jshint.group('line'), match_jshint.group('col'), match_jshint.group('message')
self.add_message(int(line), lines, message, errorMessages)
self.underline_range(view, int(line), int(col), errorUnderlines)
elif (self.linter in ('jshint', 'jslint')):
try:
errors = json.loads(errors.strip() or '[]')

0 comments on commit cc2b926

Please sign in to comment.