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

Remove pipe on end of commented code prior to checking parsability #2672

Merged
merged 9 commits into from
Oct 24, 2024

Conversation

jcken95
Copy link
Contributor

@jcken95 jcken95 commented Oct 20, 2024

Closes #2671

The PR removes pipes from the end of extracted_code when checking parsability of code. A test to check that a lint is detected on commented lines ending with a pipe (which are otherwise parsable) are indeed detected.

This solves a common false negative occurrence in, for example, data wrangling

mtcars |>
# dplyr::filter(cyl > 4) |>
   dplyr::summarise(m = mean(wt))

The above snippet detect no commented code lints, but changes in this PR would lead to a commented code linter being detected

@jcken95 jcken95 changed the title 2671 pipe on end of comment Remove pipe on end of commented code prior to checking parsability Oct 20, 2024
@MichaelChirico
Copy link
Collaborator

@AshesITR / @IndrajeetPatil WDYT?

@AshesITR
Copy link
Collaborator

AshesITR commented Oct 21, 2024

I have often seen commented pipe steps in code I reviewed. I think it's a useful addition unlikely to produce many false positives.

Maybe we could also change the linters behavior to check if the code parses when removing the comment character from a consecutive block of comments as well, i.e. make it "context-aware". That would necessitate making it file-level, though and might break some stuff, so that's definitively out-pf-scope here.

NEWS.md Outdated Show resolved Hide resolved
Co-authored-by: AshesITR <alexander.rosenstock@web.de>
Copy link
Collaborator

@MichaelChirico MichaelChirico left a comment

Choose a reason for hiding this comment

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

Thanks!

@AshesITR AshesITR merged commit 5bc4dbe into r-lib:main Oct 24, 2024
19 checks passed
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.

Any pipe (|> or %>%) on the end of a line leads to a false negative for commented_code_linter
3 participants