Skip to content

Update style_dir() - #292

Merged
krlmlr merged 12 commits into
r-lib:masterfrom
jonmcalder:style-dir
Dec 5, 2017
Merged

krlmlr merged 12 commits into
r-lib:masterfrom
jonmcalder:style-dir

Conversation

@jonmcalder

Copy link
Copy Markdown
Contributor

Extension to style_dir() to address the first part of #291

@codecov-io

codecov-io commented Nov 25, 2017 •

Copy link
Copy Markdown

Codecov Report

Merging #292 into master will decrease coverage by 0.18%.
The diff coverage is 88.46%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #292      +/-   ##
==========================================
- Coverage   92.01%   91.83%   -0.19%     
==========================================
  Files          29       30       +1     
  Lines        1302     1322      +20     
==========================================
+ Hits         1198     1214      +16     
- Misses        104      108       +4
Impacted Files Coverage Δ
R/serialized_tests.R 72.44% <ø> (-0.89%) ⬇️
R/style_guides.R 98.13% <ø> (-0.15%) ⬇️
R/expr-is.R 94.73% <ø> (ø) ⬆️
R/ui.R 100% <100%> (ø) ⬆️
R/utils.R 91.3% <100%> (+2.84%) ⬆️
R/set-assert-args.R 79.31% <79.31%> (ø)

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 6f49c4b...db5e7ab. Read the comment docs.

Comment thread R/ui.R
...,
style = tidyverse_style,
transformers = style(...),
filetype = "R",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can we change that to c("r") also?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry did the other merge from my phone and I thought you'd changed it already. Happy to change this too.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@krlmlr do you prefer to stick with "R" everywhere instead of "r"? Its kind of a philosophical debate I guess...

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.

Can we use "R" everywhere? It doesn't seem to affect the code, but the default file extension is .R and not .r, and we should be consistent here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree that the default here and elsewhere should be uppercase. I think @lorenzwalthert wanted to emphasize that this argument can be/is a vector so wanted to use c("R") instead. I think the case inconsistency was incidental/accidental.

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.

I thought c("R") was an artifact... I feel it's enough if we just mention that the argument also accepts vectors in the documentation.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ok, fine.

Comment thread R/ui.R Outdated
...,
style = tidyverse_style,
transformers = style(...),
filetype = c("r"),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't see how this argument does affect the function call, i.e. it is not really used further downstream if I see that correctly.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

So was your intend to wait with merging anyways until #293 is resolved?

@jonmcalder jonmcalder Nov 26, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah this was just because the other functions (style_dir & prettify_any) were already inheriting params from here (for documentation) and I figured we'd be adding this to style_pkg later anyway.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ok, lets wait with merging then.

@jonmcalder

Copy link
Copy Markdown
Contributor Author

Ok, this should be ready for further review now.

@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, a few minor nits.

Comment thread R/ui.R Outdated
#' conveniently constructed via the `style` argument and `...`. See
#' 'Examples'.
#' @param filetype Vector of file extensions indicating which filetypes should
#' be styled. Case is ignored, and the `.` is optional, e.g. c(".R", ".Rmd")

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.

Does the code need backticks?

Comment thread R/set-assert-args.R Outdated
stop(
"Token(s) ", paste0(invalid_tokens, collapse = ", "), " are invalid. ",
"You can lookup all valid tokens and their text ",
"with styler:::looup_tokens(). Make sure you supply the values of ",

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.

looup -> lookup

Comment thread R/ui.R Outdated
path = "vignettes", pattern = "\\.rmd$", ignore.case = TRUE,
recursive = TRUE, full.names = TRUE
)
readme <- dir(pattern = "readme\\.rmd", ignore.case = TRUE)

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.

Needs ^ and $ ?

Comment thread R/ui.R
r_files <- test_files <- data_raw_files <- vignette_files <- readme <- NULL

if ("\\.r" %in% filetype) {
r_files <- dir(

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.

The paths argument to dir() seems to be vectorized, not sure about older versions of R.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks - I had overlooked this. Based on this source code from 2000, I think it's safe to assume that the paths argument has been vectorized since pre R 2.0 days, so I'll go ahead and combine these.

Comment thread R/ui.R Outdated
r_files <- dir(
path = "R", pattern = "[.][rR]$", recursive = TRUE, full.names = TRUE
)
prettify_local <- function(transformers, filetype, exclude_files) {

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.

I'm not sure the function name still matches the intent.

---

```{r setup, include=FALSE}
1+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.

Do the tests actually test that styling is applied?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we just check whether the file was named in the message about changed files. Should we test for the actual change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

They don't check whether styling is applied, just which files are being named in the changed files message. @lorenzwalthert suggested these tests so I kinda assumed we had our bases covered with actual styling tests elsewhere.

@jonmcalder

Copy link
Copy Markdown
Contributor Author

Thanks very much for the review @krlmlr! Unfortunately I won't be able to get back to this until this evening (i.e. outside office hours). I hope I'm not holding up your CRAN release?

@krlmlr

krlmlr commented Nov 29, 2017

Copy link
Copy Markdown
Member

No, that's totally fine.

@krlmlr

krlmlr commented Nov 29, 2017

Copy link
Copy Markdown
Member

Thanks for working on this!

Fix typo in assert_tokens
Add code backticks in documentation
Rename prettify_local
Use vector of paths
Strict readme regex
@lorenzwalthert
lorenzwalthert requested review from krlmlr and removed request for krlmlr December 2, 2017 11:22
@jonmcalder

Copy link
Copy Markdown
Contributor Author

Hi @krlmlr! Sorry I should have requested a follow up review from you on Wednesday eve after pushing some changes.

I think I have addressed all your comments. The drop in testing coverage is very marginal - but in any case highlights the question of whether or not you feel there is sufficient testing? (please refer to the comments above)

@lorenzwalthert
lorenzwalthert requested a review from krlmlr December 4, 2017 21:22

@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.

Looks good, thanks!

@krlmlr
krlmlr merged commit c8ce5de into r-lib:master Dec 5, 2017
@krlmlr

krlmlr commented Dec 5, 2017

Copy link
Copy Markdown
Member

Thanks again!

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).
@jonmcalder

Copy link
Copy Markdown
Contributor Author

Happy to help out - another good learning opportunity for me. Thanks @krlmlr!

@jonmcalder
jonmcalder deleted the style-dir branch December 5, 2017 18:28
jonmcalder referenced this pull request Dec 5, 2017
- Add test for styling `.Rmd` files.
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.

4 participants