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 #12] Allow passing boolean literals to touch #232

Merged
merged 1 commit into from
Apr 12, 2020
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#12](https://github.com/rubocop-hq/rubocop-rails/issues/12): Fix a false positive for `Rails/SkipsModelValidations` when passing a boolean literal to `touch`. ([@eugeneius][])

## 2.5.2 (2020-04-09)

### Bug fixes
Expand Down
5 changes: 4 additions & 1 deletion lib/rubocop/cop/rails/skips_model_validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ class SkipsModelValidations < Cop
update_counters].freeze

def_node_matcher :good_touch?, <<~PATTERN
(send (const nil? :FileUtils) :touch ...)
{
(send (const nil? :FileUtils) :touch ...)
(send _ :touch {true false})
}
PATTERN

def on_send(node)
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/rails/skips_model_validations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
it 'accepts FileUtils.touch' do
expect_no_offenses("FileUtils.touch('file')")
end

it 'accepts touch with literal true' do
expect_no_offenses('belongs_to(:user).touch(true)')
end

it 'accepts touch with literal false' do
expect_no_offenses('belongs_to(:user).touch(false)')
end
end

context 'with methods that require at least an argument' do
Expand Down