Skip to content

Commit

Permalink
Merge pull request #114 from github/mgriffin/autocorrect-view-shorthand
Browse files Browse the repository at this point in the history
Allow RailsViewRenderShorthand errors to be autocorrected
  • Loading branch information
jhawthorn authored Oct 19, 2022
2 parents e9af3d9 + af77d72 commit aad3693
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/rubocop/cop/github/rails_view_render_shorthand.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module RuboCop
module Cop
module GitHub
class RailsViewRenderShorthand < Base
extend AutoCorrector

MSG = "Prefer `render` partial shorthand"

def_node_matcher :render_with_options?, <<-PATTERN
Expand All @@ -26,9 +28,13 @@ def on_send(node)
locals_key = option_pairs.map { |pair| locals_key?(pair) }.compact.first

if option_pairs.length == 1 && partial_key
add_offense(node, message: "Use `render #{partial_key.source}` instead")
add_offense(node, message: "Use `render #{partial_key.source}` instead") do |corrector|
corrector.replace(node.source_range, "render #{partial_key.source}")
end
elsif option_pairs.length == 2 && partial_key && locals_key
add_offense(node, message: "Use `render #{partial_key.source}, #{locals_key.source}` instead")
add_offense(node, message: "Use `render #{partial_key.source}, #{locals_key.source}` instead") do |corrector|
corrector.replace(node.source_range, "render #{partial_key.source}, #{locals_key.source}")
end
end
end
end
Expand Down

0 comments on commit aad3693

Please sign in to comment.