option.get should not warn if scoped under isDefined
See original GitHub issuethere’s one use case where option.get
is safe and reasonable:
def foo(bar: Option[String]) = {
if (bar.isDefined) {
val example = bar.get
// do something with example
}
// we no longer care whether it was defined or not
}
The current implementation of this rule forces you use .getOrElse(somethingImpossible)
in this context. That seems undesirable to me; things like if (false)
and empty else { }
are anti-patterns, so using getOrElse when you know the orElse is impossible should be one, too.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
java - Problems with local variable scope. How to solve it?
When you try to access this variable inside mouseDown() method you are trying to access a local variable from within an anonymous inner...
Read more >Variable scope, closure - The Modern JavaScript Tutorial
If a variable is not found anywhere, that's an error in strict mode (without use strict , an assignment to a non-existing variable...
Read more >Warning Options (Using the GNU Compiler Collection (GCC))
When an unrecognized warning option is requested (e.g., -Wunknown-warning ), GCC emits a diagnostic stating that the option is not recognized.
Read more >JSHint Options Reference
Warning This option has been deprecated and will be removed in the next major release of JSHint. JSHint is limiting its scope to...
Read more >7.2. Warnings and sanity-checking
In Monoid instances declarations warn if any of the following conditions does not hold: If mappend is defined it must be canonical (i.e....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If you want to side effect only when an option is defined, use .foreach
On Wed, 3 Jun 2020 at 00:45, FFdhorkin notifications@github.com wrote:
Having said that, I believe the warning is a proper one.