From 93ea87ad6e352b197f20e7ef31433d928bc6cff3 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Tue, 4 May 2021 23:39:54 +0900 Subject: [PATCH] [Fix #476] Fix a false positive for `Rails/ReversibleMigratin` Fixes #476. This PR fixes a false positive for `Rails/ReversibleMigratin` when using `drop_table` with symbol proc. --- CHANGELOG.md | 1 + lib/rubocop/cop/rails/reversible_migration.rb | 2 +- spec/rubocop/cop/rails/reversible_migration_spec.rb | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fe0501ab2..6e4e814c47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ * [#137](https://github.com/rubocop/rubocop-rails/issues/137): Make `Rails/HasManyOrHasOneDependent` aware of `readonly?` is `true`. ([@koic][]) * [#474](https://github.com/rubocop/rubocop-rails/pull/474): Fix a false negative for `Rails/SafeNavigation` when using `try!` without receiver. ([@koic][]) * [#126](https://github.com/rubocop/rubocop-rails/issues/126): Fix an incorrect auto-correct for `Rails/SafeNavigation` with `Style/RedndantSelf`. ([@koic][]) +* [#476](https://github.com/rubocop/rubocop-rails/issues/476): Fix a false positive for `Rails/ReversibleMigratin` when using `drop_table` with symbol proc. ([@koic][]) ### Changes diff --git a/lib/rubocop/cop/rails/reversible_migration.rb b/lib/rubocop/cop/rails/reversible_migration.rb index 7c12cea115..36f5f05117 100644 --- a/lib/rubocop/cop/rails/reversible_migration.rb +++ b/lib/rubocop/cop/rails/reversible_migration.rb @@ -237,7 +237,7 @@ def check_irreversible_schema_statement_node(node) def check_drop_table_node(node) drop_table_call(node) do - unless node.parent.block_type? + unless node.parent.block_type? || node.last_argument.block_pass_type? add_offense( node, message: format(MSG, action: 'drop_table(without block)') diff --git a/spec/rubocop/cop/rails/reversible_migration_spec.rb b/spec/rubocop/cop/rails/reversible_migration_spec.rb index 694066033a..9788fc57bf 100644 --- a/spec/rubocop/cop/rails/reversible_migration_spec.rb +++ b/spec/rubocop/cop/rails/reversible_migration_spec.rb @@ -101,6 +101,10 @@ def change end RUBY + it_behaves_like 'accepts', 'drop_table(with symbol proc)', <<~RUBY + drop_table :users, &:timestamps + RUBY + it_behaves_like 'offense', 'drop_table(without block)', <<~RUBY drop_table :users RUBY