Skip to content

Commit

Permalink
[Fix rubocop#1278] Fix a false positivie for Rails/SkipsModelValidations
Browse files Browse the repository at this point in the history
  • Loading branch information
siwoo-park-ringle authored and tldn0718 committed May 16, 2024
1 parent 582af1e commit eaedb72
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_safe_navigator_for_skips_model_validation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1278](https://github.com/rubocop/rubocop-rails/issues/1278): Fix a false positive for `Rails/SkipsModelValidations` when using `insert` or `insert!` with a safe navigator. ([@tldn0718][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/skips_model_validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class SkipsModelValidations < Base
PATTERN

def_node_matcher :good_insert?, <<~PATTERN
(send _ {:insert :insert!} _ {
(call _ {:insert :insert!} _ {
!(hash ...)
(hash <(pair (sym !{:returning :unique_by}) _) ...>)
} ...)
Expand Down
2 changes: 2 additions & 0 deletions spec/rubocop/cop/rails/skips_model_validations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@
it "does not register an offense for #{method} that looks like String#insert" do
expect_no_offenses(<<~RUBY)
string.#{method}(0, 'b')
string&.#{method}(0, 'b')
RUBY
end

it "does not register an offense for #{method} that looks like Array#insert" do
expect_no_offenses(<<~RUBY)
array.#{method}(1, :a, :b)
array&.#{method}(1, :a, :b)
RUBY
end

Expand Down

0 comments on commit eaedb72

Please sign in to comment.