Class: RuboCop::Cop::Bugcrowd::CanWithClassConst
- Inherits:
-
Cop
- Object
- Cop
- RuboCop::Cop::Bugcrowd::CanWithClassConst
- Defined in:
- lib/rubocop/cop/bugcrowd/can_with_class_const.rb
Constant Summary collapse
- MSG =
"\u{1F6A8} Don't call can? with a class constant, as it will unexpectedly pass. Use an instance instead. (https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities-with-Blocks#only-for-object-attributes) \u{1F6A8}\n"
Instance Method Summary collapse
Instance Method Details
#autocorrect(node) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/rubocop/cop/bugcrowd/can_with_class_const.rb', line 19 def autocorrect(node) lambda do |corrector| internal_expression = node.children.last corrector.replace( internal_expression.loc.expression, "#{internal_expression.source}.new" ) end end |
#on_send(node) ⇒ Object
15 16 17 |
# File 'lib/rubocop/cop/bugcrowd/can_with_class_const.rb', line 15 def on_send(node) add_offense(node) if can_with_class_const?(node) end |