Skip to content

Instantly share code, notes, and snippets.

@dansouza
Created August 23, 2012 02:13
Show Gist options
  • Save dansouza/3431363 to your computer and use it in GitHub Desktop.
Save dansouza/3431363 to your computer and use it in GitHub Desktop.
Quick fix on SublimeLint's extras.py Lua() and PHP() classes so that Lua uses STDIN instead of a temporary file and PHP can also catch fatal errors
# extras.py - sublimelint plugin for simple external linters
from lint.linter import Linter
import os
class Coffee(Linter):
language = 'coffeescript'
cmd = ('coffee', '--compile', '--stdio')
regex = r'^[A-Za-z]+: (?P<error>.+) on line (?P<line>\d+)'
class Java(Linter):
language = 'java'
cmd = ('javac', '-Xlint')
regex = r'^[^:]+:(?P<line>\d+): (?P<error>.*)$'
def communicate(self, *args):
return self.tmpfile(*args, suffix='.java')
class JavaScript(Linter):
language = 'javascript'
cmd = ('jsl', '-stdin')
regex = r'^\((?P<line>\d+)\):\s+(?P<error>.+)'
class Lua(Linter):
# Dan: fixed this so that it uses stdin instead of a temporary file
language = 'lua'
cmd = ('luac', '-p', '-')
# changed the regex since " near 'XXX' " is always present
# http://www.lua.org/source/5.1/llex.c.html#luaX_lexerror
# also previous regex wasn't capturing the error messages
# properly (breaking up at the first character of the error)
# message
regex = r'^luac: [^:]+:(?P<line>\d+): (?P<error>.+) near \'(?P<near>.*)\''
class Nasm(Linter):
language = 'x86 assembly'
cmd = ('nasm', '-X', 'gnu', '-I.', '-o', os.devnull)
regex = r'^[^:]+:(?P<line>\d+): (?P<error>.*)$'
def communicate(self, cmd, code):
return self.tmpfile(cmd, code, suffix='.asm')
class Perl(Linter):
language = 'perl'
cmd = ('perl', '-c')
regex = r'(?P<error>.+?) at .+? line (?P<line>\d+)(, near "(?P<near>.+?)")?'
class PHP(Linter):
# Dan: fixed this so that it now handles PHP fatal errors too
# Now it does not distinguish between 'parse' and 'syntax' errors
# on <type>, but rather on <subtype> if present,
# and <type> can contain either "Parse" or "Fatal", so it distinguishes
# between a fatal error and a simple parse/syntax error.
language = ('php', 'html')
cmd = ('php', '-l', '-d display_errors=On')
regex = r'^(?P<type>Parse|Fatal) error:\s*((?P<subtype>parse|syntax) error,)?\s*(?P<error>.+?)?\s+in \- on line\s+(?P<line>\d+)'
def match_error(self, r, line):
match, row, col, error, near = super(PHP, self).match_error(r, line)
if match and match.group('type') == 'Parse' and not error:
error = 'parse error'
if match and match.group('type') == 'Fatal' and not error:
error = 'fatal error'
return match, row, col, error, near
class Ruby(Linter):
language = 'ruby'
cmd = ('ruby', '-wc')
regex = r'^.+:(?P<line>\d+):\s+(?P<error>.+)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment