Skip to content

Commit

Permalink
Merge commit 'smith/ranged' into ranged
Browse files Browse the repository at this point in the history
Conflicts:
	plugin/jslint/jslint.vim
  • Loading branch information
hallettj committed Aug 6, 2009
2 parents 1c93cc1 + 9f4b4cc commit 0bf9250
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 34 deletions.
50 changes: 36 additions & 14 deletions plugin/jslint/jslint.vim
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
function! s:JSLint()
function! s:JSLint() range
cclose " Close quickfix window
cexpr [] " Create empty quickfix list

" Detect range
if a:firstline == a:lastline
let b:firstline = 1
let b:lastline = '$'
else
let b:firstline = a:firstline
let b:lastline = a:lastline
endif

" Delete previous matches
if exists('b:errors')
for error in b:errors
call matchdelete(error)
endfor
endif

let b:errors = []

" Set up command and parameters
let s:plugin_path = '"' . expand("~/") . '"'
if has("win32")
let s:cmd = 'cscript'
let s:cmd = 'cscript /NoLogo '
let s:plugin_path = s:plugin_path . "vimfiles"
let s:runjslint_ext = 'wsf'
else
Expand All @@ -20,22 +31,33 @@ function! s:JSLint()
endif
let s:plugin_path = s:plugin_path . "/plugin/jslint/"
let s:cmd = "cd " . s:plugin_path . " && " . s:cmd . " " . s:plugin_path
\ . "runjslint." . s:runjslint_ext
\ . "runjslint." . s:runjslint_ext
let b:jslint_output = system(s:cmd, join(getline(b:firstline, b:lastline),
\ "\n") . "\n")

let b:jslint_output = system(s:cmd, join(getline(1, '$'), "\n") . "\n")
let b:errors = []
let b:has_errors = 0

for error in split(b:jslint_output, "\n")
let b:parts = matchlist(error, "line\\s\\+\\(\\d\\+\\)\\s\\+")
" Match {line}:{char}:{message}
let b:parts = matchlist(error, "\\(\\d\\+\\):\\(\\d\\+\\):\\(.*\\)")
if !empty(b:parts)
call add(b:errors, matchadd('Error', '\%'.b:parts[1].'l'))
if b:parts[1] == line('.')
echo(error)
endif
elseif error ==? "All Good."
echo "JSLint: " . error
let b:has_errors = 1
let l:line = b:parts[1] + (b:firstline - 1) " Get line relative to selection
" Add line to match list
call add(b:errors, matchadd('Error', '\%' . l:line . 'l'))
" Add to quickfix
caddexpr expand("%") . ":" . l:line . ":" . b:parts[2] . ":" . b:parts[3]
endif
endfor

" Open the quickfix window if errors are present
if b:has_errors == 1
copen
else " Or not
echo "JSLint: All good."
endif
endfunction

command! JSLint :call s:JSLint()
command! -range JSLint <line1>,<line2>call s:JSLint()

19 changes: 10 additions & 9 deletions plugin/jslint/runjslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ var readSTDIN = function() {
};

var body = readSTDIN() || arguments[0],
result = JSLINT(body),
ok = JSLINT(body),
i,
error;
error,
errorCount;

if (result) {
print('All good.');
} else {
print('Error:');
for (i = 0; i < JSLINT.errors.length; i++) {
if (!ok) {
errorCount = JSLINT.errors.length;
for (i = 0; i < errorCount; i += 1) {
error = JSLINT.errors[i];
print('Problem at line ' + error.line + ' character ' + error.character + ': ' + error.reason);
print(error.evidence);
if (error && error.reason && error.reason.match(/^Stopping/) === null) {
print([error.line, error.character, error.reason].join(":"));
}
}
}

21 changes: 10 additions & 11 deletions plugin/jslint/runjslint.wsf
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,20 @@ var readSTDIN = function() {
};

var body = readSTDIN() || arguments[0],
result = JSLINT(body),
ok = JSLINT(body),
i,
error;

if (result) {
WScript.echo('All good.');
} else {
WScript.echo('Error:');
for (i = 0; i < JSLINT.errors.length; i++) {
error,
errorCount;

if (!ok) {
errorCount = JSLINT.errors.length;
for (i = 0; i < errorCount; i += 1) {
error = JSLINT.errors[i];
if (error) {
WScript.echo('Problem at line ' + error.line + ' character ' + error.character + ': ' + error.reason);
WScript.echo(error.evidence);
if (error && error.reason && error.reason.match(/^Stopping/) === null) {
WScript.echo([error.line, error.character, error.reason].join(":"));
}
}
}
</script>
</job>

0 comments on commit 0bf9250

Please sign in to comment.