Class: RuboCop::Cop::Rails::IgnoredSkipActionFilterOption
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Rails::IgnoredSkipActionFilterOption
- Extended by:
- AutoCorrector
- Includes:
- RangeHelp
- Defined in:
- lib/rubocop/cop/rails/ignored_skip_action_filter_option.rb
Overview
Checks that ‘if` and `only` (or `except`) are not used together as options of `skip_*` action filter.
The ‘if` option will be ignored when `if` and `only` are used together. Similarly, the `except` option will be ignored when `if` and `except` are used together.
Constant Summary collapse
- MSG =
<<~MSG.chomp.freeze `%<ignore>s` option will be ignored when `%<prefer>s` and `%<ignore>s` are used together. MSG
- RESTRICT_ON_SEND =
%i[skip_after_action skip_around_action skip_before_action skip_action_callback].freeze
- FILTERS =
RESTRICT_ON_SEND.map { |method_name| ":#{method_name}" }
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rubocop/cop/rails/ignored_skip_action_filter_option.rb', line 59 def on_send(node) = (node) return unless return unless .hash_type? = () if if_and_only?() add_offense([:if], message: format(MSG, prefer: :only, ignore: :if)) do |corrector| remove_node_with_left_space_and_comma(corrector, [:if]) end elsif if_and_except?() add_offense([:except], message: format(MSG, prefer: :if, ignore: :except)) do |corrector| remove_node_with_left_space_and_comma(corrector, [:except]) end end end |