Class: RuboCop::Cop::Legion::ConstantSafety::InheritParam
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Legion::ConstantSafety::InheritParam
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/legion/constant_safety/inherit_param.rb
Overview
Detects const_defined? or const_get called with only one argument.
Without false as the second argument, Ruby searches the entire inheritance
chain including Object, which can cause false positives and namespace leaks.
Constant Summary collapse
- MSG =
'Pass `false` as inherit parameter: `%<method>s(%<arg>s, false)`. ' \ 'Default `true` leaks through `Object`.'
- RESTRICT_ON_SEND =
%i[const_defined? const_get].freeze
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rubocop/cop/legion/constant_safety/inherit_param.rb', line 27 def on_send(node) return unless node.arguments.size == 1 arg = node.first_argument = format(MSG, method: node.method_name, arg: arg.source) add_offense(node, message: ) do |corrector| corrector.insert_after(arg.source_range, ', false') end end |