diff options
author | Thibault Vatter <thibault.vatter@gmail.com> | 2019-04-23 14:44:26 -0400 |
---|---|---|
committer | w0rp <w0rp@users.noreply.github.com> | 2019-04-23 19:44:26 +0100 |
commit | ce0b14979ea7429f07b6ca496333f72d93a8d013 (patch) | |
tree | 337a94162284dac87f87e155a27e5837ec3435ea | |
parent | 893ac34cca903df14dabee7bdee7a018675c16d4 (diff) | |
download | ale-ce0b14979ea7429f07b6ca496333f72d93a8d013.zip |
Add a fixer for r based on the styler package (#2401)
* Add styler as a new fixer for R files
* Add to the list of supported tools
* Add documentation
-rw-r--r-- | autoload/ale/fix/registry.vim | 5 | ||||
-rw-r--r-- | autoload/ale/fixers/styler.vim | 16 | ||||
-rw-r--r-- | doc/ale-r.txt | 16 | ||||
-rw-r--r-- | doc/ale-supported-languages-and-tools.txt | 1 | ||||
-rw-r--r-- | doc/ale.txt | 1 | ||||
-rw-r--r-- | supported-tools.md | 1 | ||||
-rw-r--r-- | test/fixers/test_styler_fixer_callback.vader | 21 |
7 files changed, 61 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 2b43e40a..45da359a 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -285,6 +285,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['kt'], \ 'description': 'Fix Kotlin files with ktlint.', \ }, +\ 'styler': { +\ 'function': 'ale#fixers#styler#Fix', +\ 'suggested_filetypes': ['r'], +\ 'description': 'Fix R files with styler.', +\ }, \ 'latexindent': { \ 'function': 'ale#fixers#latexindent#Fix', \ 'suggested_filetypes': ['tex'], diff --git a/autoload/ale/fixers/styler.vim b/autoload/ale/fixers/styler.vim new file mode 100644 index 00000000..7ff3275c --- /dev/null +++ b/autoload/ale/fixers/styler.vim @@ -0,0 +1,16 @@ +" Author: tvatter <thibault.vatter@gmail.com> +" Description: Fixing R files with styler. + +call ale#Set('r_styler_executable', 'Rscript') +call ale#Set('r_styler_options', 'tidyverse_style') + +function! ale#fixers#styler#Fix(buffer) abort + return { + \ 'command': 'Rscript --vanilla -e ' + \ . '"suppressPackageStartupMessages(library(styler));' + \ . 'style_file(commandArgs(TRUE), style = ' + \ . ale#Var(a:buffer, 'r_styler_options') . ')"' + \ . ' %t', + \ 'read_temporary_file': 1, + \} +endfunction diff --git a/doc/ale-r.txt b/doc/ale-r.txt index f85f48fd..b5ccebe5 100644 --- a/doc/ale-r.txt +++ b/doc/ale-r.txt @@ -25,5 +25,21 @@ g:ale_r_lintr_lint_package *g:ale_r_lintr_lint_package* of `lintr::lint`. This prevents erroneous namespace warnings when linting package files. + +=============================================================================== +styler *ale-r-styler* + +g:ale_r_styler_options *g:ale_r_styler_options* + *b:ale_r_styler_options* + Type: |String| + Default: `'styler::tidyverse_style'` + + This option can be configured to change the options for styler. + + The value of this option will be used as the `style` argument for the + `styler::style_file` options. Consult the styler documentation + for more information. + + =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index b682dc31..acec5926 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -357,6 +357,7 @@ Notes: * `qmllint` * R * `lintr` + * `styler` * Racket * `raco` * ReasonML diff --git a/doc/ale.txt b/doc/ale.txt index 3b194cb0..6e48de27 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -2149,6 +2149,7 @@ documented in additional help files. qmlfmt................................|ale-qml-qmlfmt| r.......................................|ale-r-options| lintr.................................|ale-r-lintr| + styler................................|ale-r-styler| reasonml................................|ale-reasonml-options| merlin................................|ale-reasonml-merlin| ols...................................|ale-reasonml-ols| diff --git a/supported-tools.md b/supported-tools.md index 59f8b082..7768d699 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -366,6 +366,7 @@ formatting. * [qmllint](https://github.com/qt/qtdeclarative/tree/5.11/tools/qmllint) * R * [lintr](https://github.com/jimhester/lintr) + * [styler](https://github.com/r-lib/styler) * Racket * [raco](https://docs.racket-lang.org/raco/) * ReasonML diff --git a/test/fixers/test_styler_fixer_callback.vader b/test/fixers/test_styler_fixer_callback.vader new file mode 100644 index 00000000..85e45c1d --- /dev/null +++ b/test/fixers/test_styler_fixer_callback.vader @@ -0,0 +1,21 @@ +Before: + call ale#test#SetDirectory('/testplugin/test/fixers') + +After: + Restore + + call ale#test#RestoreDirectory() + +Execute(The styler callback should include custom styler options): + let g:ale_r_styler_options = "a_custom_option" + + AssertEqual + \ { + \ 'command': 'Rscript --vanilla -e ' + \ . '"suppressPackageStartupMessages(library(styler));' + \ . 'style_file(commandArgs(TRUE), style = ' + \ . 'a_custom_option)"' + \ . ' %t', + \ 'read_temporary_file': 1, + \ }, + \ ale#fixers#styler#Fix(bufnr('')) |