Skip to content

Allow for dry run#634

Merged
lorenzwalthert merged 10 commits intor-lib:masterfrom
lorenzwalthert:issue-633
May 7, 2020
Merged

Allow for dry run#634
lorenzwalthert merged 10 commits intor-lib:masterfrom
lorenzwalthert:issue-633

Conversation

@lorenzwalthert
Copy link
Collaborator

@lorenzwalthert lorenzwalthert commented Apr 17, 2020

Closes #633 and implements an API change.

New argument dry in style_file() and friends to control write back and failing in case of modification. The argument takes these values:

  • off (default): Current behavior. Write back to file as side effect. Return tibble with summary invisible (as now).
  • on: Never modify files, also return tibble summary as if things were written back.
  • fail: Same as on, but fail fast with error if modification would occur on write-back.

Any feedback on the design welcome, I am not so sure this is optimal. @krlmlr since this is an API change, I'd like to have your opinion on that if possible.

@codecov-io
Copy link

codecov-io commented Apr 17, 2020

Codecov Report

Merging #634 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #634   +/-   ##
=======================================
  Coverage   90.64%   90.65%           
=======================================
  Files          47       47           
  Lines        2171     2173    +2     
=======================================
+ Hits         1968     1970    +2     
  Misses        203      203           
Impacted Files Coverage Δ
R/ui-styling.R 100.00% <ø> (ø)
R/io.R 87.75% <100.00%> (+0.52%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3b94f31...06603fd. Read the comment docs.

@lorenzwalthert
Copy link
Collaborator Author

@select-id-from-users you can try this if you want. Will merge into master later.

@select-id-from-users
Copy link

@lorenzwalthert Works like a charm, thank you very much!

tux:/tmp/renv$ Rscript -e 'styler::style_file("test.R", dry="fail")'
Styling  1  files:
 test.R Error: File `test.R` would be modified by styler and `dry` = 'fail'.
Backtrace:
     █
  1. └─styler::style_file("test.R", dry = "fail")
  2.   └─styler:::transform_files(...)
  3.     └─purrr::map_lgl(...)
  4.       └─styler:::.f(.x[[i]], ...)
  5.         └─styler:::transform_code(path, fun = fun, ..., dry = dry)
  6.           └─styler:::transform_utf8(path, fun = fun, ..., dry = dry)
  7.             ├─map_lgl(path, transform_utf8_one, fun = fun, dry = dry) %>% set_names(path)
  8.             │ └─base::eval(lhs, parent, parent)
  9.             │   └─base::eval(lhs, parent, parent)
 10.             └─purrr::map_lgl(path, transform_utf8_one, fun = fun, dry = dry)
 11.               └─styler:::.f(.x[[i]], ...)
 12.                 └─rlang::with_handlers(...)
 13.                   └─bas
Execution halted
tux:/tmp/renv$ echo $?
1
tux:/tmp/renv$ Rscript -e 'styler::style_file("test.R", dry="off")'
Styling  1  files:
 test.R ℹ 
────────────────────────────────────────
Status	Count	Legend 
✔ 	0	File unchanged.
ℹ 	1	File changed.
✖ 	0	Styling threw an error.
────────────────────────────────────────
Please review the changes carefully!
tux:/tmp/renv$ Rscript -e 'styler::style_file("test.R", dry="fail")'
Styling  1  files:
 test.R ✔ 
────────────────────────────────────────
Status	Count	Legend 
✔ 	1	File unchanged.
ℹ 	0	File changed.
✖ 	0	Styling threw an error.
────────────────────────────────────────
tux:/tmp/renv$ echo $?
0

@lorenzwalthert
Copy link
Collaborator Author

Error: File test.R would be modified by styler and dry = 'fail'.

Maybe we can come up with a better error:

Error: File `test.R` would be modified by styler and argument `dry` is set to 'fail'.

Also, do you find on, off and dry self-explanatory?

@select-id-from-users
Copy link

I guess since the error is thrown only when dry="fail" you don't have to mention that dry is set to 'fail'? I have no strong opinion here, and would be happy either way.

I find the options self-explanatory yes. Maybe "on" could be "warn"? Although warnings can also result in non-zero exit code when you run devtools::check(error_on="note"). Also here I don't have strong opinion. Naming things is hard.

@lorenzwalthert lorenzwalthert merged commit 8f42440 into r-lib:master May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dry-run mode

3 participants