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
This commit is contained in:
parent
893ac34cca
commit
ce0b14979e
@ -285,6 +285,11 @@ let s:default_registry = {
|
|||||||
\ 'suggested_filetypes': ['kt'],
|
\ 'suggested_filetypes': ['kt'],
|
||||||
\ 'description': 'Fix Kotlin files with ktlint.',
|
\ 'description': 'Fix Kotlin files with ktlint.',
|
||||||
\ },
|
\ },
|
||||||
|
\ 'styler': {
|
||||||
|
\ 'function': 'ale#fixers#styler#Fix',
|
||||||
|
\ 'suggested_filetypes': ['r'],
|
||||||
|
\ 'description': 'Fix R files with styler.',
|
||||||
|
\ },
|
||||||
\ 'latexindent': {
|
\ 'latexindent': {
|
||||||
\ 'function': 'ale#fixers#latexindent#Fix',
|
\ 'function': 'ale#fixers#latexindent#Fix',
|
||||||
\ 'suggested_filetypes': ['tex'],
|
\ 'suggested_filetypes': ['tex'],
|
||||||
|
16
autoload/ale/fixers/styler.vim
Normal file
16
autoload/ale/fixers/styler.vim
Normal file
@ -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
|
@ -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
|
of `lintr::lint`. This prevents erroneous namespace warnings when linting
|
||||||
package files.
|
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:
|
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
||||||
|
@ -357,6 +357,7 @@ Notes:
|
|||||||
* `qmllint`
|
* `qmllint`
|
||||||
* R
|
* R
|
||||||
* `lintr`
|
* `lintr`
|
||||||
|
* `styler`
|
||||||
* Racket
|
* Racket
|
||||||
* `raco`
|
* `raco`
|
||||||
* ReasonML
|
* ReasonML
|
||||||
|
@ -2149,6 +2149,7 @@ documented in additional help files.
|
|||||||
qmlfmt................................|ale-qml-qmlfmt|
|
qmlfmt................................|ale-qml-qmlfmt|
|
||||||
r.......................................|ale-r-options|
|
r.......................................|ale-r-options|
|
||||||
lintr.................................|ale-r-lintr|
|
lintr.................................|ale-r-lintr|
|
||||||
|
styler................................|ale-r-styler|
|
||||||
reasonml................................|ale-reasonml-options|
|
reasonml................................|ale-reasonml-options|
|
||||||
merlin................................|ale-reasonml-merlin|
|
merlin................................|ale-reasonml-merlin|
|
||||||
ols...................................|ale-reasonml-ols|
|
ols...................................|ale-reasonml-ols|
|
||||||
|
@ -366,6 +366,7 @@ formatting.
|
|||||||
* [qmllint](https://github.com/qt/qtdeclarative/tree/5.11/tools/qmllint)
|
* [qmllint](https://github.com/qt/qtdeclarative/tree/5.11/tools/qmllint)
|
||||||
* R
|
* R
|
||||||
* [lintr](https://github.com/jimhester/lintr)
|
* [lintr](https://github.com/jimhester/lintr)
|
||||||
|
* [styler](https://github.com/r-lib/styler)
|
||||||
* Racket
|
* Racket
|
||||||
* [raco](https://docs.racket-lang.org/raco/)
|
* [raco](https://docs.racket-lang.org/raco/)
|
||||||
* ReasonML
|
* ReasonML
|
||||||
|
21
test/fixers/test_styler_fixer_callback.vader
Normal file
21
test/fixers/test_styler_fixer_callback.vader
Normal file
@ -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(''))
|
Loading…
x
Reference in New Issue
Block a user