Skip to content

Instantly share code, notes, and snippets.

@minego
Forked from anonymous/.vimrc
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minego/c91b041ea5aad4573943 to your computer and use it in GitHub Desktop.
Save minego/c91b041ea5aad4573943 to your computer and use it in GitHub Desktop.
lint
" Call a lint script on write, it will call the appropriate lint tool for the
" file type. Show the results in the quickfix window.
function! Lint()
let current_file = shellescape(expand('%:p'))
let output = system('lint ' . current_file)
if strlen(output) > 0
" write quickfix errors to a temp file
let quickfix_tmpfile_name = tempname()
exe "redir! > " . quickfix_tmpfile_name
silent echon output
redir END
let s:quickfix_cmd = 'cfile '
" read in the errors temp file
execute "silent! " s:quickfix_cmd . quickfix_tmpfile_name
" open the quicfix window
botright copen
" Save the buffer so we can close it
let s:qfix_buffer = bufnr("$")
" delete the temp file
call delete(quickfix_tmpfile_name)
else
" No errors
if(exists("s:qfix_buffer"))
cclose
unlet s:qfix_buffer
endif
endif
endfunction
if has("autocmd")
autocmd BufWritePost,FileWritePost <buffer> call Lint()
endif
#!/bin/sh
# Run the proper lint tool on the specified file(s). Use the following to
# install the dependencies on arch linux:
#
# yaourt -S csslint
# yaourt -S nodejs-jsonlint
# yaourt -S nodejs-jshint
# TODO Pipe the various tools through a subscript to correct the syntax so it
# is consistent regardless of the file type.
if [ $# -le 0 ]; then
echo "Usage: $0 <filename>"
exit 1
fi
function lintc() {
return 0
}
function lintcss() {
csslint --quiet --format=compact --ignore=important \
"$1" \
| sed -e 's/: line /:/' -e 's/, col /:/'
}
function lintjs() {
# Try jshint, and fall back to jsl
which jshint > /dev/null
if [ $? -eq 0 ]; then
jshint --verbose "$1" \
| sed -e 's/: line /:/' -e 's/, col /:/' \
| grep -v \(W084\)$ \
| grep -v \(W004\)$ \
| grep -v \(W069\)$ \
| head -n -2
else
jsl -process "$1" \
-nofilelisting -nocontext \
-nosummary -nologo -conf ~/.jsl.conf
fi
}
function lintjson() {
jsonlint -q "$1"
}
while (( "$#" )); do
filename=$1
mimetype=`file --mime-type "$1"`
shift
case "$mimetype" in
"text/x-c")
lintc "$filename"
;;
esac
case "$filename" in
*.js)
lintjs "$filename"
;;
*.json)
lintjson "$filename"
;;
*.css)
lintcss "$filename"
;;
esac
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment