From 73d32335fe0b9d723e19f098d3c263b01e17d234 Mon Sep 17 00:00:00 2001 From: ghsang <66662835+ghsang@users.noreply.github.com> Date: Sun, 25 Jul 2021 13:48:12 +0900 Subject: [PATCH] Add support for `dart analyze` (#3825) --- ale_linters/dart/dart_analyze.vim | 28 ++++++ doc/ale-dart.txt | 92 +++++++++++++------- doc/ale-supported-languages-and-tools.txt | 1 + doc/ale.txt | 3 +- supported-tools.md | 1 + test/handler/test_dart_analyze_handler.vader | 28 ++++++ 6 files changed, 121 insertions(+), 32 deletions(-) create mode 100644 ale_linters/dart/dart_analyze.vim create mode 100644 test/handler/test_dart_analyze_handler.vader diff --git a/ale_linters/dart/dart_analyze.vim b/ale_linters/dart/dart_analyze.vim new file mode 100644 index 00000000..a00162d8 --- /dev/null +++ b/ale_linters/dart/dart_analyze.vim @@ -0,0 +1,28 @@ +" Author: ghsang +" 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, +\}) diff --git a/doc/ale-dart.txt b/doc/ale-dart.txt index 983a23d1..a046808b 100644 --- a/doc/ale-dart.txt +++ b/doc/ale-dart.txt @@ -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* diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index 27c50efa..f3d7767c 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -124,6 +124,7 @@ Notes: * `dafny`!! * Dart * `analysis_server` + * `dart-analyze`!! * `dart-format`!! * `dartanalyzer`!! * `dartfmt`!! diff --git a/doc/ale.txt b/doc/ale.txt index 2d80c322..5d6e215a 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -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| diff --git a/supported-tools.md b/supported-tools.md index 2a60b6d6..77c92112 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -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) diff --git a/test/handler/test_dart_analyze_handler.vader b/test/handler/test_dart_analyze_handler.vader new file mode 100644 index 00000000..b3f20fb8 --- /dev/null +++ b/test/handler/test_dart_analyze_handler.vader @@ -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.', + \ ])