Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a fixer for r based on the styler package #2401

Merged
merged 8 commits into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions autoload/ale/fix/registry.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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': {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I think you might be missing a } here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, thanks!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now tests pass, hooray 😄.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed :)

\ 'function': 'ale#fixers#latexindent#Fix',
\ 'suggested_filetypes': ['tex'],
Expand Down
16 changes: 16 additions & 0 deletions autoload/ale/fixers/styler.vim
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions doc/ale-r.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:
1 change: 1 addition & 0 deletions doc/ale-supported-languages-and-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ Notes:
* `qmllint`
* R
* `lintr`
* `styler`
* Racket
* `raco`
* ReasonML
Expand Down
1 change: 1 addition & 0 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
1 change: 1 addition & 0 deletions supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions test/fixers/test_styler_fixer_callback.vader
Original file line number Diff line number Diff line change
@@ -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(''))