Comments (5)
AFAIK this is not possible with RuboCop, as it's not evaluating any code. At most, you could detect if value
is a local variable, and if that local variable has been assigned the literal nil
, but I would advise against that, as it doesn't seem very useful. If you must know if the method is being called with nil
values, the only way to really know is to check at runtime. Another approach would be to use a type checker like Sorbet.
from rubocop.
RuboCop is fundamentally a static analysis tool for single files, and therefore, it cannot perform analysis across multiple files. As already mentioned, it is impossible to determine if any case, other than nil literals and local variables, is nil. So, it might be possible to ascertain the value of local variables by traversing for nodes where the value is assigned.
from rubocop.
This is one way I could do it but the problem here is that it fails on every type of value and not just nil
.
def_node_matcher :must_equal_nil?, <<~PATTERN
{
(send _ :must_equal (lvar _))
(send _ :must_equal (nil))
}
PATTERN
Any way to just make it work for nil
values?
from rubocop.
I've tried several solutions, but none have worked so far. It's possible that we're dealing with a static analyzer and cannot obtain the value beforehand. I'm hoping someone from the Rubocop family can provide additional guidance.
from rubocop.
Yes, I have used the sorbet in some other context, which bulk up the project and I can't convince everyone to opt in for that in this case!
Thanks for the input
from rubocop.
Related Issues (20)
- Style/HashExcept ignores negation
- `Lint/UselessMethodDefinition` should ignore required keyword arguments HOT 3
- false positive edge-case of Missing top-level documentation comment on class split among several files HOT 5
- Wrong auto-correct for Layout/DotPosition + Layout/MultilineMethodCallIndentation: mixes the . of a floating-point value with the . of a method HOT 2
- Fix Style/MethodCallWithArgsParentheses with constant
- Behavior difference of `rubocop` vs `rubocop .`
- Style/SymbolProc crashes on a single file HOT 5
- Wrong hash rewriting after applying rules HOT 1
- Layout/SpaceAroundOperator causes false positives
- Autocorrection for Lint/ImplicitStringConcatenation
- When a `.rubocop_todo.yml` exclude is not useful anymore, instead raise a (correctable) offense
- RuboCop auto-corrected code contains too many deep indentation
- Lint/UselessAssignment causes a false positive when using hash value omission and block HOT 1
- Feature request: Add "Lint/RaiseNotImplementedError" cop
- False negative for Lint/ImplicitStringConcatenation
- Feature request: Ability to correct global offenses
- Bug: Metrics/MethodLength AllowedMethods/AllowedPatterns not working HOT 3
- Cop idea: Style/BitPredicates HOT 1
- Lint/FloatComparison breaks when parsing Rational literal
- Warning: `support_autocorrect?` is deprecated. Use `cop.class.support_autocorrect?` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rubocop.