Created
October 12, 2014 23:01
-
-
Save anonymous/17b7293c893a3965a015 to your computer and use it in GitHub Desktop.
Simple lint script that calls the correct tool for the file provided
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 "$1" \ | |
| sed -e 's/: line /:/' -e 's/, col /:/' | |
else | |
jsl -process "$1" \ | |
-nofilelisting -nocontext \ | |
-nosummary -nologo -conf ~/.jsl.conf | |
fi | |
} | |
function lintjson() { | |
jsonlint -c "$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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment