-
Notifications
You must be signed in to change notification settings - Fork 188
feat(new linter): added a new linter #830
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
Conversation
* Added a new linter that checks for a space between the right parenthesis and the function body in function definitions that span one line and don't use braces Closes #809
Hi @kpagacz, thanks for taking the time to write a PR!
I had similar issues on my Windows machine.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far, just a few things need changing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, thank you.
I think this is ready to merge. Would you add a line to NEWS.md and update the roxygen documentation to reflect the extensions?
Done. Thanks for taking the time to review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@jimhester @MichaelChirico @renkun-ken @russHyde do we want this in the default linters? |
yes agree. IINM styler::style_file also fixes this |
expect_lint("if (TRUE)test", msg, linter) | ||
expect_lint("while (TRUE)test", msg, linter) | ||
expect_lint("for (i in seq_along(1))test", msg, linter) | ||
expect_lint("\\()test", msg, linter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lambda syntax should only be checked in R >= 4.0.
Curiously, the test also fails for R 4.0.
Can you investigate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for failure on 4.0 itself, wasn't there a bug with utils::getParseData() on that release?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going to look into running that particular test only for R>=4.0 and will check if the parsed tree is somehow wrong for version 4.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the failure on the R version 4.0.5 (I assume that's the one running there). The new lambda syntax was introduced in the version 4.1.0 as per this NEWS document: https://cran.r-project.org/doc/manuals/r-release/NEWS.pdf (3rd point on the 3rd page). For obvious reasons parsing () lambdas returns an error on the version 4.0.x
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad re the version number. The condition needs to be on R version >= 4.1.0, not 4.0.0
Do you need help with adding the linter to the defaults?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added the necessary skip condition.
I don't think unbraced blocks of the form
are allowed in the tidyverse style (see section "inline statements" in https://style.tidyverse.org/syntax.html#control-flow); though they are allowed if on a single line. |
Russ, AIUI that example is just to show another usage that wouldn't be flagged by this linter, rather than showing code that is "OK". That is, the code maybe should be flagged, but it would be by a different linter, unless you are proposing to extend the scope of this linter. |
I think this could be added to the default linters. |
OK cool. |
Hi all,
I have added a new linter that checks for a space after the closing parenthesis of the list of formal function arguments in cases where no braces are used and the function definition spans only a single line.
Examples:
Closes #809