Skip to content

RuboCop::Cop::GitHub::RailsControllerRenderLiteral: Make error message helpful for locals offence #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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