Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-09-27 18:09:37 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-09-27 18:09:37 +0300
commit57ae76cdb503afd6c0821de3a03b4387af6b59eb (patch)
treed6ffcbdd75157d969fcd5f4850f3a11f21b95a6c /rubocop
parent5471fef2360f9bcf604a026d5807a554dae243e9 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/background_migration/feature_category.rb29
-rw-r--r--rubocop/cop/rspec/invalid_feature_category.rb29
-rw-r--r--rubocop/feature_categories.rb35
3 files changed, 49 insertions, 44 deletions
diff --git a/rubocop/cop/background_migration/feature_category.rb b/rubocop/cop/background_migration/feature_category.rb
index f6b68e03736..7a96271224d 100644
--- a/rubocop/cop/background_migration/feature_category.rb
+++ b/rubocop/cop/background_migration/feature_category.rb
@@ -2,6 +2,7 @@
require_relative '../../migration_helpers'
require_relative '../../code_reuse_helpers'
+require_relative '../../feature_categories'
module RuboCop
module Cop
@@ -10,32 +11,20 @@ module RuboCop
class FeatureCategory < RuboCop::Cop::Base
include MigrationHelpers
- FEATURE_CATEGORIES_FILE_PATH = File.expand_path("../../../config/feature_categories.yml", __dir__)
-
MSG = "'feature_category' should be defined to better assign the ownership for batched migration jobs. " \
"For more details refer: " \
"https://docs.gitlab.com/ee/development/feature_categorization/#batched-background-migrations"
- INVALID_FEATURE_CATEGORY_MSG = "'feature_category' is invalid. " \
- "List of valid ones can be found in #{FEATURE_CATEGORIES_FILE_PATH}".freeze
+ INVALID_FEATURE_CATEGORY_MSG =
+ "'feature_category' is invalid. " \
+ "List of valid ones can be found in #{FeatureCategories::CONFIG_PATH}".freeze
RESTRICT_ON_SEND = [:feature_category].freeze
- class << self
- attr_accessor :available_feature_categories
- end
-
def_node_search :feature_category?, <<~PATTERN
(:send nil? :feature_category ...)
PATTERN
- def on_new_investigation
- super
-
- # Defined only once per rubocop whole run instead of each file.
- fetch_available_feature_categories unless self.class.available_feature_categories.present?
- end
-
def on_class(node)
return unless in_background_migration?(node) && node.parent_class&.short_name == :BatchedMigrationJob
@@ -48,15 +37,15 @@ module RuboCop
add_offense(node, message: INVALID_FEATURE_CATEGORY_MSG) unless valid_feature_category?(node)
end
+ def external_dependency_checksum
+ FeatureCategories.config_checksum
+ end
+
private
def valid_feature_category?(node)
feature_category = node.descendants.first.value
- self.class.available_feature_categories.include?(feature_category.to_s)
- end
-
- def fetch_available_feature_categories
- self.class.available_feature_categories = YAML.load_file(FEATURE_CATEGORIES_FILE_PATH).to_set
+ FeatureCategories.available.include?(feature_category.to_s)
end
end
end
diff --git a/rubocop/cop/rspec/invalid_feature_category.rb b/rubocop/cop/rspec/invalid_feature_category.rb
index 9ef880d6aac..afb762cd283 100644
--- a/rubocop/cop/rspec/invalid_feature_category.rb
+++ b/rubocop/cop/rspec/invalid_feature_category.rb
@@ -4,6 +4,8 @@ require 'rubocop/cop/rspec/base'
require 'rubocop/cop/rspec/mixin/top_level_group'
require 'did_you_mean'
+require_relative '../../feature_categories'
+
module RuboCop
module Cop
module RSpec
@@ -34,16 +36,6 @@ module RuboCop
MSG_SYMBOL = 'Please use a symbol as value.'
- FEATURE_CATEGORIES_PATH = File.expand_path('../../../config/feature_categories.yml', __dir__).freeze
-
- # List of feature categories which are not defined in config/feature_categories.yml
- CUSTOM_FEATURE_CATEGORIES = [
- # https://docs.gitlab.com/ee/development/feature_categorization/#tooling-feature-category
- :tooling,
- # https://docs.gitlab.com/ee/development/feature_categorization/#shared-feature-category
- :shared
- ].to_set.freeze
-
# @!method feature_category?(node)
def_node_matcher :feature_category_value, <<~PATTERN
(block
@@ -69,17 +61,14 @@ module RuboCop
add_offense(value_node, message: message)
end
- # Used by RuboCop to invalidate its cache if the contents of
- # config/feature_categories.yml changes.
def external_dependency_checksum
- @external_dependency_checksum ||=
- Digest::SHA256.file(FEATURE_CATEGORIES_PATH).hexdigest
+ FeatureCategories.config_checksum
end
private
def suggestion_message(value_node)
- spell = DidYouMean::SpellChecker.new(dictionary: self.class.feature_categories)
+ spell = DidYouMean::SpellChecker.new(dictionary: FeatureCategories.available_with_custom)
suggestions = spell.correct(value_node.value)
return if suggestions.none?
@@ -88,15 +77,7 @@ module RuboCop
end
def valid_feature_category?(node)
- self.class.feature_categories.include?(node.value)
- end
-
- def self.feature_categories
- @feature_categories ||= YAML
- .load_file(FEATURE_CATEGORIES_PATH)
- .map(&:to_sym)
- .to_set
- .union(CUSTOM_FEATURE_CATEGORIES)
+ FeatureCategories.available_with_custom.include?(node.value.to_s)
end
end
end
diff --git a/rubocop/feature_categories.rb b/rubocop/feature_categories.rb
new file mode 100644
index 00000000000..451989184d8
--- /dev/null
+++ b/rubocop/feature_categories.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+require 'set'
+require 'yaml'
+require 'digest/sha2'
+
+module RuboCop
+ module FeatureCategories
+ CONFIG_PATH = File.expand_path("../config/feature_categories.yml", __dir__)
+
+ # List of feature categories which are not defined in config/feature_categories.yml
+ # https://docs.gitlab.com/ee/development/feature_categorization/#tooling-feature-category
+ # https://docs.gitlab.com/ee/development/feature_categorization/#shared-feature-category
+ CUSTOM_CATEGORIES = %w[
+ tooling
+ shared
+ ].to_set.freeze
+
+ def self.available
+ @available ||= YAML.load_file(CONFIG_PATH).to_set
+ end
+
+ def self.available_with_custom
+ @available_with_custom ||= available.union(CUSTOM_CATEGORIES)
+ end
+
+ # Used by RuboCop to invalidate its cache if the contents of
+ # config/feature_categories.yml changes.
+ # Define a method called `external_dependency_checksum` and call
+ # this method to use it.
+ def self.config_checksum
+ @config_checksum ||= Digest::SHA256.file(CONFIG_PATH).hexdigest
+ end
+ end
+end