Skip to content
代码片段 群组 项目
提交 78a45db5 编辑于 作者: Terri Chu's avatar Terri Chu 提交者: Peter Leitzen
浏览文件

Add rubocop for deprecated advanced search migrations

上级 70fb4f8c
No related branches found
No related tags found
无相关合并请求
......@@ -1025,3 +1025,10 @@ RSpec/FactoryBot/LocalStaticAssignment:
Rails/TransactionExitStatement:
Enabled: true
Search/AvoidCheckingFinishedOnDeprecatedMigrations:
Include:
- 'ee/app/models/**/*.rb'
- 'ee/lib/elastic/**/*.rb'
- 'ee/lib/gitlab/elastic/**/*.rb'
- 'ee/spec/support/helpers/elasticsearch_helpers.rb'
---
Search/AvoidCheckingFinishedOnDeprecatedMigrations:
Details: grace period
# frozen_string_literal: true
module RuboCop
module Cop
module Search
# Cop that prevents checking migration_has_finished? on deprecated migrations
#
# @example
#
# # bad
# def disable_project_joins_for_blob?
# Elastic::DataMigrationService
# .migration_has_finished?(:backfill_project_permissions_in_blobs_using_permutations)
# end
#
# # good
# def disable_project_joins_for_blob?
# Elastic::DataMigrationService.migration_has_finished?(:backfill_project_permissions_in_blobs)
# end
class AvoidCheckingFinishedOnDeprecatedMigrations < RuboCop::Cop::Base
MSG = 'Migration is deprecated and can not be used with `migration_has_finished?`.'
def_node_matcher :deprecated_migration?, <<~PATTERN
(send
(const (const {nil? cbase} :Elastic) :DataMigrationService) :migration_has_finished?
(sym :backfill_project_permissions_in_blobs_using_permutations))
PATTERN
RESTRICT_ON_SEND = %i[migration_has_finished?].freeze
def on_send(node)
add_offense(node) if deprecated_migration?(node)
end
end
end
end
end
# frozen_string_literal: true
require 'rubocop_spec_helper'
require_relative '../../../../rubocop/cop/search/avoid_checking_finished_on_deprecated_migrations'
RSpec.describe RuboCop::Cop::Search::AvoidCheckingFinishedOnDeprecatedMigrations, feature_category: :global_search do
context 'when a deprecated class is used with migration_has_finished?' do
it 'flags it as an offense' do
expect_offense <<~SOURCE
return if Elastic::DataMigrationService.migration_has_finished?(:backfill_project_permissions_in_blobs_using_permutations)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Migration is deprecated and can not be used with `migration_has_finished?`.
SOURCE
end
end
context 'when a non deprecated class is used with migration_has_finished?' do
it 'does not flag it as an offense' do
expect_no_offenses <<~SOURCE
return if Elastic::DataMigrationService.migration_has_finished?(:backfill_project_permissions_in_blobs)
SOURCE
end
end
context 'when migration_has_finished? method is called on another class' do
it 'does not flag it as an offense' do
expect_no_offenses <<~SOURCE
return if Klass.migration_has_finished?(:backfill_project_permissions_in_blobs_using_permutations)
SOURCE
end
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册