diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-20 15:19:03 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-20 15:19:03 +0000 |
commit | 14bd84b61276ef29b97d23642d698de769bacfd2 (patch) | |
tree | f9eba90140c1bd874211dea17750a0d422c04080 /rubocop | |
parent | 891c388697b2db0d8ee0c8358a9bdbf6dc56d581 (diff) | |
download | gitlab-ce-14bd84b61276ef29b97d23642d698de769bacfd2.tar.gz |
Add latest changes from gitlab-org/gitlab@15-10-stable-eev15.10.0-rc42
Diffstat (limited to 'rubocop')
-rw-r--r-- | rubocop/cop/background_migration/missing_dictionary_file.rb | 59 | ||||
-rw-r--r-- | rubocop/cop/gitlab/feature_available_usage.rb | 2 | ||||
-rw-r--r-- | rubocop/cop/gitlab/json.rb | 6 | ||||
-rw-r--r-- | rubocop/cop/gitlab/mark_used_feature_flags.rb | 24 | ||||
-rw-r--r-- | rubocop/cop/graphql/id_type.rb | 2 | ||||
-rw-r--r-- | rubocop/cop/migration/add_reference.rb | 2 | ||||
-rw-r--r-- | rubocop/cop/rspec/factory_bot/inline_association.rb | 2 | ||||
-rw-r--r-- | rubocop/rubocop-ruby30.yml | 4 | ||||
-rw-r--r-- | rubocop/rubocop-ruby31.yml | 10 |
9 files changed, 78 insertions, 33 deletions
diff --git a/rubocop/cop/background_migration/missing_dictionary_file.rb b/rubocop/cop/background_migration/missing_dictionary_file.rb new file mode 100644 index 00000000000..9158b268bf9 --- /dev/null +++ b/rubocop/cop/background_migration/missing_dictionary_file.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +require_relative '../../migration_helpers' + +module RuboCop + module Cop + module BackgroundMigration + # Checks the batched background migration has the corresponding dictionary file + class MissingDictionaryFile < RuboCop::Cop::Base + include MigrationHelpers + + MSG = "Missing %{file_name}. " \ + "Use the generator 'batched_background_migration' to create dictionary files automatically. " \ + "For more details refer: https://docs.gitlab.com/ee/development/database/batched_background_migrations.html#generator" + + DICTIONARY_DIR = "db/docs/batched_background_migrations" + + def_node_matcher :batched_background_migration_name_node, <<~PATTERN + `(send nil? :queue_batched_background_migration $_ ...) + PATTERN + + def_node_matcher :migration_constant_value, <<~PATTERN + `(casgn nil? %const_name ({sym|str} $_)) + PATTERN + + def on_class(node) + return unless time_enforced?(node) && in_post_deployment_migration?(node) + + migration_name_node = batched_background_migration_name_node(node) + return unless migration_name_node + + migration_name = if migration_name_node.const_name.present? + migration_constant_value(node, const_name: migration_name_node.const_name.to_sym) + else + migration_name_node.value + end + + return if dictionary_file?(migration_name) + + add_offense(node, message: format(MSG, file_name: dictionary_file_path(migration_name))) + end + + private + + def dictionary_file?(migration_class_name) + File.exist?(dictionary_file_path(migration_class_name)) + end + + def dictionary_file_path(migration_class_name) + File.join(rails_root, DICTIONARY_DIR, "#{migration_class_name.underscore}.yml") + end + + def rails_root + @rails_root ||= File.expand_path('../../..', __dir__) + end + end + end + end +end diff --git a/rubocop/cop/gitlab/feature_available_usage.rb b/rubocop/cop/gitlab/feature_available_usage.rb index fcf4992a19d..df4409c27e0 100644 --- a/rubocop/cop/gitlab/feature_available_usage.rb +++ b/rubocop/cop/gitlab/feature_available_usage.rb @@ -39,7 +39,7 @@ module RuboCop return if feature_name(node).nil? return if ALL_FEATURES.include?(feature_name(node)) && args_count(node) == 2 - if !ALL_FEATURES.include?(feature_name(node)) + if !ALL_FEATURES.include?(feature_name(node)) # rubocop:disable Rails/NegateInclude add_offense(node, message: licensed_feature_message(node)) elsif args_count(node) < 2 add_offense(node, message: NOT_ENOUGH_ARGS_MSG) diff --git a/rubocop/cop/gitlab/json.rb b/rubocop/cop/gitlab/json.rb index cf2ed0ba536..8b10850b894 100644 --- a/rubocop/cop/gitlab/json.rb +++ b/rubocop/cop/gitlab/json.rb @@ -6,9 +6,9 @@ module RuboCop class Json < RuboCop::Cop::Base extend RuboCop::Cop::AutoCorrector - MSG = <<~EOL + MSG = <<~TEXT Prefer `Gitlab::Json` over calling `JSON` directly. See https://docs.gitlab.com/ee/development/json.html - EOL + TEXT AVAILABLE_METHODS = %i[parse parse! load decode dump generate encode pretty_generate].to_set.freeze @@ -41,7 +41,7 @@ module RuboCop end def cbased(node) - return unless %r{/ee/}.match?(node.location.expression.source_buffer.name) + return unless node.location.expression.source_buffer.name.include?('/ee/') "::" end diff --git a/rubocop/cop/gitlab/mark_used_feature_flags.rb b/rubocop/cop/gitlab/mark_used_feature_flags.rb index ffd59c8fffc..f466ab87aa0 100644 --- a/rubocop/cop/gitlab/mark_used_feature_flags.rb +++ b/rubocop/cop/gitlab/mark_used_feature_flags.rb @@ -32,12 +32,6 @@ module RuboCop RESTRICT_ON_SEND = FEATURE_METHODS + SELF_METHODS - USAGE_DATA_COUNTERS_EVENTS_YAML_GLOBS = [ - File.expand_path("../../../config/metrics/aggregates/*.yml", __dir__), - File.expand_path("../../../lib/gitlab/usage_data_counters/known_events/*.yml", __dir__), - File.expand_path("../../../ee/lib/ee/gitlab/usage_data_counters/known_events/*.yml", __dir__) - ].freeze - class << self # We track feature flags in `on_new_investigation` only once per # rubocop whole run instead once per file. @@ -52,8 +46,6 @@ module RuboCop return if self.class.feature_flags_already_tracked self.class.feature_flags_already_tracked = true - - track_usage_data_counters_known_events! end def on_casgn(node) @@ -184,22 +176,6 @@ module RuboCop feature_method?(node) || self_method?(node) end - # Marking all event's feature flags as used as Gitlab::UsageDataCounters::HLLRedisCounter.track_event{,context} - # is mostly used with dynamic event name. - def track_usage_data_counters_known_events! - usage_data_counters_known_event_feature_flags.each { |feature_flag_name| save_used_feature_flag(feature_flag_name) } - end - - def usage_data_counters_known_event_feature_flags - USAGE_DATA_COUNTERS_EVENTS_YAML_GLOBS.each_with_object(Set.new) do |glob, memo| - Dir.glob(glob).each do |path| - YAML.safe_load(File.read(path))&.each do |hash| - memo << hash['feature_flag'] if hash['feature_flag'] - end - end - end - end - def defined_feature_flags @defined_feature_flags ||= begin flags_paths = [ diff --git a/rubocop/cop/graphql/id_type.rb b/rubocop/cop/graphql/id_type.rb index eb677aa4507..c9d9b4ea6eb 100644 --- a/rubocop/cop/graphql/id_type.rb +++ b/rubocop/cop/graphql/id_type.rb @@ -21,7 +21,7 @@ module RuboCop private def does_not_match?(arg) - !WHITELISTED_ARGUMENTS.include?(arg) + !WHITELISTED_ARGUMENTS.include?(arg) # rubocop:disable Rails/NegateInclude end end end diff --git a/rubocop/cop/migration/add_reference.rb b/rubocop/cop/migration/add_reference.rb index 02a0ef899b4..8daa85749fd 100644 --- a/rubocop/cop/migration/add_reference.rb +++ b/rubocop/cop/migration/add_reference.rb @@ -41,7 +41,7 @@ module RuboCop private def existing_table?(new_tables, table) - !new_tables.include?(table) + !new_tables.include?(table) # rubocop:disable Rails/NegateInclude end def create_table?(node) diff --git a/rubocop/cop/rspec/factory_bot/inline_association.rb b/rubocop/cop/rspec/factory_bot/inline_association.rb index 8d7c73b99a0..acd2c10a63d 100644 --- a/rubocop/cop/rspec/factory_bot/inline_association.rb +++ b/rubocop/cop/rspec/factory_bot/inline_association.rb @@ -99,7 +99,7 @@ module RuboCop def inside_assocation_definition?(node) node.each_ancestor(:block).any? do |parent| name = association_definition(parent) - name && !SKIP_NAMES.include?(name) + name && !SKIP_NAMES.include?(name) # rubocop:disable Rails/NegateInclude end end end diff --git a/rubocop/rubocop-ruby30.yml b/rubocop/rubocop-ruby30.yml index d46bb9388a3..b984d761b80 100644 --- a/rubocop/rubocop-ruby30.yml +++ b/rubocop/rubocop-ruby30.yml @@ -2,8 +2,8 @@ # Ruby 3.0. # # After the transition has been completed: -# * Move all configuration which enable cops to .rubocop.yml. -# * Remove all reminaing configuration. +# * Move all configuration which enabled or tweaked cops to .rubocop.yml. +# * Remove all remaining configuration. # These cops are disabled in Ruby 2.7 (rubocop-27.yml). Style/MutableConstant: diff --git a/rubocop/rubocop-ruby31.yml b/rubocop/rubocop-ruby31.yml new file mode 100644 index 00000000000..109c7ca2dfe --- /dev/null +++ b/rubocop/rubocop-ruby31.yml @@ -0,0 +1,10 @@ +# RuboCop configuration adjustments during the transition time from Ruby 3.0 to +# Ruby 3.1. +# +# After the transition has been completed: +# * Move all configuration which enabled or tweaked cops to .rubocop.yml. +# * Remove all remaining configuration. + +# Short-hand Hash syntax does not work prior 3.1. +Style/HashSyntax: + EnforcedShorthandSyntax: never |