Skip to content

Commit

Permalink
Fix false positive in when a sequence has a symbol proc argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdeo committed Apr 10, 2018
1 parent 24c18ac commit b2c7328
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Master (Unreleased)

* Fix false positive in `RSpec/Pending` cop when pending is used as a method name. ([@Darhazer][])
* Fix `FactoryBot/DynamicAttributeDefinedStatically` false positive when using symbol proc argument for a sequence. ([@tdeo][])

## 1.25.0 (2018-04-07)

Expand Down Expand Up @@ -330,3 +331,4 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
[@jojos003]: https://github.com/jojos003
[@abrom]: https://github.com/abrom
[@patrickomatic]: https://github.com/patrickomatic
[@tdeo]: https://github.com/tdeo
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ class DynamicAttributeDefinedStatically < Cop
(block (send nil? {:factory :trait} ...) _ { (begin $...) $(send ...) } )
PATTERN

def_node_matcher :callback_with_symbol_proc?, <<-PATTERN
(send nil? {:before :after} sym (block_pass sym))
def_node_matcher :callback_or_sequence_with_symbol_proc?, <<-PATTERN
(send nil? {:before :after :sequence} sym (block_pass sym))
PATTERN

def on_block(node)
factory_attributes(node).to_a.flatten.each do |attribute|
next if callback_with_symbol_proc?(attribute) ||
next if callback_or_sequence_with_symbol_proc?(attribute) ||
static?(attribute)
add_offense(attribute, location: :expression)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@
RUBY
end

it 'accepts valid sequence definition' do
expect_no_offenses(<<-RUBY)
#{factory_bot}.define do
factory :post do
sequence :negative_numbers, &:-@
end
end
RUBY
end

bad = <<-RUBY
#{factory_bot}.define do
factory :post do
Expand Down

0 comments on commit b2c7328

Please sign in to comment.