File tree Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## Master (Unreleased)
4
4
5
+ - Fix a false positive in ` RSpec/IndexedLet ` with suffixes after index-like numbers. ([ @pirj ] )
6
+
5
7
## 2.20.0 (2023-04-18)
6
8
7
9
- Add new ` RSpec/IndexedLet ` cop. ([ @dmitrytsepelev ] )
Original file line number Diff line number Diff line change @@ -56,19 +56,24 @@ def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
56
56
57
57
private
58
58
59
- INDEX_REGEX = /_?\d +/ . freeze
59
+ SUFFIX_INDEX_REGEX = /_?\d +$/ . freeze
60
+ INDEX_REGEX = /\d +/ . freeze
60
61
61
62
def filter_indexed_lets ( candidates )
62
63
candidates
63
64
. filter { |node | indexed_let? ( node ) }
64
- . group_by { |node | let_name ( node ) . to_s . gsub ( INDEX_REGEX , '' ) }
65
+ . group_by { |node | let_name_stripped_index ( node ) }
65
66
. values
66
67
. filter { |lets | lets . length > cop_config [ 'Max' ] }
67
68
. flatten
68
69
end
69
70
70
71
def indexed_let? ( node )
71
- let? ( node ) && INDEX_REGEX . match? ( let_name ( node ) )
72
+ let? ( node ) && SUFFIX_INDEX_REGEX . match? ( let_name ( node ) )
73
+ end
74
+
75
+ def let_name_stripped_index ( node )
76
+ let_name ( node ) . to_s . gsub ( INDEX_REGEX , '' )
72
77
end
73
78
end
74
79
end
Original file line number Diff line number Diff line change 73
73
RUBY
74
74
end
75
75
76
+ it 'ignores names with an index-like and a suffix' do
77
+ expect_no_offenses ( <<~RUBY )
78
+ context SomeService do
79
+ let(:user_7_day_average) { 700 }
80
+ let(:user_30_day_average) { 3000 }
81
+ end
82
+ RUBY
83
+ end
84
+
76
85
it 'not flags which have different prefixes' do
77
86
expect_no_offenses ( <<~RUBY )
78
87
describe SomeService do
You can’t perform that action at this time.
0 commit comments