コード例 #1
0
ファイル: linter.py プロジェクト: bronson/SublimeLint
	def lint(self, code):
		if not (self.language and self.cmd and self.regex):
			raise NotImplementedError

		output = self.communicate(self.cmd, code)
		if output:
			persist.debug('Output:', repr(output))

			for match, row, col, message, near in self.find_errors(output):
				if match:
					if row or row is 0:
						if col or col is 0:
							# adjust column numbers to match the linter's tabs if necessary
							if self.tab_size > 1:
								start, end = self.highlight.full_line(row)
								code_line = code[start:end]
								diff = 0
								for i in xrange(len(code_line)):
									if code_line[i] == '\t':
										diff += (self.tab_size - 1)

									if col - diff <= i:
										col = i
										break

							self.highlight.range(row, col)
						elif near:
							self.highlight.near(row, near)
						else:
							self.highlight.line(row)

					self.error(row, message)
コード例 #2
0
ファイル: linter.py プロジェクト: bronson/SublimeLint
    def lint(self, code):
        if not (self.language and self.cmd and self.regex):
            raise NotImplementedError

        output = self.communicate(self.cmd, code)
        if output:
            persist.debug('Output:', repr(output))

            for match, row, col, message, near in self.find_errors(output):
                if match:
                    if row or row is 0:
                        if col or col is 0:
                            # adjust column numbers to match the linter's tabs if necessary
                            if self.tab_size > 1:
                                start, end = self.highlight.full_line(row)
                                code_line = code[start:end]
                                diff = 0
                                for i in xrange(len(code_line)):
                                    if code_line[i] == '\t':
                                        diff += (self.tab_size - 1)

                                    if col - diff <= i:
                                        col = i
                                        break

                            self.highlight.range(row, col)
                        elif near:
                            self.highlight.near(row, near)
                        else:
                            self.highlight.line(row)

                    self.error(row, message)
コード例 #3
0
	def load(self, name):
		persist.debug('SublimeLint: loading `%s`' % name)
		pushd = os.getcwd()
		os.chdir(self.base)
		path = list(sys.path)

		sys.path.insert(0, self.path)

		try:
			__import__(name)

			# first, we get the actual module from sys.modules, not the base mod returned by __import__
			# second, we get an updated version of the module with reload() so development is easier
			mod = sys.modules[name] = reload(sys.modules[name])
		except:
			persist.debug('SublimeLint: error importing `%s`' % name)
			persist.debug('-'*20)
			persist.debug(traceback.format_exc())
			persist.debug('-'*20)

		self.modules[name] = mod

		# update module's __file__ with the absolute path so we know to reload it if Sublime Text saves that path
		mod.__file__ = os.path.abspath(mod.__file__).rstrip('co') # strip .pyc/.pyo to just .py

		sys.path = path
		os.chdir(pushd)

		return mod
コード例 #4
0
ファイル: linter.py プロジェクト: ktaragorn/sublimelint
    def lint_view(cls, view_id, filename, code, sections, callback):
        if view_id in cls.linters:
            selectors = Linter.get_selectors(view_id)

            linters = tuple(cls.linters[view_id])
            linter_text = ", ".join(l.name for l in linters)
            persist.debug("SublimeLint: `%s` as %s" % (filename or "untitled", linter_text))
            for linter in linters:
                if linter.settings.get("disable"):
                    continue

                if not linter.selector:
                    linter.filename = filename
                    linter.pre_lint(code)

            for sel, linter in selectors:
                if sel in sections:
                    highlight = Highlight(code, scope=linter.scope, outline=linter.outline)
                    errors = {}

                    for line_offset, left, right in sections[sel]:
                        highlight.shift(line_offset, left)
                        linter.pre_lint(code[left:right], highlight=highlight)

                        for line, error in linter.errors.items():
                            errors[line + line_offset] = error

                    linter.errors = errors

                    # merge our result back to the main thread
            sublime.set_timeout(lambda: callback(linters[0].view, linters), 0)
コード例 #5
0
ファイル: modules.py プロジェクト: Ephemerall/sublimelint
	def load(self, name):
		persist.debug('SublimeLint: loading `%s`' % name)
		pushd = os.getcwd()
		os.chdir(self.base)
		path = list(sys.path)

		sys.path.insert(0, self.path)

		mod = None
		try:
			__import__(name)

			# first, we get the actual module from sys.modules, not the base mod returned by __import__
			# second, we get an updated version of the module with reload() so development is easier
			mod = sys.modules[name] = reload(sys.modules[name])
		except:
			persist.debug('SublimeLint: error importing `%s`' % name)
			persist.debug('-'*20)
			persist.debug(traceback.format_exc())
			persist.debug('-'*20)

		if not mod:
			return

		self.modules[name] = mod

		# update module's __file__ with the absolute path so we know to reload it if Sublime Text saves that path
		mod.__file__ = os.path.abspath(mod.__file__).rstrip('co') # strip .pyc/.pyo to just .py

		sys.path = path
		os.chdir(pushd)

		return mod
コード例 #6
0
ファイル: linter.py プロジェクト: floger/sublimetext2-config
    def lint_view(cls, view_id, filename, code, sections, callback):
        if view_id in cls.linters:
            selectors = Linter.get_selectors(view_id)

            linters = tuple(cls.linters[view_id])
            linter_text = (', '.join(l.name for l in linters))
            persist.debug('SublimeLint: `%s` as %s' %
                          (filename or 'untitled', linter_text))
            for linter in linters:
                if linter.settings.get('disable'):
                    continue

                if not linter.selector:
                    linter.filename = filename
                    linter.pre_lint(code)

            for sel, linter in selectors:
                if sel in sections:
                    highlight = Highlight(code,
                                          scope=linter.scope,
                                          outline=linter.outline)
                    errors = {}

                    for line_offset, left, right in sections[sel]:
                        highlight.shift(line_offset, left)
                        linter.pre_lint(code[left:right], highlight=highlight)

                        for line, error in linter.errors.items():
                            errors[line + line_offset] = error

                    linter.errors = errors

            # merge our result back to the main thread
            sublime.set_timeout(lambda: callback(linters[0].view, linters), 0)
コード例 #7
0
ファイル: util.py プロジェクト: Ephemerall/sublimelint
def popen(cmd, env=None):
	if isinstance(cmd, basestring):
		cmd = cmd,

	info = None
	if os.name == 'nt':
		info = subprocess.STARTUPINFO()
		info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
		info.wShowWindow = subprocess.SW_HIDE

	if env is None:
		env = create_environment()

	try:
		return subprocess.Popen(cmd, stdin=subprocess.PIPE,
			stdout=subprocess.PIPE, stderr=subprocess.PIPE,
			startupinfo=info, env=env)
	except OSError, err:
		persist.debug('SublimeLint: Error launching', repr(cmd))
		persist.debug('Error was:', err.strerror)
コード例 #8
0
def popen(cmd, env=None):
	if isinstance(cmd, basestring):
		cmd = cmd,

	info = None
	if os.name == 'nt':
		info = subprocess.STARTUPINFO()
		info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
		info.wShowWindow = subprocess.SW_HIDE

	if env is None:
		env = create_environment()

	try:
		return subprocess.Popen(cmd, stdin=subprocess.PIPE,
			stdout=subprocess.PIPE, stderr=subprocess.PIPE,
			startupinfo=info, env=env)
	except OSError, err:
		persist.debug('SublimeLint: Error launching', repr(cmd))
		persist.debug('Error was:', err.strerror)