-
Notifications
You must be signed in to change notification settings - Fork 73
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
storing styler config in a config file / DESCRIPTION / other #319
Comments
Maybe also non-hidden |
Are there any plans to tackle this again in the future? The ideal case would be that RStudio also picks up this settings file. |
After some more thoughts on this, I felt like the whole idea of argument value resolution using defaults and config files should be handled by another package since it seems a rather generic problem. Hence, I created the package fallback. I also created a styler branch where we could test this: https://github.com/lorenzwalthert/styler/tree/config. Inspired by reprex, the syntax is: # I changed the defaults in the styler source code for the arguments
tidyverse_style <- function(strict = fallback(TRUE), ...) {
# ...
}
# the user can, as before:
style_text("1+1", style = tidyverse_style)
#> [details on resolution omitted] Which basically means
The user, of course, can override all defaults. Here is the trace with the most verbose output. style_text("1+1", style = tidyverse_style, strict = FALSE)
declaring argument scope
#> ● trying ./config.yaml: ✔ success (tokens)
#> declaring argument strict
#> ● resorting to literal input value: ✔ success (FALSE)
#> declaring argument indent_by
#> ● trying ./config.yaml: ✔ success (2)
#> declaring argument start_comments_with_one_space
#> ● trying ./config.yaml: ✖ failed (key does not exist in source file)
#> ● trying ~/config.yaml: ✖ failed (source file does not exist)
#> ● resorting to terminal fallback value: ✔success (FALSE)
#> declaring argument reindention
#> ● trying ./config.yaml: ✔ success (NULL, 0, TRUE)
#> declaring argument math_token_spacing
#> ● trying ./config.yaml: ✔ success (c("'+'", "'-'", "'*'", "'/'"), '^') This is early alpha, all feedback welcomed, breaking changes too. @krlmlr If you can help me conceptually for the API / naming conventions / argument order ect, dropping a few comments in an issue in lorenzwalthert/fallback I would really appreciate it. |
Also, consider how other formatters have solved this problem, e.g. https://ljvmiranda921.github.io/notebook/2018/06/21/precommits-using-black-and-flake8/ |
This is also relevant for the save on styling functionality provided via an environment variable ( |
Until we make progress here (if at all), you can also use RStudio snippets to store your preferred styler command, e.g. with snippet style
styler::style_file(${1:file}, strict = TRUE, scope = "spaces", indent_by = 4) You can type |
Note that you can also run R code within a snippet. The placeholder inside the snippet could default to the file that is currently opened in your editor. Then it almost behaves like a keybinding without the need to specify the file again 🙂 |
Hello. Thanks for all the great work you do. |
I think I’d prefer to solve this outside {styler}, eg with {fallback} as referenced above. I am happy to transfer the repo to someone else if they want to continue work on it, because I don’t have time. |
Maybe {renv} would want to expose their mechanism so we don't have to re-invent the wheel? Upvotes welcome 😀 rstudio/renv#1865 |
Repo may include a file
fallbacks.yaml
that contains a configuration for styling, like this:When
styler::style_pkg()
is run, such a config file is looked for in the root directory and if one is found, the options specified there should be given precedence over what is specified in the function call. Or something like that. WIP @ https://github.com/lorenzwalthert/styler/tree/configThe text was updated successfully, but these errors were encountered: