Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adjust column indices for tabs

  • Loading branch information...
commit d2bfe2f504160a20604dc012c154ff0a3860c37d 1 parent 408ba7f
@lunixbochs authored
Showing with 18 additions and 7 deletions.
  1. +16 −6 lint/linter.py
  2. +2 −1  sublimelint.py
View
22 lint/linter.py
@@ -25,10 +25,11 @@ class Linter:
languages = {}
linters = {}
- def __init__(self, view, syntax, filename=None):
+ def __init__(self, view, syntax, filename=None, tab_size=None):
self.view = view
self.syntax = syntax
self.filename = filename
+ self.tab_size = tab_size
if self.regex:
self.regex = re.compile(self.regex)
@@ -92,7 +93,7 @@ def reload(cls, mod):
for linter in linters:
if linter.__module__ == mod:
cls.linters[id].remove(linter)
- linter = cls.languages[linter.name](linter.view, linter.syntax, linter.filename)
+ linter = cls.languages[linter.name](linter.view, linter.syntax, linter.filename, linter.tab_size)
cls.linters[id].add(linter)
return
@@ -102,11 +103,12 @@ def text(cls, view):
return view.substr(sublime.Region(0, view.size())).encode('utf-8')
@classmethod
- def lint_view(cls, view_id, filename, code, callback):
+ def lint_view(cls, view_id, filename, tab_size, code, callback):
if view_id in cls.linters:
linters = tuple(cls.linters[view_id])
for linter in linters:
linter.filename = filename
+ linter.tab_size = tab_size
linter.lint(code)
# merge our result back to the main thread
@@ -141,6 +143,12 @@ def lint(self, code=None):
if match:
if row or row is 0:
if col or col is 0:
+ # expand tab characters in column number
+ code_line = self.highlight.full_line(row)
+ for char in code_line[:col]:
+ if char == '\t':
+ col += self.tab_size - 1
+
self.highlight.range(row, col)
elif near:
self.highlight.near(row, near)
@@ -189,8 +197,10 @@ def match_error(self, r, line):
error, row, col, near = [items[k] for k in ('error', 'line', 'col', 'near')]
row = int(row) - 1
- # TODO: columns wrt spaces vs tabs
- return match, row, int(col), error, near
+ if col:
+ col = int(col)
+
+ return match, row, col, error, near
return match, None, None, '', None
@@ -225,7 +235,7 @@ def create_environment(self):
def tmpfile(self, cmd, code, suffix=''):
if isinstance(cmd, basestring):
cmd = cmd,
-
+
f = tempfile.NamedTemporaryFile(suffix=suffix)
f.write(code)
f.flush()
View
3  sublimelint.py
@@ -47,9 +47,10 @@ def lint(self, view_id):
if view is not None:
filename = view.file_name()
+ tab_size = view.settings().get('tab_size')
persist.debug('SublimeLint: running on `%s`' % os.path.split(filename or 'untitled')[1])
code = Linter.text(view)
- thread.start_new_thread(Linter.lint_view, (view_id, filename, code, self.finish))
+ thread.start_new_thread(Linter.lint_view, (view_id, filename, tab_size, code, self.finish))
def finish(self, view, linters):
errors = {}
Please sign in to comment.
Something went wrong with that request. Please try again.