Skip to content

handle nested terminal if/else in return_linter() - #2362

Merged
MichaelChirico merged 16 commits into
mainfrom
return-recurse
Dec 4, 2023
Merged

MichaelChirico merged 16 commits into
mainfrom
return-recurse

Conversation

@MichaelChirico

@MichaelChirico MichaelChirico commented Nov 28, 2023 •

Copy link
Copy Markdown
Collaborator

Closes #2354, Closes #2356

NEWS is missing, but I'll put it into the expanded item for #2321 (depending on which is merged first)

@MichaelChirico MichaelChirico changed the title handle nested terminal if/else handle nested terminal if/else in return_linter() Nov 28, 2023
@codecov-commenter

codecov-commenter commented Nov 28, 2023 •

Copy link
Copy Markdown

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (2dcb091) 99.11% compared to head (eaa36bc) 99.09%.

❗ Current head eaa36bc differs from pull request most recent head 0d57bc7. Consider uploading reports for the commit 0d57bc7 to get more accurate results

Files Patch % Lines
R/return_linter.R 97.43% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2362      +/-   ##
==========================================
- Coverage   99.11%   99.09%   -0.02%     
==========================================
  Files         125      125              
  Lines        5650     5658       +8     
==========================================
+ Hits         5600     5607       +7     
- Misses         50       51       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MichaelChirico

Copy link
Copy Markdown
Collaborator Author

I was also a bit worried about performance -- would overhead to recursing in R push us to pursue this as pure XPath?

I am satisfied with the R-recursion approach -- timing is not meaningfully different (faster, if anything) & should be much more readable. I linted all base R packages as a stress test:

setwd("src/library")
f = list.files()
f = f[file.exists(file.path(f, "DESCRIPTION"))]
lint_all = \(pkgs, linters) for (pkg in pkgs) lint_package(pkg, linters = linters)

# 'old' = current main, 'new' = current this PR

system.time(lint_all(f, old_explicit))
#    user  system elapsed 
#  72.638   1.162  74.112 
system.time(lint_all(f, old_implicit))
#    user  system elapsed 
#  66.546   0.819  67.682 
system.time(lint_all(f, new_explicit))
#    user  system elapsed 
#  72.178   1.058  73.604 
system.time(lint_all(f, new_implicit))
#    user  system elapsed 
#  62.563   0.871  63.674 

Comment thread R/return_linter.R Resolved
Comment thread R/return_linter.R Resolved
Comment thread R/return_linter.R Resolved
Comment thread R/return_linter.R Resolved
Comment thread tests/testthat/test-return_linter.R Resolved
@MichaelChirico
MichaelChirico merged commit c6dab82 into main Dec 4, 2023
@MichaelChirico
MichaelChirico deleted the return-recurse branch December 4, 2023 06:38
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.

Handling control statements of any depth in return_linter return_linter() for implicit returns has a false positive on nested early returns

3 participants