Skip to content

Commas trailing - #2104

Merged
AshesITR merged 11 commits into
r-lib:mainfrom
MEO265:commas_trailing
Sep 5, 2023
Merged

AshesITR merged 11 commits into
r-lib:mainfrom
MEO265:commas_trailing

Conversation

@MEO265

@MEO265 MEO265 commented Sep 4, 2023

Copy link
Copy Markdown
Contributor

This is the pull request for issue #2102

This is my first PR in your project, please don't hold back with comments

@codecov-commenter

codecov-commenter commented Sep 4, 2023 •

Copy link
Copy Markdown

Codecov Report

Merging #2104 (8671f49) into main (960d863) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 8671f49 differs from pull request most recent head b71d22e. Consider uploading reports for the commit b71d22e to get more accurate results

@@           Coverage Diff           @@
##             main    #2104   +/-   ##
=======================================
  Coverage   99.65%   99.65%           
=======================================
  Files         118      118           
  Lines        5206     5208    +2     
=======================================
+ Hits         5188     5190    +2     
  Misses         18       18           
Files Changed Coverage Δ
R/commas_linter.R 100.00% <100.00%> (ø)

@AshesITR AshesITR left a comment

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.

Thanks a lot for the PR. Solid work, just a few remarks.

Comment thread R/commas_linter.R Outdated
xpath_after <- "//OP-COMMA[@line1 = following-sibling::*[1]/@line1 and @col1 = following-sibling::*[1]/@col1 - 1]"
xpath_after <- paste0(
"//OP-COMMA[@line1 = following-sibling::*[1]/@line1 and @col1 = following-sibling::*[1]/@col1 - 1",
if (allow_trailing_comma) " and not(following-sibling::*[1]/self::OP-RIGHT-BRACKET)",

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.

Maybe also allow RBB (a[[1,]]) and OP-RIGHT-PAREN (a(1,)) if the argument is set?

Comment thread NEWS.md Outdated
* `keyword_quote_linter()` for finding unnecessary or discouraged quoting of symbols in assignment, function arguments, or extraction (part of #884, @MichaelChirico). Quoting is unnecessary when the target is a valid R name, e.g. `c("a" = 1)` can be `c(a = 1)`. The same goes to assignment (`"a" <- 1`) and extraction (`x$"a"`). Where quoting is necessary, the linter encourages doing so with backticks (e.g. `` x$`a b` `` instead of `x$"a b"`).
* `length_levels_linter()` for using the specific function `nlevels()` instead of checking `length(levels(x))` (part of #884, @MichaelChirico).
* `if_not_else_linter()` for encouraging `if` statements to be structured as `if (A) x else y` instead of `if (!A) y else x` (part of #884, @MichaelChirico).
* `commas_linter()` add parameter `allow_trailing_comma` to allow trailing commas while indexing.

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'd suggest to use the wording "gains an option", see the bullet regarding fixed_regex_linter().

And please reference the issue number and give yourself credit for it.

Comment thread R/commas_linter.R Outdated
#' - <https://style.tidyverse.org/syntax.html#commas>
#' @export
commas_linter <- function() {
commas_linter <- function(allow_trailing_comma = FALSE) {

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.

allow_trailing seems more concise to me since comma is already part of the linter name.

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.

it's also more consistent with missing_argument_linter()

@MEO265

MEO265 commented Sep 4, 2023 •

Copy link
Copy Markdown
Contributor Author

Line 76 of commas_linter.R is 121 characters and not 120 characters long, should that be changed or is there tolerance?
I don't think the whole thing became more readable due to a change


I found a minimally invasive solution, but I would also be interested in the question in principle

@AshesITR

AshesITR commented Sep 5, 2023

Copy link
Copy Markdown
Collaborator

There is no tolerance, 120 is an upper limit.
Regarding the long line here, it could be broken up by introducing a local variable.

if (allow_trailing) {
  xp_trailing_cond <- "and not(following-sibling::*[1][
    self::OP-RIGHT-PAREN or self::OP-RIGHT-BRACKET or self::RBB
  ]"
} else {
  xp_trailing_cond <- ""
}
xpath_after <- glue(
  "//OP-COMMA[@line1 = following-sibling::*[1]/@line1 and @col1 = following-sibling::*[1]/@col1 - 1 {xp_trailing_cond}]"
)

@MEO265

MEO265 commented Sep 5, 2023

Copy link
Copy Markdown
Contributor Author

There is no tolerance, 120 is an upper limit. Regarding the long line here, it could be broken up by introducing a local variable.

if (allow_trailing) {
  xp_trailing_cond <- "and not(following-sibling::*[1][
    self::OP-RIGHT-PAREN or self::OP-RIGHT-BRACKET or self::RBB
  ]"
} else {
  xp_trailing_cond <- ""
}
xpath_after <- glue(
  "//OP-COMMA[@line1 = following-sibling::*[1]/@line1 and @col1 = following-sibling::*[1]/@col1 - 1 {xp_trailing_cond}]"
)

@AshesITR I have already implemented another solution, should I still implement the one suggested?

@AshesITR
AshesITR merged commit 02732a2 into r-lib:main Sep 5, 2023
@AshesITR

AshesITR commented Sep 5, 2023

Copy link
Copy Markdown
Collaborator

It's fine, thanks!

@MEO265
MEO265 deleted the commas_trailing branch September 7, 2023 13:59
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