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

Minimal styling #433

Open
krlmlr opened this Issue Oct 14, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@krlmlr
Member

krlmlr commented Oct 14, 2018

Ideally I'd like to pass a single transformer to style_xxx(). However:

library(styler)
string <- "x <- 'ü'"

style_guide <- list(
  token = list(
    frobnicate = identity
  )
)

style_text(text = string, transformers = style_guide)
#> Warning: Unknown or uninitialised column: 'lag_newlines'.
#> Warning: Unknown or uninitialised column: 'newlines'.
#> Warning: Unknown or uninitialised column: 'lag_newlines'.
#> Warning: Unknown or uninitialised column: 'newlines'.
#> Warning: Unknown or uninitialised column: 'lag_newlines'.

#> Warning: Unknown or uninitialised column: 'lag_newlines'.

#> Warning: Unknown or uninitialised column: 'lag_newlines'.
#> Warning: Unknown or uninitialised column: 'newlines'.
#> Warning: Unknown or uninitialised column: 'lag_newlines'.

#> Warning: Unknown or uninitialised column: 'lag_newlines'.
#> Warning: Unknown or uninitialised column: 'newlines'.
#> Warning: Unknown or uninitialised column: 'indent'.
#> Error in `$<-.data.frame`(`*tmp*`, "indent", value = integer(0)): replacement has 0 rows, data has 1

Created on 2018-10-14 by the reprex package (v0.2.1.9000)

This works if we add a "minimal style" as extra information, derived from the initialize step of tidyverse_style() .

library(styler)
string <- "x <- 'ü'"

style_guide <- list(
  token = list(
    frobnicate = identity
  )
)

minimal_style <- list(
  initialize = tidyverse_style()$initialize,
  use_raw_indention = FALSE,
  reindention = list(comments_only = FALSE)
)

# Why is this necessary?
style_guide <- modifyList(style_guide, minimal_style)

style_text(text = string, transformers = style_guide)
#> x <- 'ü'

Created on 2018-10-14 by the reprex package (v0.2.1)

Seems like we could get rid of this requirement by using isTRUE() for testing logicals, and by moving the initialize step out of tidyverse_style(), perhaps hard-code it in styler . What do you think?

@lorenzwalthert

This comment has been minimized.

Collaborator

lorenzwalthert commented Oct 14, 2018

I am not sure why you need modifyList:

library(styler)
string <- "x <- 'ü'"

style_guide <- list(
  token = list(
    frobnicate = identity
  )
)

minimal_style <- list(
  initialize = tidyverse_style()$initialize,
  use_raw_indention = FALSE,
  reindention = list(comments_only = FALSE)
)

style_text(text = string, transformers = minimal_style)
#> x <- 'ü'

Created on 2018-10-14 by the reprex package (v0.2.0.9000)

@lorenzwalthert

This comment has been minimized.

Collaborator

lorenzwalthert commented Oct 14, 2018

For the rest I agree, this could be helpful. Interested in making a PR?

@krlmlr

This comment has been minimized.

Member

krlmlr commented Oct 14, 2018

I want to apply style_guide, especially the frobnicate transformer.

I might do a PR when I next work on styler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment