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

Commas trailing #2104

Merged
merged 11 commits into from
Sep 5, 2023
Merged

Commas trailing #2104

merged 11 commits into from
Sep 5, 2023

Conversation

MEO265
Copy link
Contributor

@MEO265 MEO265 commented Sep 4, 2023

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
Copy link

codecov-commenter commented Sep 4, 2023

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%> (ø)

Copy link
Collaborator

@AshesITR AshesITR left a comment

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.

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
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?

NEWS.md Outdated
@@ -40,6 +40,7 @@
* `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
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.

#' @evalRd rd_tags("commas_linter")
#' @seealso
#' - [linters] for a complete list of linters available in lintr.
#' - <https://style.tidyverse.org/syntax.html#commas>
#' @export
commas_linter <- function() {
commas_linter <- function(allow_trailing_comma = FALSE) {
Copy link
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
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
Copy link
Contributor Author

MEO265 commented Sep 4, 2023

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
Copy link
Collaborator

AshesITR commented Sep 5, 2023

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
Copy link
Contributor Author

MEO265 commented Sep 5, 2023

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
21 checks passed
@AshesITR
Copy link
Collaborator

AshesITR commented Sep 5, 2023

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