Fix #308 - Check Dart files with dartanalyzer
This commit is contained in:
parent
aa94d0902a
commit
235fc90e22
@ -71,6 +71,7 @@ name. That seems to be the fairest way to arrange this table.
|
||||
| CSS | [csslint](http://csslint.net/), [stylelint](https://github.com/stylelint/stylelint) |
|
||||
| Cython (pyrex filetype) | [cython](http://cython.org/) |
|
||||
| D | [dmd](https://dlang.org/dmd-linux.html) |
|
||||
| Dart | [dartanalyzer](https://github.com/dart-lang/sdk/tree/master/pkg/analyzer_cli) |
|
||||
| Dockerfile | [hadolint](https://github.com/lukasmartinelli/hadolint) |
|
||||
| Elixir | [credo](https://github.com/rrrene/credo), [dogma](https://github.com/lpil/dogma) |
|
||||
| Elm | [elm-make](https://github.com/elm-lang/elm-make) |
|
||||
|
40
ale_linters/dart/dartanalyzer.vim
Normal file
40
ale_linters/dart/dartanalyzer.vim
Normal file
@ -0,0 +1,40 @@
|
||||
" Author: w0rp <devw0rp@gmail.com>
|
||||
" Description: Check Dart files with dartanalyzer
|
||||
|
||||
call ale#Set('dart_dartanalyzer_executable', 'dartanalyzer')
|
||||
|
||||
function! ale_linters#dart#dartanalyzer#GetExecutable(buffer) abort
|
||||
return ale#Var(a:buffer, 'dart_dartanalyzer_executable')
|
||||
endfunction
|
||||
|
||||
function! ale_linters#dart#dartanalyzer#GetCommand(buffer) abort
|
||||
let l:executable = ale_linters#dart#dartanalyzer#GetExecutable(a:buffer)
|
||||
let l:path = ale#path#FindNearestFile(a:buffer, '.packages')
|
||||
|
||||
return ale#Escape(l:executable)
|
||||
\ . (!empty(l:path) ? ' --packages ' . ale#Escape(l:path) : '')
|
||||
\ . ' %t'
|
||||
endfunction
|
||||
|
||||
function! ale_linters#dart#dartanalyzer#Handle(buffer, lines) abort
|
||||
let l:pattern = '\v^ ([a-z]+) . (.+) at (.+):(\d+):(\d+) . (.+)$'
|
||||
let l:output = []
|
||||
|
||||
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||
call add(l:output, {
|
||||
\ 'type': l:match[1] ==# 'error' ? 'E' : 'W',
|
||||
\ 'text': l:match[6] . ': ' . l:match[2],
|
||||
\ 'lnum': str2nr(l:match[4]),
|
||||
\ 'col': str2nr(l:match[5]),
|
||||
\})
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('dart', {
|
||||
\ 'name': 'dartanalyzer',
|
||||
\ 'executable_callback': 'ale_linters#dart#dartanalyzer#GetExecutable',
|
||||
\ 'command_callback': 'ale_linters#dart#dartanalyzer#GetCommand',
|
||||
\ 'callback': 'ale_linters#dart#dartanalyzer#Handle',
|
||||
\})
|
36
doc/ale-dart.txt
Normal file
36
doc/ale-dart.txt
Normal file
@ -0,0 +1,36 @@
|
||||
===============================================================================
|
||||
ALE Dart Integration *ale-dart-options*
|
||||
|
||||
|
||||
===============================================================================
|
||||
dartanalyzer *ale-dart-dartanalyzer*
|
||||
|
||||
Installation
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Install Dart via whatever means. `dartanalyzer` will be included in the SDK.
|
||||
|
||||
You can add the SDK to `$PATH`, as described here:
|
||||
https://www.dartlang.org/tools/sdk
|
||||
|
||||
If you have installed Dart on Linux, you can also try the following: >
|
||||
" Set the executable path for dartanalyzer to the absolute path to it.
|
||||
let g:ale_dart_dartanalyzer_executable = '/usr/lib/dart/bin/dartanalyzer'
|
||||
<
|
||||
... or similarly for wherever your Dart SDK lives. This should work without
|
||||
having to modify `$PATH`.
|
||||
|
||||
|
||||
Options
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
g:ale_dart_dartanalyzer_executable *g:ale_dart_dartanalyzer_executable*
|
||||
*b:ale_dart_dartanalyzer_executable*
|
||||
Type: |String|
|
||||
Default: `'dartanalyzer'`
|
||||
|
||||
This variable can be set to change the path to dartanalyzer.
|
||||
|
||||
|
||||
===============================================================================
|
||||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
@ -31,6 +31,8 @@ CONTENTS *ale-contents*
|
||||
stylelint...........................|ale-css-stylelint|
|
||||
cmake.................................|ale-cmake-options|
|
||||
cmakelint...........................|ale-cmake-cmakelint|
|
||||
dart..................................|ale-dart-options|
|
||||
dartanalyzer........................|ale-dart-dartanalyzer|
|
||||
erlang................................|ale-erlang-options|
|
||||
erlc................................|ale-erlang-erlc|
|
||||
syntaxerl...........................|ale-erlang-syntaxerl|
|
||||
@ -172,6 +174,7 @@ The following languages and tools are supported.
|
||||
* CSS: 'csslint', 'stylelint'
|
||||
* Cython (pyrex filetype): 'cython'
|
||||
* D: 'dmd'
|
||||
* Dart: 'dartanalyzer'
|
||||
* Dockerfile: 'hadolint'
|
||||
* Elixir: 'credo', 'dogma'
|
||||
* Elm: 'elm-make'
|
||||
|
0
test/command_callback/dart_paths/.packages
Normal file
0
test/command_callback/dart_paths/.packages
Normal file
@ -0,0 +1,40 @@
|
||||
Before:
|
||||
Save g:ale_dart_dartanalyzer_executable
|
||||
unlet! g:ale_dart_dartanalyzer_executable
|
||||
|
||||
runtime ale_linters/dart/dartanalyzer.vim
|
||||
|
||||
call ale#test#SetDirectory('/testplugin/test/command_callback')
|
||||
|
||||
After:
|
||||
Restore
|
||||
|
||||
call ale#test#RestoreDirectory()
|
||||
call ale#linter#Reset()
|
||||
|
||||
Execute(The default command and executable should be correct):
|
||||
AssertEqual
|
||||
\ 'dartanalyzer',
|
||||
\ ale_linters#dart#dartanalyzer#GetExecutable(bufnr(''))
|
||||
AssertEqual
|
||||
\ ale#Escape('dartanalyzer') . ' %t',
|
||||
\ ale_linters#dart#dartanalyzer#GetCommand(bufnr(''))
|
||||
|
||||
Execute(The executable should be configurable):
|
||||
let g:ale_dart_dartanalyzer_executable = '/usr/lib/dart/bin/dartanalyzer'
|
||||
|
||||
AssertEqual
|
||||
\ '/usr/lib/dart/bin/dartanalyzer',
|
||||
\ ale_linters#dart#dartanalyzer#GetExecutable(bufnr(''))
|
||||
AssertEqual
|
||||
\ ale#Escape('/usr/lib/dart/bin/dartanalyzer') . ' %t',
|
||||
\ ale_linters#dart#dartanalyzer#GetCommand(bufnr(''))
|
||||
|
||||
Execute(The .packages file should be set if detected):
|
||||
call ale#test#SetFilename('dart_paths/foo')
|
||||
|
||||
AssertEqual
|
||||
\ ale#Escape('dartanalyzer')
|
||||
\ . ' --packages ' . ale#Escape(g:dir . '/dart_paths/.packages')
|
||||
\ . ' %t',
|
||||
\ ale_linters#dart#dartanalyzer#GetCommand(bufnr(''))
|
28
test/handler/test_dartanalyzer_handler.vader
Normal file
28
test/handler/test_dartanalyzer_handler.vader
Normal file
@ -0,0 +1,28 @@
|
||||
Before:
|
||||
runtime ale_linters/dart/dartanalyzer.vim
|
||||
|
||||
After:
|
||||
call ale#linter#Reset()
|
||||
|
||||
Execute(Basic problems should be parsed correctly):
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'expected_token: Expected to find ''}''',
|
||||
\ 'lnum': 5,
|
||||
\ 'col': 1,
|
||||
\ },
|
||||
\ {
|
||||
\ 'type': 'W',
|
||||
\ 'text': 'invalid_assignment: A value of type ''String'' can''t be assigned to a variable of type ''int''',
|
||||
\ 'lnum': 2,
|
||||
\ 'col': 16,
|
||||
\ },
|
||||
\ ],
|
||||
\ ale_linters#dart#dartanalyzer#Handle(bufnr(''), [
|
||||
\ 'Analyzing main.dart...',
|
||||
\ ' error • Expected to find ''}'' at main.dart:5:1 • expected_token',
|
||||
\ ' warning • A value of type ''String'' can''t be assigned to a variable of type ''int'' at main.dart:2:16 • invalid_assignment',
|
||||
\ '1 error and 1 warning found.',
|
||||
\ ])
|
Loading…
Reference in New Issue
Block a user