summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAhmed El Gabri <ahmed@gabri.me>2017-02-05 18:26:26 +0100
committerAhmed El Gabri <ahmed@gabri.me>2017-02-05 21:19:34 +0100
commit119695bd08eb17c340cd22c6a044de324d86d511 (patch)
tree211102fc4a975b186aff93cb2c47a924a15889ec
parent744d7d789f859b70ea5981377600678c0ff4f6c2 (diff)
downloadale-119695bd08eb17c340cd22c6a044de324d86d511.zip
Add standard linter
-rw-r--r--README.md2
-rw-r--r--ale_linters/javascript/standard.vim71
-rw-r--r--test/test_standard_handler.vader44
3 files changed, 116 insertions, 1 deletions
diff --git a/README.md b/README.md
index 8a86f462..56a7486d 100644
--- a/README.md
+++ b/README.md
@@ -68,7 +68,7 @@ name. That seems to be the fairest way to arrange this table.
| Go | [gofmt -e](https://golang.org/cmd/gofmt/), [go vet](https://golang.org/cmd/vet/), [golint](https://godoc.org/github.com/golang/lint), [go build](https://golang.org/cmd/go/) |
| Haskell | [ghc](https://www.haskell.org/ghc/), [hlint](https://hackage.haskell.org/package/hlint) |
| HTML | [HTMLHint](http://htmlhint.com/), [tidy](http://www.html-tidy.org/) |
-| JavaScript | [eslint](http://eslint.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/), [flow](https://flowtype.org/) |
+| JavaScript | [eslint](http://eslint.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/), [flow](https://flowtype.org/), [standard](http://standardjs.com/)
| JSON | [jsonlint](http://zaa.ch/jsonlint/) |
| LaTeX | [chktex](http://www.nongnu.org/chktex/), [lacheck](https://www.ctan.org/pkg/lacheck) |
| Lua | [luacheck](https://github.com/mpeterv/luacheck) |
diff --git a/ale_linters/javascript/standard.vim b/ale_linters/javascript/standard.vim
new file mode 100644
index 00000000..9dc2d205
--- /dev/null
+++ b/ale_linters/javascript/standard.vim
@@ -0,0 +1,71 @@
+" Author: Ahmed El Gabri <@ahmedelgabri>
+" Description: standardjs for JavaScript files
+
+let g:ale_javascript_standard_executable =
+\ get(g:, 'ale_javascript_standard_executable', 'standard')
+
+let g:ale_javascript_standard_options =
+\ get(g:, 'ale_javascript_standard_options', '')
+
+let g:ale_javascript_standard_use_global =
+\ get(g:, 'ale_javascript_standard_use_global', 0)
+
+function! ale_linters#javascript#standard#GetExecutable(buffer) abort
+ if g:ale_javascript_standard_use_global
+ return g:ale_javascript_standard_executable
+ endif
+
+ return ale#util#ResolveLocalPath(
+ \ a:buffer,
+ \ 'node_modules/.bin/standard',
+ \ g:ale_javascript_standard_executable
+ \)
+endfunction
+
+function! ale_linters#javascript#standard#GetCommand(buffer) abort
+ return ale_linters#javascript#standard#GetExecutable(a:buffer)
+ \ . ' ' . g:ale_javascript_standard_options
+ \ . ' --stdin %s'
+endfunction
+
+function! ale_linters#javascript#standard#Handle(buffer, lines) abort
+ " Matches patterns line the following:
+ "
+ " /path/to/some-filename.js:47:14: Strings must use singlequote.
+ " /path/to/some-filename.js:56:41: Expected indentation of 2 spaces but found 4.
+ " /path/to/some-filename.js:13:3: Parsing error: Unexpected token
+ let l:pattern = '^.*:\(\d\+\):\(\d\+\): \(.\+\)$'
+ let l:output = []
+
+ for l:line in a:lines
+ let l:match = matchlist(l:line, l:pattern)
+
+ if len(l:match) == 0
+ continue
+ endif
+
+ let l:type = 'Error'
+ let l:text = l:match[3]
+
+ " vcol is Needed to indicate that the column is a character.
+ call add(l:output, {
+ \ 'bufnr': a:buffer,
+ \ 'lnum': l:match[1] + 0,
+ \ 'vcol': 0,
+ \ 'col': l:match[2] + 0,
+ \ 'text': l:text,
+ \ 'type': 'E',
+ \ 'nr': -1,
+ \})
+ endfor
+
+ return l:output
+endfunction
+
+call ale#linter#Define('javascript', {
+\ 'name': 'standard',
+\ 'executable_callback': 'ale_linters#javascript#standard#GetExecutable',
+\ 'command_callback': 'ale_linters#javascript#standard#GetCommand',
+\ 'callback': 'ale_linters#javascript#standard#Handle',
+\})
+
diff --git a/test/test_standard_handler.vader b/test/test_standard_handler.vader
new file mode 100644
index 00000000..1d1b71c4
--- /dev/null
+++ b/test/test_standard_handler.vader
@@ -0,0 +1,44 @@
+Execute(The standard handler should parse lines correctly):
+ runtime ale_linters/javascript/standard.vim
+
+ AssertEqual
+ \ [
+ \ {
+ \ 'bufnr': 347,
+ \ 'lnum': 47,
+ \ 'vcol': 0,
+ \ 'col': 14,
+ \ 'text': 'Expected indentation of 2 spaces but found 4.',
+ \ 'type': 'E',
+ \ 'nr': -1,
+ \ },
+ \ {
+ \ 'bufnr': 347,
+ \ 'lnum': 56,
+ \ 'vcol': 0,
+ \ 'col': 41,
+ \ 'text': 'Strings must use singlequote.',
+ \ 'type': 'E',
+ \ 'nr': -1,
+ \ },
+ \ {
+ \ 'bufnr': 347,
+ \ 'lnum': 13,
+ \ 'vcol': 0,
+ \ 'col': 3,
+ \ 'text': 'Parsing error: Unexpected token',
+ \ 'type': 'E',
+ \ 'nr': -1,
+ \ },
+ \ ],
+ \ ale_linters#javascript#standard#Handle(347, [
+ \ 'This line should be ignored completely',
+ \ '/path/to/some-filename.js:47:14: Expected indentation of 2 spaces but found 4.',
+ \ '/path/to/some-filename.js:56:41: Strings must use singlequote.',
+ \ 'This line should be ignored completely',
+ \ '/path/to/some-filename.js:13:3: Parsing error: Unexpected token',
+ \ ])
+
+After:
+ call ale#linter#Reset()
+