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-01-18 22:00:14 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-01-18 22:00:14 +0300
commit05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch)
tree11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /rubocop
parentec73467c23693d0db63a797d10194da9e72a74af (diff)
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.0-rc42
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/check_graceful_task.rb2
-rw-r--r--rubocop/cop/background_migration/feature_category.rb64
-rw-r--r--rubocop/cop/gitlab/strong_memoize_attr.rb19
-rw-r--r--rubocop/cop/lint/last_keyword_argument.rb8
-rw-r--r--rubocop/rubocop-migrations.yml6
-rw-r--r--rubocop/rubocop-ruby30.yml4
6 files changed, 91 insertions, 12 deletions
diff --git a/rubocop/check_graceful_task.rb b/rubocop/check_graceful_task.rb
index 724f7fa6963..7bf678def83 100644
--- a/rubocop/check_graceful_task.rb
+++ b/rubocop/check_graceful_task.rb
@@ -69,7 +69,7 @@ module RuboCop
message = format(
':warning: `%{job_name}` passed :green: but contained <%{job_url}|silenced offenses>. ' \
'See <%{docs_link}|docs>.',
- docs_link: 'https://docs.gitlab.com/ee/development/contributing/style_guides.html#silenced-offenses',
+ docs_link: 'https://docs.gitlab.com/ee/development/rubocop_development_guide.html#silenced-offenses',
job_name: job_name,
job_url: job_url)
diff --git a/rubocop/cop/background_migration/feature_category.rb b/rubocop/cop/background_migration/feature_category.rb
new file mode 100644
index 00000000000..ec70b5baadf
--- /dev/null
+++ b/rubocop/cop/background_migration/feature_category.rb
@@ -0,0 +1,64 @@
+# frozen_string_literal: true
+
+require_relative '../../migration_helpers'
+require_relative '../../code_reuse_helpers'
+
+module RuboCop
+ module Cop
+ module BackgroundMigration
+ # Cop that checks if a valid 'feature_category' is defined in the batched background migration job
+ class FeatureCategory < RuboCop::Cop::Base
+ include MigrationHelpers
+
+ FEATURE_CATEGORIES_FILE_PATH = "config/feature_categories.yml"
+
+ 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}"
+
+ 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
+
+ add_offense(node) unless feature_category?(node)
+ end
+
+ def on_send(node)
+ return unless in_background_migration?(node)
+
+ add_offense(node, message: INVALID_FEATURE_CATEGORY_MSG) unless valid_feature_category?(node)
+ 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
+ end
+ end
+ end
+ end
+end
diff --git a/rubocop/cop/gitlab/strong_memoize_attr.rb b/rubocop/cop/gitlab/strong_memoize_attr.rb
index c98aa4765fa..0b3de9d7863 100644
--- a/rubocop/cop/gitlab/strong_memoize_attr.rb
+++ b/rubocop/cop/gitlab/strong_memoize_attr.rb
@@ -34,12 +34,12 @@ module RuboCop
class StrongMemoizeAttr < RuboCop::Cop::Base
extend RuboCop::Cop::AutoCorrector
- MSG = 'Use `strong_memoize_attr`, instead of using `strong_memoize` directly'
+ MSG = 'Use `strong_memoize_attr`, instead of using `strong_memoize` directly.'
def_node_matcher :strong_memoize?, <<~PATTERN
(block
$(send nil? :strong_memoize
- (sym $_)
+ (sym _)
)
(args)
$_
@@ -47,21 +47,26 @@ module RuboCop
PATTERN
def on_block(node)
- send_node, attr_name, body = strong_memoize?(node)
+ send_node, body = strong_memoize?(node)
return unless send_node
- corrector = autocorrect_pure_definitions(node.parent, attr_name, body) if node.parent.def_type?
+ # Don't flag methods with parameters.
+ return if send_node.each_ancestor(:def).first&.arguments&.any?
+
+ # Don't flag singleton methods.
+ return if send_node.each_ancestor(:defs).any?
+
+ corrector = autocorrect_pure_definitions(node.parent, body) if node.parent.def_type?
add_offense(send_node, &corrector)
end
private
- def autocorrect_pure_definitions(def_node, attr_name, body)
+ def autocorrect_pure_definitions(def_node, body)
proc do |corrector|
method_name = def_node.method_name
- attr_suffix = ", :#{attr_name}" if attr_name != method_name
- replacement = "\n#{indent(def_node)}strong_memoize_attr :#{method_name}#{attr_suffix}"
+ replacement = "\n#{indent(def_node)}strong_memoize_attr :#{method_name}"
corrector.insert_after(def_node, replacement)
corrector.replace(def_node.body, body.source)
diff --git a/rubocop/cop/lint/last_keyword_argument.rb b/rubocop/cop/lint/last_keyword_argument.rb
index 3f5ad7e20d7..f50c25f7924 100644
--- a/rubocop/cop/lint/last_keyword_argument.rb
+++ b/rubocop/cop/lint/last_keyword_argument.rb
@@ -18,6 +18,8 @@ module RuboCop
KEYWORD_DEPRECATION_STR = 'maybe ** should be added to the call'
def on_send(node)
+ return if target_ruby_version >= 3.0
+
arg = get_last_argument(node)
return unless arg
@@ -49,13 +51,13 @@ module RuboCop
end
def known_match?(file_path, line_number, method_name)
- file_path_from_root = file_path.sub(File.expand_path('../../..', __dir__), '')
- file_and_line = "#{file_path_from_root}:#{line_number}"
-
method_name = 'initialize' if method_name == 'new'
return unless self.class.keyword_warnings[method_name]
+ file_path_from_root = file_path.sub(File.expand_path('../../..', __dir__), '')
+ file_and_line = "#{file_path_from_root}:#{line_number}"
+
self.class.keyword_warnings[method_name].any? do |warning|
warning.include?(file_and_line)
end
diff --git a/rubocop/rubocop-migrations.yml b/rubocop/rubocop-migrations.yml
index ccde12bca77..36ef17ad6a3 100644
--- a/rubocop/rubocop-migrations.yml
+++ b/rubocop/rubocop-migrations.yml
@@ -12,10 +12,14 @@ Migration/UpdateLargeTable:
- :ci_builds_metadata
- :ci_build_trace_metadata
- :ci_job_artifacts
- - :ci_pipeline_messages
+ - :ci_job_artifact_states
+ - :ci_job_variables
+ - :ci_namespace_mirrors
- :ci_pipelines
- :ci_pipelines_config
+ - :ci_pipeline_messages
- :ci_pipeline_variables
+ - :ci_refs
- :ci_stages
- :deployments
- :description_versions
diff --git a/rubocop/rubocop-ruby30.yml b/rubocop/rubocop-ruby30.yml
index 6cd3f66ce55..b7634210e3d 100644
--- a/rubocop/rubocop-ruby30.yml
+++ b/rubocop/rubocop-ruby30.yml
@@ -14,3 +14,7 @@ Style/MutableConstant:
Enabled: false
Style/RedundantFreeze:
Enabled: false
+
+# No longer needed because Ruby 3.0 will fail due to kwargs issues.
+Lint/LastKeywordArgument:
+ Enabled: false