mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-15 08:47:06 +08:00
Add support for dart analyze (#3825)
This commit is contained in:
28
ale_linters/dart/dart_analyze.vim
Normal file
28
ale_linters/dart/dart_analyze.vim
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
" Author: ghsang <gwonhyuksang@gmail.com>
|
||||||
|
" Description: Check Dart files with dart analyze
|
||||||
|
|
||||||
|
call ale#Set('dart_analyze_executable', 'dart')
|
||||||
|
|
||||||
|
function! ale_linters#dart#dart_analyze#Handle(buffer, lines) abort
|
||||||
|
let l:pattern = '\v^ ([a-z]+) - (.+):(\d+):(\d+) - (.+) - (.+)$'
|
||||||
|
let l:output = []
|
||||||
|
|
||||||
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||||
|
call add(l:output, {
|
||||||
|
\ 'type': l:match[1] is# 'error' ? 'E' : 'W',
|
||||||
|
\ 'text': l:match[6] . ': ' . l:match[5],
|
||||||
|
\ 'lnum': str2nr(l:match[3]),
|
||||||
|
\ 'col': str2nr(l:match[4]),
|
||||||
|
\})
|
||||||
|
endfor
|
||||||
|
|
||||||
|
return l:output
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
call ale#linter#Define('dart', {
|
||||||
|
\ 'name': 'dart_analyze',
|
||||||
|
\ 'executable': {b -> ale#Var(b, 'dart_analyze_executable')},
|
||||||
|
\ 'command': '%e analyze %s',
|
||||||
|
\ 'callback': 'ale_linters#dart#dart_analyze#Handle',
|
||||||
|
\ 'lint_file': 1,
|
||||||
|
\})
|
||||||
@@ -27,6 +27,67 @@ g:ale_dart_analysis_server_executable *g:ale_dart_analysis_server_executable*
|
|||||||
This variable can be set to change the path of dart.
|
This variable can be set to change the path of dart.
|
||||||
|
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
dart-analyze *ale-dart-analyze*
|
||||||
|
|
||||||
|
Installation
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Installing Dart should probably ensure that `dart` is in your `$PATH`.
|
||||||
|
|
||||||
|
In case it is not, try to set the executable option to its absolute path. : >
|
||||||
|
" Set the executable path for dart to the absolute path to it.
|
||||||
|
let g:ale_dart_format_executable = '/usr/lib/dart/bin/dart'
|
||||||
|
>
|
||||||
|
|
||||||
|
Install Dart via whatever means. `dart analyze` will be included in the SDK.
|
||||||
|
|
||||||
|
Options
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
g:ale_dart_analyze_executable *g:ale_dart_analyze_executable*
|
||||||
|
*b:ale_dart_analyze_executable*
|
||||||
|
Type: |String|
|
||||||
|
Default: `'dart'`
|
||||||
|
|
||||||
|
This variable can be set to specify an absolute path to the
|
||||||
|
format executable (or to specify an alternate executable).
|
||||||
|
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
dart-format *ale-dart-format*
|
||||||
|
|
||||||
|
Installation
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Installing Dart should probably ensure that `dart` is in your `$PATH`.
|
||||||
|
|
||||||
|
In case it is not, try to set the executable option to its absolute path. : >
|
||||||
|
" Set the executable path for dart to the absolute path to it.
|
||||||
|
let g:ale_dart_format_executable = '/usr/lib/dart/bin/dart'
|
||||||
|
>
|
||||||
|
|
||||||
|
Options
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
g:ale_dart_format_executable *g:ale_dart_format_executable*
|
||||||
|
*b:ale_dart_format_executable*
|
||||||
|
Type: |String|
|
||||||
|
Default: `'dart'`
|
||||||
|
|
||||||
|
This variable can be set to specify an absolute path to the
|
||||||
|
format executable (or to specify an alternate executable).
|
||||||
|
|
||||||
|
|
||||||
|
g:ale_dart_format_options *g:ale_dart_format_options*
|
||||||
|
*b:ale_dart_format_options*
|
||||||
|
Type: |String|
|
||||||
|
Default: `''`
|
||||||
|
|
||||||
|
This variable can be set to pass additional options to the dart format fixer.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
dartanalyzer *ale-dart-dartanalyzer*
|
dartanalyzer *ale-dart-dartanalyzer*
|
||||||
|
|
||||||
@@ -58,37 +119,6 @@ g:ale_dart_dartanalyzer_executable *g:ale_dart_dartanalyzer_executable*
|
|||||||
|
|
||||||
This variable can be set to change the path to dartanalyzer.
|
This variable can be set to change the path to dartanalyzer.
|
||||||
|
|
||||||
===============================================================================
|
|
||||||
dart-format *ale-dart-format*
|
|
||||||
|
|
||||||
Installation
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
Installing Dart should probably ensure that `dart` is in your `$PATH`.
|
|
||||||
|
|
||||||
In case it is not, try to set the executable option to its absolute path. : >
|
|
||||||
" Set the executable path for dart to the absolute path to it.
|
|
||||||
let g:ale_dart_format_executable = '/usr/lib/dart/bin/dart'
|
|
||||||
>
|
|
||||||
|
|
||||||
Options
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
g:ale_dart_format_executable *g:ale_dart_format_executable*
|
|
||||||
*b:ale_dart_format_executable*
|
|
||||||
Type: |String|
|
|
||||||
Default: `'dart'`
|
|
||||||
|
|
||||||
This variable can be set to specify an absolute path to the
|
|
||||||
format executable (or to specify an alternate executable).
|
|
||||||
|
|
||||||
|
|
||||||
g:ale_dart_format_options *g:ale_dart_format_options*
|
|
||||||
*b:ale_dart_format_options*
|
|
||||||
Type: |String|
|
|
||||||
Default: `''`
|
|
||||||
|
|
||||||
This variable can be set to pass additional options to the dart format fixer.
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
dartfmt *ale-dart-dartfmt*
|
dartfmt *ale-dart-dartfmt*
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ Notes:
|
|||||||
* `dafny`!!
|
* `dafny`!!
|
||||||
* Dart
|
* Dart
|
||||||
* `analysis_server`
|
* `analysis_server`
|
||||||
|
* `dart-analyze`!!
|
||||||
* `dart-format`!!
|
* `dart-format`!!
|
||||||
* `dartanalyzer`!!
|
* `dartanalyzer`!!
|
||||||
* `dartfmt`!!
|
* `dartfmt`!!
|
||||||
|
|||||||
@@ -2700,8 +2700,9 @@ documented in additional help files.
|
|||||||
dafny.................................|ale-dafny-dafny|
|
dafny.................................|ale-dafny-dafny|
|
||||||
dart....................................|ale-dart-options|
|
dart....................................|ale-dart-options|
|
||||||
analysis_server.......................|ale-dart-analysis_server|
|
analysis_server.......................|ale-dart-analysis_server|
|
||||||
dartanalyzer..........................|ale-dart-dartanalyzer|
|
dart-analyze..........................|ale-dart-analyze|
|
||||||
dart-format...........................|ale-dart-format|
|
dart-format...........................|ale-dart-format|
|
||||||
|
dartanalyzer..........................|ale-dart-dartanalyzer|
|
||||||
dartfmt...............................|ale-dart-dartfmt|
|
dartfmt...............................|ale-dart-dartfmt|
|
||||||
desktop.................................|ale-desktop-options|
|
desktop.................................|ale-desktop-options|
|
||||||
desktop-file-validate.................|ale-desktop-desktop-file-validate|
|
desktop-file-validate.................|ale-desktop-desktop-file-validate|
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ formatting.
|
|||||||
* [dafny](https://rise4fun.com/Dafny) :floppy_disk:
|
* [dafny](https://rise4fun.com/Dafny) :floppy_disk:
|
||||||
* Dart
|
* Dart
|
||||||
* [analysis_server](https://github.com/dart-lang/sdk/tree/master/pkg/analysis_server)
|
* [analysis_server](https://github.com/dart-lang/sdk/tree/master/pkg/analysis_server)
|
||||||
|
* [dart-analyze](https://github.com/dart-lang/sdk/tree/master/pkg/analyzer_cli) :floppy_disk:
|
||||||
* [dart-format](https://github.com/dart-lang/sdk/tree/master/utils/dartfmt)
|
* [dart-format](https://github.com/dart-lang/sdk/tree/master/utils/dartfmt)
|
||||||
* [dartanalyzer](https://github.com/dart-lang/sdk/tree/master/pkg/analyzer_cli) :floppy_disk:
|
* [dartanalyzer](https://github.com/dart-lang/sdk/tree/master/pkg/analyzer_cli) :floppy_disk:
|
||||||
* [dartfmt](https://github.com/dart-lang/sdk/tree/master/utils/dartfmt)
|
* [dartfmt](https://github.com/dart-lang/sdk/tree/master/utils/dartfmt)
|
||||||
|
|||||||
28
test/handler/test_dart_analyze_handler.vader
Normal file
28
test/handler/test_dart_analyze_handler.vader
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
Before:
|
||||||
|
runtime ale_linters/dart/dart_analyze.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#dart_analyze#Handle(bufnr(''), [
|
||||||
|
\ 'Analyzing main.dart...',
|
||||||
|
\ ' error - main.dart:5:1 - Expected to find ''}'' - expected_token',
|
||||||
|
\ ' warning - main.dart:2:16 - A value of type ''String'' can''t be assigned to a variable of type ''int'' - invalid_assignment',
|
||||||
|
\ '1 error and 1 warning found.',
|
||||||
|
\ ])
|
||||||
Reference in New Issue
Block a user