Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #1278] Fix a false positivie for Rails/SkipsModelValidations #1279

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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