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

Combination of stylerignore directives and local() leads to problematic styling #1072

Closed
IndrajeetPatil opened this issue Nov 26, 2022 · 2 comments · Fixed by #1082
Closed

Comments

@IndrajeetPatil
Copy link
Collaborator

IndrajeetPatil commented Nov 26, 2022

Problem

The following code

# styler: off
skip_if_not_installed("tibble")
local({
  x <- 1
})
# styler: on

is styled to-

# styler: off
local({
  x <- 1
})
skip_if_not_installed("tibble")
local
# styler: on

Note how skip() and local change their positions.

How to reproduce

Run the example code in interactive mode.
If you are looking for a more realistic example, run styler:::style_active_file() on this file.

Note

It's interesting that I can reproduce the issue in the minimal example posted above in the interactive mode, but not in a reprex.

Screenshot 2022-11-26 at 08 54 23

IndrajeetPatil added a commit to easystats/datawizard that referenced this issue Dec 22, 2022
I know that this is not what we want, but the styler annotations are creating problematic formatting.

I have created issues to track this.

- r-lib/styler#1067
- r-lib/styler#1072

We can revisit this once they are resolved.
@lorenzwalthert
Copy link
Collaborator

lorenzwalthert commented Dec 24, 2022

Seems a caching interaction. Full reprex:

full <- c(
  '# styler: off',
  'skip_if_not_installed("tibble")',
  'local({',
    'x<-1',
  '})',
  '# styler: on'
)
without_ignore <- full[c(-1, -length(full))]
styler:::local_test_setup(cache = TRUE)
styler::style_text(without_ignore)
#> skip_if_not_installed("tibble")
#> local({
#>   x <- 1
#> })
styler::style_text(full)
#> # styler: off
#> local({
#> x<-1
#> })
#> skip_if_not_installed("tibble")
#> local
#> # styler: on

Created on 2022-12-24 with reprex v2.0.2

@lorenzwalthert
Copy link
Collaborator

lorenzwalthert commented Dec 25, 2022

Tough one o tell you… these interactions between caching and stylerignore are hard to get right, but I think I found a solution after hours of digging. Will push later and hopefully be able to explain Tue problem and the solution.

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

Successfully merging a pull request may close this issue.

2 participants