Skip to content

Commit

Permalink
Merge pull request #183 from github/jdennes/fix-render-literal-cop-me…
Browse files Browse the repository at this point in the history
…ssage

`RuboCop::Cop::GitHub::RailsControllerRenderLiteral`: Make error message helpful for `locals` offence
  • Loading branch information
jdennes authored Jul 18, 2024
2 parents dfe8f2b + cec95e7 commit c858bf9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/rubocop/cop/github/rails_controller_render_literal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module GitHub
class RailsControllerRenderLiteral < Base
include RenderLiteralHelpers

MSG = "render must be used with a string literal or an instance of a Class"
MSG = "render must be used with a string literal or an instance of a Class, and use literals for locals keys"

def_node_matcher :ignore_key?, <<-PATTERN
(pair (sym {
Expand Down
40 changes: 30 additions & 10 deletions test/test_rails_controller_render_literal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ def index
RUBY

assert_equal 1, offenses.count
assert_equal "#{cop.name}: render must be used with a string literal or an instance of a Class", offenses[0].message
assert_equal \
"#{cop.name}: render must be used with a string literal or an instance of a Class, and use literals for locals keys",
offenses[0].message
end

def test_render_implicit_with_layout_offense
Expand All @@ -287,7 +289,9 @@ def index
RUBY

assert_equal 1, offenses.count
assert_equal "#{cop.name}: render must be used with a string literal or an instance of a Class", offenses[0].message
assert_equal \
"#{cop.name}: render must be used with a string literal or an instance of a Class, and use literals for locals keys",
offenses[0].message
end

def test_render_implicit_with_status_offense
Expand All @@ -300,7 +304,9 @@ def index
RUBY

assert_equal 1, offenses.count
assert_equal "#{cop.name}: render must be used with a string literal or an instance of a Class", offenses[0].message
assert_equal \
"#{cop.name}: render must be used with a string literal or an instance of a Class, and use literals for locals keys",
offenses[0].message
end

def test_render_variable_offense
Expand All @@ -313,7 +319,9 @@ def index
RUBY

assert_equal 1, offenses.count
assert_equal "#{cop.name}: render must be used with a string literal or an instance of a Class", offenses[0].message
assert_equal \
"#{cop.name}: render must be used with a string literal or an instance of a Class, and use literals for locals keys",
offenses[0].message
end

def test_render_to_string_variable_offense
Expand All @@ -326,7 +334,9 @@ def index
RUBY

assert_equal 1, offenses.count
assert_equal "#{cop.name}: render must be used with a string literal or an instance of a Class", offenses[0].message
assert_equal \
"#{cop.name}: render must be used with a string literal or an instance of a Class, and use literals for locals keys",
offenses[0].message
end

def test_render_action_variable_offense
Expand All @@ -339,7 +349,9 @@ def index
RUBY

assert_equal 1, offenses.count
assert_equal "#{cop.name}: render must be used with a string literal or an instance of a Class", offenses[0].message
assert_equal \
"#{cop.name}: render must be used with a string literal or an instance of a Class, and use literals for locals keys",
offenses[0].message
end

def test_render_template_variable_offense
Expand All @@ -352,7 +364,9 @@ def index
RUBY

assert_equal 1, offenses.count
assert_equal "#{cop.name}: render must be used with a string literal or an instance of a Class", offenses[0].message
assert_equal \
"#{cop.name}: render must be used with a string literal or an instance of a Class, and use literals for locals keys",
offenses[0].message
end

def test_render_partial_variable_offense
Expand All @@ -365,7 +379,9 @@ def index
RUBY

assert_equal 1, offenses.count
assert_equal "#{cop.name}: render must be used with a string literal or an instance of a Class", offenses[0].message
assert_equal \
"#{cop.name}: render must be used with a string literal or an instance of a Class, and use literals for locals keys",
offenses[0].message
end

def test_render_template_with_layout_variable_offense
Expand All @@ -378,7 +394,9 @@ def index
RUBY

assert_equal 1, offenses.count
assert_equal "#{cop.name}: render must be used with a string literal or an instance of a Class", offenses[0].message
assert_equal \
"#{cop.name}: render must be used with a string literal or an instance of a Class, and use literals for locals keys",
offenses[0].message
end

def test_render_template_variable_with_layout_offense
Expand All @@ -391,7 +409,9 @@ def index
RUBY

assert_equal 1, offenses.count
assert_equal "#{cop.name}: render must be used with a string literal or an instance of a Class", offenses[0].message
assert_equal \
"#{cop.name}: render must be used with a string literal or an instance of a Class, and use literals for locals keys",
offenses[0].message
end

def test_render_shorthand_static_locals_no_offsense
Expand Down

0 comments on commit c858bf9

Please sign in to comment.