Skip to content

Commit c7040a7

Browse files
authored
Merge pull request #14196 from viralpraxis/consistent-metric-dep-cops-method-names-highlight
Consistently highlight `Metric` cops method name in offense messages
2 parents 727c3c8 + dceaafd commit c7040a7

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

lib/rubocop/cop/metrics/abc_size.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module Metrics
3939
class AbcSize < Base
4040
include MethodComplexity
4141

42-
MSG = 'Assignment Branch Condition size for %<method>s is too high. ' \
42+
MSG = 'Assignment Branch Condition size for `%<method>s` is too high. ' \
4343
'[%<abc_vector>s %<complexity>.4g/%<max>.4g]'
4444

4545
private

spec/rubocop/cop/metrics/abc_size_spec.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def method_name
2121
it 'registers an offense for an if modifier' do
2222
expect_offense(<<~RUBY)
2323
def method_name
24-
^^^^^^^^^^^^^^^ Assignment Branch Condition size for method_name is too high. [<0, 2, 1> 2.24/0]
24+
^^^^^^^^^^^^^^^ Assignment Branch Condition size for `method_name` is too high. [<0, 2, 1> 2.24/0]
2525
call_foo if some_condition # 0 + 2*2 + 1*1
2626
end
2727
RUBY
@@ -30,7 +30,7 @@ def method_name
3030
it 'registers an offense for an assignment of a local variable' do
3131
offenses = expect_offense(<<~RUBY)
3232
def method_name
33-
^^^^^^^^^^^^^^^ Assignment Branch Condition size for method_name is too high. [<1, 0, 0> 1/0]
33+
^^^^^^^^^^^^^^^ Assignment Branch Condition size for `method_name` is too high. [<1, 0, 0> 1/0]
3434
x = 1
3535
end
3636
RUBY
@@ -41,7 +41,7 @@ def method_name
4141
it 'registers an offense for an assignment of an element' do
4242
expect_offense(<<~RUBY)
4343
def method_name
44-
^^^^^^^^^^^^^^^ Assignment Branch Condition size for method_name is too high. [<1, 2, 0> 2.24/0]
44+
^^^^^^^^^^^^^^^ Assignment Branch Condition size for `method_name` is too high. [<1, 2, 0> 2.24/0]
4545
x[0] = 1
4646
end
4747
RUBY
@@ -50,7 +50,7 @@ def method_name
5050
it 'registers an offense for complex content including A, B, and C scores' do
5151
expect_offense(<<~RUBY)
5252
def method_name
53-
^^^^^^^^^^^^^^^ Assignment Branch Condition size for method_name is too high. [<3, 4, 5> 7.07/0]
53+
^^^^^^^^^^^^^^^ Assignment Branch Condition size for `method_name` is too high. [<3, 4, 5> 7.07/0]
5454
my_options = Hash.new if 1 == 1 || 2 == 2 # 1, 1, 4
5555
my_options.each do |key, value| # 2, 1, 1
5656
p key # 0, 1, 0
@@ -63,7 +63,7 @@ def method_name
6363
it 'registers an offense for a `define_method`' do
6464
expect_offense(<<~RUBY)
6565
define_method :method_name do
66-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Assignment Branch Condition size for method_name is too high. [<1, 0, 0> 1/0]
66+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Assignment Branch Condition size for `method_name` is too high. [<1, 0, 0> 1/0]
6767
x = 1
6868
end
6969
RUBY
@@ -73,7 +73,7 @@ def method_name
7373
it 'registers an offense for a `define_method` with numblock' do
7474
expect_offense(<<~RUBY)
7575
define_method :method_name do
76-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Assignment Branch Condition size for method_name is too high. [<1, 0, 0> 1/0]
76+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Assignment Branch Condition size for `method_name` is too high. [<1, 0, 0> 1/0]
7777
x = _1
7878
end
7979
RUBY
@@ -84,7 +84,7 @@ def method_name
8484
it 'registers an offense for a `define_method` with itblock' do
8585
expect_offense(<<~RUBY)
8686
define_method :method_name do
87-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Assignment Branch Condition size for method_name is too high. [<1, 0, 0> 1/0]
87+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Assignment Branch Condition size for `method_name` is too high. [<1, 0, 0> 1/0]
8888
x = it
8989
end
9090
RUBY
@@ -94,7 +94,7 @@ def method_name
9494
it 'treats safe navigation method calls like regular method calls + a condition' do
9595
expect_offense(<<~RUBY)
9696
def method_name
97-
^^^^^^^^^^^^^^^ Assignment Branch Condition size for method_name is too high. [<0, 2, 1> 2.24/0]
97+
^^^^^^^^^^^^^^^ Assignment Branch Condition size for `method_name` is too high. [<0, 2, 1> 2.24/0]
9898
object&.do_something
9999
end
100100
RUBY
@@ -104,7 +104,7 @@ def method_name
104104
it 'registers an offense for an assignment of a local variable' do
105105
offenses = expect_offense(<<~RUBY)
106106
def method_name
107-
^^^^^^^^^^^^^^^ Assignment Branch Condition size for method_name is too high. [<1, 0, 0> 1/0]
107+
^^^^^^^^^^^^^^^ Assignment Branch Condition size for `method_name` is too high. [<1, 0, 0> 1/0]
108108
x = 1
109109
end
110110
RUBY
@@ -177,7 +177,7 @@ def self.foo
177177
it 'does not count repeated attributes' do
178178
expect_offense(<<~RUBY)
179179
def foo
180-
^^^^^^^ Assignment Branch Condition size for foo is too high. [<0, 1, 0> 1/0]
180+
^^^^^^^ Assignment Branch Condition size for `foo` is too high. [<0, 1, 0> 1/0]
181181
bar
182182
self.bar
183183
bar
@@ -192,7 +192,7 @@ def foo
192192
it 'counts repeated attributes' do
193193
expect_offense(<<~RUBY)
194194
def foo
195-
^^^^^^^ Assignment Branch Condition size for foo is too high. [<0, 3, 0> 3/0]
195+
^^^^^^^ Assignment Branch Condition size for `foo` is too high. [<0, 3, 0> 3/0]
196196
bar
197197
self.bar
198198
bar
@@ -243,7 +243,7 @@ def method_name
243243

244244
expect_offense(<<~RUBY)
245245
def method_name
246-
^^^^^^^^^^^^^^^ Assignment Branch Condition size for method_name is too high. [#{presentation}]
246+
^^^^^^^^^^^^^^^ Assignment Branch Condition size for `method_name` is too high. [#{presentation}]
247247
#{code.join("\n ")}
248248
end
249249
RUBY

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