Skip to content

Commit 78f1ec9

Browse files
biinaribbatsov
authored andcommitted
Alter multiline memoization message for braces enforced style
1 parent e0f28e0 commit 78f1ec9

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/rubocop/cop/style/multiline_memoization.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class MultilineMemoization < Base
3434
include ConfigurableEnforcedStyle
3535
extend AutoCorrector
3636

37-
MSG = 'Wrap multiline memoization blocks in `begin` and `end`.'
37+
KEYWORD_MSG = 'Wrap multiline memoization blocks in `begin` and `end`.'
38+
BRACES_MSG = 'Wrap multiline memoization blocks in `(` and `)`.'
3839

3940
def on_or_asgn(node)
4041
_lhs, rhs = *node
@@ -51,6 +52,10 @@ def on_or_asgn(node)
5152
end
5253
end
5354

55+
def message(_node)
56+
style == :braces ? BRACES_MSG : KEYWORD_MSG
57+
end
58+
5459
private
5560

5661
def bad_rhs?(rhs)

spec/rubocop/cop/style/multiline_memoization_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
it 'registers an offense for begin...end block on first line' do
135135
expect_offense(<<~RUBY)
136136
foo ||= begin
137-
^^^^^^^^^^^^^ Wrap multiline memoization blocks in `begin` and `end`.
137+
^^^^^^^^^^^^^ Wrap multiline memoization blocks in `(` and `)`.
138138
bar
139139
baz
140140
end
@@ -150,7 +150,7 @@
150150
it 'registers an offense for begin...end block on following line' do
151151
expect_offense(<<~RUBY)
152152
foo ||=
153-
^^^^^^^ Wrap multiline memoization blocks in `begin` and `end`.
153+
^^^^^^^ Wrap multiline memoization blocks in `(` and `)`.
154154
begin
155155
bar
156156
baz

0 commit comments

Comments
 (0)