-
-
Notifications
You must be signed in to change notification settings - Fork 279
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
Tell SimpleCov to ignore unreachable code #2034
Conversation
I like the use of I agree it's a good sign to be deliberate that it's unreachable code. At this point, I think we should probably add a contributor guideline to the README so folks know how to handle unreachable code. Some ways of using node patterns and then further matching in Ruby methods and case handling for config both lend themselves to that outcome, so it will likely come up. |
Also FYI, I tried |
|
If I remember correctly, |
It raises an exception NoMatchingPatternError. This essentially handles
that part for us (instead of ArgumentError), but it's not considered
exhaustive. It also doesn't give us a convenient place to put a `# :nocov`
block.
Not considering the `case ... in` block to be exhaustive may be a failing
in Simplecov that we should look into, since pattern matching is new but
not that new.
…On Sun, Feb 9, 2025 at 7:19 AM Benjamin Quorning ***@***.***> wrote:
If I remember correctly, case/in blocks *must* have an else branch. Or is
it just that it raises an exception if none of the branches are matched?
—
Reply to this email directly, view it on GitHub
<#2034 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANFDS2Y5QPC6YCEHI6DYRL2O5WYHAVCNFSM6AAAAABWYZY3Z2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNBWGM2TGNBQGI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
d9a0658
to
2be7260
Compare
2be7260
to
ca144e2
Compare
In some cases we know that a case statement is covering all possible branches, e.g. `case [foo?, bar?]` has four branches (if the predicate methods return booleans, of course), and `case style` has a know number of branches, depending on `SupportedStyles` in config/default.yml. So, when to use `else ... raise ArgumentError`, and when to change the last `elsif` or `when` into an `else`? I don't know.
ca144e2
to
3870bd0
Compare
@@ -2,7 +2,7 @@ | |||
|
|||
SimpleCov.start do | |||
enable_coverage :branch | |||
minimum_coverage line: 100, branch: 98.44 | |||
minimum_coverage line: 100, branch: 100 |
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.
@corsonknowles Yay ✨
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.
🤩👏
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.
❤️ 🥇
@pirj 👍🏼❓ |
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.
Thank you! 🤩
In some cases we know that a case statement is covering all possible branches, e.g.
case [foo?, bar?]
has four branches (if the predicate methods return booleans, of course), andcase style
has a know number of branches, depending onSupportedStyles
in config/default.yml.So, when to use
else ... raise ArgumentError
, and when to change the lastelsif
orwhen
into anelse
? I don't know.To avoid conflicts with other PRs improving code coverage, the .simplecov file is not updated here.Before submitting the PR make sure the following are checked:
master
(if not - rebase it).CHANGELOG.md
if the new code introduces user-observable changes.bundle exec rake
) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).