Skip to content

Commit

Permalink
Merge pull request #1279 from tldn0718/fix-skip-model-validation-safe…
Browse files Browse the repository at this point in the history
…-navigator

[Fix #1278] Fix a false positivie for Rails/SkipsModelValidations
  • Loading branch information
koic authored May 17, 2024
2 parents 582af1e + 40d9dc3 commit 171e6de
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 171e6de

Please sign in to comment.