Added dartfmt fixer (#1683)

* Added dartfmt to Fixers
* Added dartfmt specific documentation
This commit is contained in:
Govind KP 2018-07-01 18:25:41 +05:30 committed by w0rp
parent 06f61eeeb8
commit 9d98e6db0c
7 changed files with 99 additions and 2 deletions

View File

@ -111,7 +111,7 @@ formatting.
| Cython (pyrex filetype) | [cython](http://cython.org/) |
| D | [dmd](https://dlang.org/dmd-linux.html) |
| Dafny | [dafny](https://rise4fun.com/Dafny) !! |
| Dart | [dartanalyzer](https://github.com/dart-lang/sdk/tree/master/pkg/analyzer_cli) !!, [language_server](https://github.com/natebosch/dart_language_server) |
| Dart | [dartanalyzer](https://github.com/dart-lang/sdk/tree/master/pkg/analyzer_cli) !!, [language_server](https://github.com/natebosch/dart_language_server), [dartfmt](https://github.com/dart-lang/sdk/tree/master/utils/dartfmt) |
| Dockerfile | [hadolint](https://github.com/hadolint/hadolint) |
| Elixir | [credo](https://github.com/rrrene/credo), [dialyxir](https://github.com/jeremyjh/dialyxir), [dogma](https://github.com/lpil/dogma), [mix](https://hexdocs.pm/mix/Mix.html) !!|
| Elm | [elm-format](https://github.com/avh4/elm-format), [elm-make](https://github.com/elm-lang/elm-make) |

View File

@ -210,6 +210,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['qml'],
\ 'description': 'Fix QML files with qmlfmt.',
\ },
\ 'dartfmt': {
\ 'function': 'ale#fixers#dartfmt#Fix',
\ 'suggested_filetypes': ['dart'],
\ 'description': 'Fix Dart files with dartfmt.',
\ },
\}
" Reset the function registry to the default entries.

View File

@ -0,0 +1,18 @@
" Author: reisub0 <reisub0@gmail.com>
" Description: Integration of dartfmt with ALE.
call ale#Set('dart_dartfmt_executable', 'dartfmt')
call ale#Set('dart_dartfmt_options', '')
function! ale#fixers#dartfmt#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'dart_dartfmt_executable')
let l:options = ale#Var(a:buffer, 'dart_dartfmt_options')
return {
\ 'command': ale#Escape(l:executable)
\ . ' -w'
\ . (empty(l:options) ? '' : ' ' . l:options)
\ . ' %t',
\ 'read_temporary_file': 1,
\}
endfunction

View File

@ -35,4 +35,37 @@ g:ale_dart_dartanalyzer_executable *g:ale_dart_dartanalyzer_executable*
===============================================================================
dartfmt *ale-dart-dartfmt*
Installation
-------------------------------------------------------------------------------
Installing Dart should probably ensure that `dartfmt` is in your `$PATH`.
In case it is not, try to set the executable option to its absolute path. : >
" Set the executable path for dartfmt to the absolute path to it.
let g:ale_dart_dartfmt_executable = '/usr/lib/dart/bin/dartfmt'
>
Options
-------------------------------------------------------------------------------
g:ale_dart_dartfmt_executable *g:ale_dart_dartfmt_executable*
*b:ale_dart_dartfmt_executable*
Type: |String|
Default: `''`
This variable can be set to specify an absolute path to the
dartfmt executable (or to specify an alternate executable).
g:ale_dart_dartfmt_options *g:ale_dart_dartfmt_options*
*b:ale_dart_dartfmt_options*
Type: |String|
Default: `''`
This variable can be set to pass additional options to the dartfmt fixer.
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@ -59,6 +59,7 @@ CONTENTS *ale-contents*
nvcc................................|ale-cuda-nvcc|
dart..................................|ale-dart-options|
dartanalyzer........................|ale-dart-dartanalyzer|
dartfmt.............................|ale-dart-dartfmt|
dockerfile............................|ale-dockerfile-options|
hadolint............................|ale-dockerfile-hadolint|
elixir................................|ale-elixir-options|
@ -342,7 +343,7 @@ Notes:
* Cython (pyrex filetype): `cython`
* D: `dmd`
* Dafny: `dafny`!!
* Dart: `dartanalyzer`!!, `language_server`
* Dart: `dartanalyzer`!!, `language_server`, dartfmt!!
* Dockerfile: `hadolint`
* Elixir: `credo`, `dialyxir`, `dogma`, `mix`!!
* Elm: `elm-format, elm-make`

View File

View File

@ -0,0 +1,40 @@
Before:
Save g:ale_dart_dartfmt_executable
Save g:ale_dart_dartfmt_options
" Use an invalid global executable, so we don't match it.
let g:ale_dart_dartfmt_executable = 'xxxinvalid'
let g:ale_dart_dartfmt_options = ''
call ale#test#SetDirectory('/testplugin/test/fixers')
After:
Restore
call ale#test#RestoreDirectory()
Execute(The dartfmt callback should return the correct default values):
call ale#test#SetFilename('../dart_files/testfile.dart')
AssertEqual
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape('xxxinvalid')
\ . ' -w'
\ . ' %t',
\ },
\ ale#fixers#dartfmt#Fix(bufnr(''))
Execute(The dartfmt callback should include custom dartfmt options):
let g:ale_dart_dartfmt_options = "-l 80"
call ale#test#SetFilename('../dart_files/testfile.dart')
AssertEqual
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape('xxxinvalid')
\ . ' -w'
\ . ' ' . g:ale_dart_dartfmt_options
\ . ' %t',
\ },
\ ale#fixers#dartfmt#Fix(bufnr(''))