Skip to content

Commit 171e6de

Browse files
authored
Merge pull request #1279 from tldn0718/fix-skip-model-validation-safe-navigator
[Fix #1278] Fix a false positivie for Rails/SkipsModelValidations
2 parents 582af1e + 40d9dc3 commit 171e6de

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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][])

Diff for: lib/rubocop/cop/rails/skips_model_validations.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class SkipsModelValidations < Base
6363
PATTERN
6464

6565
def_node_matcher :good_insert?, <<~PATTERN
66-
(send _ {:insert :insert!} _ {
66+
(call _ {:insert :insert!} _ {
6767
!(hash ...)
6868
(hash <(pair (sym !{:returning :unique_by}) _) ...>)
6969
} ...)

Diff for: spec/rubocop/cop/rails/skips_model_validations_spec.rb

+2
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,14 @@
5757
it "does not register an offense for #{method} that looks like String#insert" do
5858
expect_no_offenses(<<~RUBY)
5959
string.#{method}(0, 'b')
60+
string&.#{method}(0, 'b')
6061
RUBY
6162
end
6263

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

0 commit comments

Comments
 (0)