Commit e2d52c82 authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch 'pb-fix-multiple-database-false-positives' into 'master'

Update MultipleDatabase cop to allow some methods

See merge request gitlab-org/gitlab!81584
parents c0b058c1 5b964ed4
......@@ -18,10 +18,8 @@ Database/MultipleDatabases:
- lib/gitlab/database/migrations/observers/query_log.rb
- lib/gitlab/database/partitioning_migration_helpers/backfill_partitioned_table.rb
- lib/gitlab/database.rb
- lib/gitlab/gitlab_import/importer.rb
- lib/gitlab/health_checks/db_check.rb
- lib/gitlab/import_export/group/relation_tree_restorer.rb
- lib/gitlab/legacy_github_import/importer.rb
- lib/gitlab/seeder.rb
- spec/db/schema_spec.rb
- spec/initializers/database_config_spec.rb
......
......@@ -17,6 +17,10 @@ module RuboCop
https://docs.gitlab.com/ee/development/database/transaction_guidelines.html
EOF
ALLOWED_METHODS = %i[
no_touching
].freeze
def_node_matcher :active_record_base_method_is_used?, <<~PATTERN
(send (const (const nil? :ActiveRecord) :Base) $_)
PATTERN
......@@ -24,8 +28,17 @@ module RuboCop
def on_send(node)
return unless active_record_base_method_is_used?(node)
active_record_base_method = node.children[1]
return if method_is_allowed?(active_record_base_method)
add_offense(node, location: :expression, message: AR_BASE_MESSAGE)
end
private
def method_is_allowed?(method_name)
ALLOWED_METHODS.include?(method_name.to_sym)
end
end
end
end
......
......@@ -12,4 +12,14 @@ RSpec.describe RuboCop::Cop::Database::MultipleDatabases do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use methods from ActiveRecord::Base, [...]
SOURCE
end
described_class::ALLOWED_METHODS.each do |method_name|
it "does not flag use of ActiveRecord::Base.#{method_name}" do
expect_no_offenses(<<~SOURCE)
ActiveRecord::Base.#{method_name} do
Project.save
end
SOURCE
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment