Skip to content

Roundtrip and CLI - #289

Merged
lorenzwalthert merged 14 commits into
r-lib:masterfrom
lorenzwalthert:roundtrip
Nov 27, 2017
Merged

lorenzwalthert merged 14 commits into
r-lib:masterfrom
lorenzwalthert:roundtrip

Conversation

@lorenzwalthert

@lorenzwalthert lorenzwalthert commented Nov 25, 2017 •

Copy link
Copy Markdown
Collaborator

Closes #288, implements #287 (comment).

- use cli package for nicer formatting.
- Print a summary at the end of styling
- Use cat(), not message() to avoid red font.
- return tibble with information on what was formatted instead of vector.
- don't show info for style_text()
@lorenzwalthert lorenzwalthert changed the title Roundtrip Roundtrip and CLI Nov 25, 2017
Comment thread R/communicate.R
#' @inheritParams can_verify_roundtrip
communicate_warning <- function(changed, transformers) {
if (any(changed, na.rm = TRUE) & !can_verify_roundtrip(transformers)) {
cat("Please review the changes carefully!")

@lorenzwalthert lorenzwalthert Nov 25, 2017 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Is it ok to use cat() or do you prefer warning()? I just felt red is not the right color.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can add color with crayon if necessary.

@codecov-io

codecov-io commented Nov 25, 2017 •

Copy link
Copy Markdown

Codecov Report

Merging #289 into master will increase coverage by 0.29%.
The diff coverage is 97.5%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #289      +/-   ##
==========================================
+ Coverage   90.62%   90.91%   +0.29%     
==========================================
  Files          28       29       +1     
  Lines        1280     1299      +19     
==========================================
+ Hits         1160     1181      +21     
+ Misses        120      118       -2
Impacted Files Coverage Δ
R/ui.R 100% <ø> (ø) ⬆️
R/style_guides.R 98.27% <0%> (ø) ⬆️
R/transform-files.R 100% <100%> (+2.19%) ⬆️
R/serialized_tests.R 73.33% <100%> (+1.33%) ⬆️
R/communicate.R 100% <100%> (ø)

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 fc85d2c...1da5a74. Read the comment docs.

@lorenzwalthert

lorenzwalthert commented Nov 25, 2017 •

Copy link
Copy Markdown
Collaborator Author

Any ideas why the appveyor build fails at the point where it compares the printed console output

Styling  1  files:
 test-start_line.R ✔ 
────────────────────────────────────────
Status	Count	Legend 
✔ 	1	File unchanged.
ℹ 	0	File changed.
✖ 	0	Styling threw an eror.

With a reference value? I guess it has to do with the encoding. But using class utf8 does not help.

@krlmlr krlmlr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks. I haven't seen the output yet, but we can merge anyway.

Comment thread R/transform-files.R Outdated
#' @param old_text The initial expression in its character representation.
#' @param new_text The styled expression in its character representation.
expressions_are_identical <- function(old_text, new_text) {
identical(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Indent?

Comment thread R/communicate.R
#' @inheritParams can_verify_roundtrip
communicate_warning <- function(changed, transformers) {
if (any(changed, na.rm = TRUE) & !can_verify_roundtrip(transformers)) {
cat("Please review the changes carefully!")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can add color with crayon if necessary.

Comment thread R/transform-files.R Outdated
max_char <- min(max(nchar(files), 0), 80)
if (length(files) > 0) {
message("Styling ", length(files), " files:")
if (length(files) < 1) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please check the comparison operator.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

uups, thanks.

Comment thread R/ui.R Outdated
changed <- map_lgl(path,
style_file_one, ..., style = style, transformers = transformers
)
invisible(tibble(file = path, changed = changed))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this return value used anywhere?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No, I just found style_file_one() is redundant anyways with the current implementation of transform_files(). Must have overlooked that at some point. I will make the changes in transform_files()

Comment thread R/communicate.R Outdated
#' been changed.
#' @inheritParams can_verify_roundtrip
communicate_warning <- function(changed, transformers) {
if (any(changed, na.rm = TRUE) & !can_verify_roundtrip(transformers)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

&& better communicates intent here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Right...

@krlmlr

krlmlr commented Nov 27, 2017

Copy link
Copy Markdown
Member

Would you like to change the default scope to something weaker than "token"?

@lorenzwalthert

Copy link
Copy Markdown
Collaborator Author

I am not sure. Would you? It took us quite a while to implement everything as it is now and if we lower the default scope, I think a lot of people will not take the time to set it manually to "tokens". Also, we have the warning and many tests, so I feel like that should be sufficient.

@krlmlr

krlmlr commented Nov 27, 2017

Copy link
Copy Markdown
Member

I value the effort that it took to patch the parse data. However, if we don't change tokens, we can automatically verify correctness. This gives us an extra safety net.

I'm fine either way, please decide.

@krlmlr

krlmlr commented Nov 27, 2017

Copy link
Copy Markdown
Member

AppVeyor: Checking Unicode symbols against known output on Windows is a pain. It's ok to just skip these tests on Windows.

@lorenzwalthert

Copy link
Copy Markdown
Collaborator Author

I am wondering about how good of an idea it is to set the default to "line_breaks" and change it later to "tokens" if we styled more tidyverse packages and gained certainty that everything works fine. On the one hand, that would add safety, but the downside is API stability. So I propose to keep it as is and make sure we can address potential bug reports quickly.

@lorenzwalthert
lorenzwalthert force-pushed the roundtrip branch 4 times, most recently from 1a4c038 to 472a661 Compare November 27, 2017 22:53
@lorenzwalthert
lorenzwalthert merged commit 4c9a194 into r-lib:master Nov 27, 2017
@lorenzwalthert
lorenzwalthert deleted the roundtrip branch November 27, 2017 23:30
krlmlr added a commit that referenced this pull request Dec 5, 2017
- Remove `regex_none()`, document `NULL` default.
- `style_dir()` and `style_pkg()` now also handle `.Rmd` files (#292, @jonmcalder).
- Add test for styling `.Rmd` files.
- Better error message for styling new files via the RStudio addin (#295).
- Spelling via devtools::spell_check() (#294).
- Roundtrip and CLI (#289).
@lorenzwalthert

Copy link
Copy Markdown
Collaborator Author

Reference: #368.

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.

3 participants