Skip to content

Unreachable loops#2141

Merged
MichaelChirico merged 27 commits intor-lib:mainfrom
MEO265:unreachable_loops
Oct 9, 2023
Merged

Unreachable loops#2141
MichaelChirico merged 27 commits intor-lib:mainfrom
MEO265:unreachable_loops

Conversation

@MEO265
Copy link
Copy Markdown
Contributor

@MEO265 MEO265 commented Sep 11, 2023

Closes #2105

It would also be possible to put the two cases stop/return and next/break together. Then there would be no separate message and more than the sensible situations would be tested, e.g. next in functions, but it would be faster.

I would be grateful for a hint as to why it is only necessary to filter out the end of "nolint" blocks but not the beginning

@MEO265
Copy link
Copy Markdown
Contributor Author

MEO265 commented Sep 11, 2023

I realized I forgot for loops, after that it becomes a normal PR

@MichaelChirico
Copy link
Copy Markdown
Collaborator

I would be grateful for a hint as to why it is only necessary to filter out the end of "nolint" blocks but not the beginning

See the original #1347. The idea is that we don't want to lint as "unreachable comment" some code that only exists to terminate a # nolint region.

In principle a # nolint start region could begin there, too, but in practice I've never seen this. Plain # nolint are also ignored since they should only come after actual expressions -- the expression itself will get the unreachable_codee_linter() hit, so no need to double that up by linting the comment as well.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Sep 12, 2023

Codecov Report

Merging #2141 (e30e1a7) into main (6e4dbec) will increase coverage by 0.00%.
The diff coverage is 100.00%.

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

@@           Coverage Diff           @@
##             main    #2141   +/-   ##
=======================================
  Coverage   99.65%   99.65%           
=======================================
  Files         114      114           
  Lines        5176     5198   +22     
=======================================
+ Hits         5158     5180   +22     
  Misses         18       18           
Files Coverage Δ
R/unreachable_code_linter.R 100.00% <100.00%> (ø)

@MEO265 MEO265 marked this pull request as ready for review September 12, 2023 15:28
Comment thread R/unreachable_code_linter.R
Comment thread R/unreachable_code_linter.R Outdated
linter <- unreachable_code_linter()
msg <- rex::rex("Code and comments coming after a return() or stop()")

lines <- trim_some("
Copy link
Copy Markdown
Collaborator

@MichaelChirico MichaelChirico Sep 12, 2023

Choose a reason for hiding this comment

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

long tests like this are good for robustness, but best to start with very succinct tests of only one aspect of the lint logic.

it means more lines of code which can be tedious, but is much preferable for test readability & ease of maintenance

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 may also help to either annotate the test with a comment on what all is being tested (it looks like "various types of if/else cases"), or to split into different test_that() and record that in the test's name

Comment thread tests/testthat/test-unreachable_code_linter.R
@MichaelChirico
Copy link
Copy Markdown
Collaborator

Hi @MEO265, we're closing in on sealing up a release (lintr 3.1.1). If you'd like this PR included, please take a chance to wrap up. If you'd like it included and won't have time to work on it in the next few weeks, let us know and we can try taking over from here. Thanks!

@MEO265
Copy link
Copy Markdown
Contributor Author

MEO265 commented Sep 15, 2023

Hi @MEO265, we're closing in on sealing up a release (lintr 3.1.1). If you'd like this PR included, please take a chance to wrap up. If you'd like it included and won't have time to work on it in the next few weeks, let us know and we can try taking over from here. Thanks!

Unfortunately, I have absolutely no idea whether I will find time this week or next. I would fix everything the following Monday at the latest.
But feel free to change things yourself, especially if it doesn't fit with the release otherwise.

@MichaelChirico MichaelChirico added this to the 3.1.1 milestone Sep 19, 2023
@MichaelChirico
Copy link
Copy Markdown
Collaborator

Hi @MEO265, friendly ping :)

@MichaelChirico
Copy link
Copy Markdown
Collaborator

Fixed the more trivial requests. I'll let the long tests slide for now, @MEO265 a follow-up improving the tests would be appreciated if you find the time! Thanks for the PR.

@MichaelChirico MichaelChirico merged commit d275cbc into r-lib:main Oct 9, 2023
@MEO265 MEO265 deleted the unreachable_loops branch November 8, 2023 19:22
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.

Enhancement of unreachable_code_linter to Detect Unreachable Code in Loops

3 participants