Class: RuboCop::Cop::Elegant::NoNilReturn
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Elegant::NoNilReturn
- Defined in:
- lib/rubocop/cop/elegant/no_nil_return.rb
Overview
Forbids returning the literal nil explicitly. The cop flags two
patterns: a return nil statement anywhere inside the body, and a
body whose tail expression is the literal nil (whether it stands
alone or appears as the last statement of a multi-statement body).
Both patterns are checked inside method definitions and inside
blocks, lambdas, and procs. Bodies that omit return, use a bare
return keyword, or merely happen to evaluate to nil through
control flow are not flagged.
Constant Summary collapse
- MSG =
'Method must not return nil explicitly'
Instance Method Summary collapse
Instance Method Details
#on_block(node) ⇒ Object
29 30 31 |
# File 'lib/rubocop/cop/elegant/no_nil_return.rb', line 29 def on_block(node) check(node) end |
#on_def(node) ⇒ Object
21 22 23 |
# File 'lib/rubocop/cop/elegant/no_nil_return.rb', line 21 def on_def(node) check(node) end |
#on_defs(node) ⇒ Object
25 26 27 |
# File 'lib/rubocop/cop/elegant/no_nil_return.rb', line 25 def on_defs(node) check(node) end |
#on_numblock(node) ⇒ Object
33 34 35 |
# File 'lib/rubocop/cop/elegant/no_nil_return.rb', line 33 def on_numblock(node) check(node) end |