Add support for `dart analyze` (#3825)

This commit is contained in:
ghsang 2021-07-25 13:48:12 +09:00 committed by GitHub
parent 8c591996a8
commit 73d32335fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 121 additions and 32 deletions

View 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,
\})

View File

@ -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.
===============================================================================
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*
@ -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.
===============================================================================
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*

View File

@ -124,6 +124,7 @@ Notes:
* `dafny`!!
* Dart
* `analysis_server`
* `dart-analyze`!!
* `dart-format`!!
* `dartanalyzer`!!
* `dartfmt`!!

View File

@ -2700,8 +2700,9 @@ documented in additional help files.
dafny.................................|ale-dafny-dafny|
dart....................................|ale-dart-options|
analysis_server.......................|ale-dart-analysis_server|
dartanalyzer..........................|ale-dart-dartanalyzer|
dart-analyze..........................|ale-dart-analyze|
dart-format...........................|ale-dart-format|
dartanalyzer..........................|ale-dart-dartanalyzer|
dartfmt...............................|ale-dart-dartfmt|
desktop.................................|ale-desktop-options|
desktop-file-validate.................|ale-desktop-desktop-file-validate|

View File

@ -133,6 +133,7 @@ formatting.
* [dafny](https://rise4fun.com/Dafny) :floppy_disk:
* Dart
* [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)
* [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)

View 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.',
\ ])