Skip to content

Commit af77d72

Browse files
committed
Add autocorrect to RailsViewRenderShorthand
The text is already provided in the error message, this reuses it to allow the problem to be auto corrected
1 parent 95d99fd commit af77d72

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/rubocop/cop/github/rails_view_render_shorthand.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ module RuboCop
66
module Cop
77
module GitHub
88
class RailsViewRenderShorthand < Base
9+
extend AutoCorrector
10+
911
MSG = "Prefer `render` partial shorthand"
1012

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

2830
if option_pairs.length == 1 && partial_key
29-
add_offense(node, message: "Use `render #{partial_key.source}` instead")
31+
add_offense(node, message: "Use `render #{partial_key.source}` instead") do |corrector|
32+
corrector.replace(node.source_range, "render #{partial_key.source}")
33+
end
3034
elsif option_pairs.length == 2 && partial_key && locals_key
31-
add_offense(node, message: "Use `render #{partial_key.source}, #{locals_key.source}` instead")
35+
add_offense(node, message: "Use `render #{partial_key.source}, #{locals_key.source}` instead") do |corrector|
36+
corrector.replace(node.source_range, "render #{partial_key.source}, #{locals_key.source}")
37+
end
3238
end
3339
end
3440
end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy