Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add CoffeeLint command

  • Loading branch information...
commit 1cf15a3aecadc11ad890d935a5fbbd9a32d000c0 1 parent c218d63
@kchmck authored
Showing with 84 additions and 1 deletion.
  1. +17 −0 Readme.md
  2. +17 −1 doc/coffee-script.txt
  3. +50 −0 ftplugin/coffee.vim
View
17 Readme.md
@@ -187,6 +187,23 @@ Use `unwatch` to stop watching a buffer:
:CoffeeCompile unwatch
+### CoffeeLint: Lint your CoffeeScript
+
+The `CoffeeLint` command runs [coffeelint](http://www.coffeelint.org/) on the
+current file and parses any errors:
+
+ :[RANGE] CoffeeLint[!] [COFFEELINT-OPTIONS]
+
+Use it like `CoffeeMake`.
+
+ :CoffeeLint! | cwindow
+
+#### Default coffeelint options
+
+Options in `coffee_lint_options` are passed along to coffeelint.
+
+ let coffee_lint_options = '-f lint.json'
+
### CoffeeRun: Run some CoffeeScript
The `CoffeeRun` command compiles the current file or selected snippet and runs
View
18 doc/coffee-script.txt
@@ -28,7 +28,7 @@ COMMANDS *coffee-script-commands*
:CoffeeMake[!] {opts} Wrapper around |:make| that also passes options in
|g:coffee_make_options| to the compiler. Use |:silent|
to hide compiler output. See |:make| for more
- information about the bang and other helpful commands.
+ information about [!] and other helpful commands.
*:CoffeeCompile*
:[range]CoffeeCompile [vertical] [{win-size}]
@@ -48,6 +48,16 @@ COMMANDS *coffee-script-commands*
automatic updating. [vertical] is recommended, and
'scrollbind' is useful.
+ *:CoffeeLint*
+:[range]CoffeeLint[!] {opts}
+ Run {coffeelint} on the current file and add any
+ errors to the quickfix list. The first error is jumped
+ to if [!] isn't given. Options in
+ |g:coffee_lint_options| and {opts} are passed along to
+ {coffeelint}. Although the whole file is linted, if a
+ [range] is given, only errors within those lines will
+ be added.
+
*:CoffeeRun*
:[range]CoffeeRun Compiles the file or [range] and runs the resulting
JavaScript, displaying the output.
@@ -72,6 +82,12 @@ Set default options |CoffeeMake| should pass to the compiler.
Split the CoffeeCompile buffer vertically by default.
>
let coffee_compile_vert = 1
+<
+ *g:coffee_lint_options*
+Set default options |CoffeeLint| should pass to {coffeelint}.
+>
+ let coffee_lint_options = '-f lint.json'
+<
Syntax Highlighting~
*ft-coffee-script-syntax*
View
50 ftplugin/coffee.vim
@@ -19,6 +19,11 @@ if !len(&l:makeprg)
compiler coffee
endif
+" Options passed to CoffeeLint
+if !exists('coffee_lint_options')
+ let coffee_lint_options = ''
+endif
+
" Reset the CoffeeCompile variables for the current buffer.
function! s:CoffeeCompileResetVars()
" Compiled output buffer
@@ -190,6 +195,48 @@ function! s:CoffeeCompileComplete(arg, cmdline, cursor)
endfor
endfunction
+" Run coffeelint on a file, and add any errors between @startline and @endline
+" to the quickfix list.
+function! s:CoffeeLint(startline, endline, bang, args)
+ let filename = expand('%')
+
+ if !len(filename)
+ echoerr 'CoffeeLint must be ran on a saved file'
+ return
+ endif
+
+ let lines = split(system('coffeelint ' . g:coffee_lint_options . ' ' . a:args
+ \ . ' ' . filename . ' 2>&1'), '\n')
+ let qflist = []
+
+ for line in lines
+ let match = matchlist(line, '\f\+#\(\d\+\) : error : \(.\+\)')
+
+ " Ignore invalid lines.
+ if !len(match)
+ continue
+ endif
+
+ let lnum = str2nr(match[1])
+
+ " Don't add the error if it's not in the range.
+ if lnum < a:startline || lnum > a:endline
+ continue
+ endif
+
+ let text = match[2]
+
+ call add(qflist, {'bufnr': bufnr('%'), 'lnum': lnum, 'text': text})
+ endfor
+
+ call setqflist(qflist, 'r')
+
+ " Don't jump if there's a bang.
+ if !len(a:bang)
+ silent! cc 1
+ endif
+endfunction
+
" Don't overwrite the CoffeeCompile variables.
if !exists('b:coffee_compile_buf')
call s:CoffeeCompileResetVars()
@@ -200,3 +247,6 @@ command! -range=% -bar -nargs=* -complete=customlist,s:CoffeeCompileComplete
\ CoffeeCompile call s:CoffeeCompile(<line1>, <line2>, <q-args>)
" Run some CoffeeScript.
command! -range=% -bar CoffeeRun <line1>,<line2>:w !coffee -s
+" Run coffeelint on the file.
+command! -range=% -bang -bar -nargs=* CoffeeLint
+\ call s:CoffeeLint(<line1>, <line2>, '<bang>', <q-args>)
Please sign in to comment.
Something went wrong with that request. Please try again.