From a13353a4c4fcae0df725c35e2953bb6588087f11 Mon Sep 17 00:00:00 2001 From: Mohammad Aseem <mhdasm3@gmail.com> Date: Sat, 3 Dec 2022 06:06:04 +0000 Subject: [PATCH] Fix Rails/NegateInclude offenses --- .rubocop_todo/rails/negate_include.yml | 56 ------------------- app/finders/projects_finder.rb | 2 +- app/helpers/application_settings_helper.rb | 2 +- app/helpers/projects_helper.rb | 2 +- app/helpers/tree_helper.rb | 2 +- .../chat_message/pipeline_message.rb | 2 +- app/models/integrations/field.rb | 2 +- app/models/label.rb | 2 +- app/models/merge_request.rb | 2 +- app/models/milestone.rb | 2 +- app/services/todo_service.rb | 2 +- .../work_items/parent_links/create_service.rb | 2 +- config/application.rb | 2 +- config/initializers/1_settings.rb | 2 +- danger/roulette/Dangerfile | 2 +- .../pipeline_vulnerabilities_finder.rb | 2 +- ee/app/models/ee/vulnerability.rb | 2 +- ee/app/services/epic_issues/create_service.rb | 2 +- .../ingestion/tasks/ingest_remediations.rb | 2 +- .../validate_policy_service.rb | 2 +- lib/api/maven_packages.rb | 2 +- ...te_orphans_approval_merge_request_rules.rb | 2 +- .../legacy_upload_mover.rb | 2 +- .../ci/build/rules/rule/clause/exists.rb | 4 +- .../ci/parsers/coverage/sax_document.rb | 2 +- lib/gitlab/ci/queue/metrics.rb | 4 +- lib/gitlab/database/each_database.rb | 4 +- .../email/handler/create_issue_handler.rb | 2 +- .../email/handler/service_desk_handler.rb | 2 +- lib/gitlab/graphql/queries.rb | 4 +- .../import_export/attributes_permitter.rb | 2 +- lib/gitlab/search_results.rb | 2 +- lib/gitlab/task_helpers.rb | 2 +- lib/gitlab/url_blocker.rb | 2 +- lib/gitlab_edition.rb | 4 +- qa/qa/page/merge_request/show.rb | 2 +- qa/qa/runtime/ip_address.rb | 2 +- qa/qa/support/run.rb | 2 +- qa/qa/tools/delete_test_users.rb | 4 +- rubocop/cop/gitlab/feature_available_usage.rb | 2 +- rubocop/cop/graphql/id_type.rb | 2 +- rubocop/cop/migration/add_reference.rb | 2 +- .../rspec/factory_bot/inline_association.rb | 2 +- scripts/lib/gitlab.rb | 4 +- scripts/static-analysis | 2 +- spec/lib/container_registry/blob_spec.rb | 4 +- spec/lib/container_registry/client_spec.rb | 2 +- .../stages/metric_endpoint_inserter_spec.rb | 2 +- .../metrics/subscribers/active_record_spec.rb | 4 +- .../pushed_frontend_feature_flags_matcher.rb | 2 +- .../markdown_golden_master_shared_examples.rb | 2 +- spec/uploaders/object_storage_spec.rb | 2 +- tooling/danger/specs.rb | 2 +- 53 files changed, 61 insertions(+), 117 deletions(-) delete mode 100644 .rubocop_todo/rails/negate_include.yml diff --git a/.rubocop_todo/rails/negate_include.yml b/.rubocop_todo/rails/negate_include.yml deleted file mode 100644 index 74f469f325b2f..0000000000000 --- a/.rubocop_todo/rails/negate_include.yml +++ /dev/null @@ -1,56 +0,0 @@ ---- -# Cop supports --autocorrect. -Rails/NegateInclude: - Details: grace period - Exclude: - - 'app/finders/projects_finder.rb' - - 'app/helpers/application_settings_helper.rb' - - 'app/helpers/projects_helper.rb' - - 'app/helpers/tree_helper.rb' - - 'app/models/integrations/chat_message/pipeline_message.rb' - - 'app/models/integrations/field.rb' - - 'app/models/label.rb' - - 'app/models/merge_request.rb' - - 'app/models/milestone.rb' - - 'app/services/todo_service.rb' - - 'app/services/work_items/parent_links/create_service.rb' - - 'config/application.rb' - - 'config/initializers/1_settings.rb' - - 'danger/roulette/Dangerfile' - - 'ee/app/finders/security/pipeline_vulnerabilities_finder.rb' - - 'ee/app/models/ee/vulnerability.rb' - - 'ee/app/services/epic_issues/create_service.rb' - - 'ee/app/services/security/ingestion/tasks/ingest_remediations.rb' - - 'ee/app/services/security/security_orchestration_policies/validate_policy_service.rb' - - 'lib/api/maven_packages.rb' - - 'lib/gitlab/background_migration/legacy_upload_mover.rb' - - 'lib/gitlab/ci/build/rules/rule/clause/exists.rb' - - 'lib/gitlab/ci/parsers/coverage/sax_document.rb' - - 'lib/gitlab/ci/queue/metrics.rb' - - 'lib/gitlab/database/each_database.rb' - - 'lib/gitlab/email/handler/create_issue_handler.rb' - - 'lib/gitlab/email/handler/service_desk_handler.rb' - - 'lib/gitlab/graphql/queries.rb' - - 'lib/gitlab/import_export/attributes_permitter.rb' - - 'lib/gitlab/search_results.rb' - - 'lib/gitlab/task_helpers.rb' - - 'lib/gitlab/url_blocker.rb' - - 'lib/gitlab_edition.rb' - - 'qa/qa/page/merge_request/show.rb' - - 'qa/qa/runtime/ip_address.rb' - - 'qa/qa/support/run.rb' - - 'qa/qa/tools/delete_test_users.rb' - - 'rubocop/cop/gitlab/feature_available_usage.rb' - - 'rubocop/cop/graphql/id_type.rb' - - 'rubocop/cop/migration/add_reference.rb' - - 'rubocop/cop/rspec/factory_bot/inline_association.rb' - - 'scripts/lib/gitlab.rb' - - 'scripts/static-analysis' - - 'spec/lib/container_registry/blob_spec.rb' - - 'spec/lib/container_registry/client_spec.rb' - - 'spec/lib/gitlab/metrics/dashboard/stages/metric_endpoint_inserter_spec.rb' - - 'spec/lib/gitlab/metrics/subscribers/active_record_spec.rb' - - 'spec/support/matchers/pushed_frontend_feature_flags_matcher.rb' - - 'spec/support/shared_contexts/markdown_golden_master_shared_examples.rb' - - 'spec/uploaders/object_storage_spec.rb' - - 'tooling/danger/specs.rb' diff --git a/app/finders/projects_finder.rb b/app/finders/projects_finder.rb index 3c42a1f769f01..6b1c52c357e26 100644 --- a/app/finders/projects_finder.rb +++ b/app/finders/projects_finder.rb @@ -134,7 +134,7 @@ def impossible_visibility_level? public_visibility_levels = Gitlab::VisibilityLevel.levels_for_user(current_user) - !public_visibility_levels.include?(params[:visibility_level].to_i) + public_visibility_levels.exclude?(params[:visibility_level].to_i) end def owned_projects? diff --git a/app/helpers/application_settings_helper.rb b/app/helpers/application_settings_helper.rb index f573aa3473023..4fb53fcc73820 100644 --- a/app/helpers/application_settings_helper.rb +++ b/app/helpers/application_settings_helper.rb @@ -104,7 +104,7 @@ def import_sources_checkboxes(form) def oauth_providers_checkboxes(form) button_based_providers.map do |source| - checked = !@application_setting.disabled_oauth_sign_in_sources.include?(source.to_s) + checked = @application_setting.disabled_oauth_sign_in_sources.exclude?(source.to_s) name = Gitlab::Auth::OAuth::Provider.label_for(source) form.gitlab_ui_checkbox_component( diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index d44ba35bb4431..a3fbf78c91942 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -696,7 +696,7 @@ def project_permissions_settings(project) def project_allowed_visibility_levels(project) Gitlab::VisibilityLevel.values.select do |level| - project.visibility_level_allowed?(level) && !restricted_levels.include?(level) + project.visibility_level_allowed?(level) && restricted_levels.exclude?(level) end end diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb index 370dbb104621d..6f8b80aead91c 100644 --- a/app/helpers/tree_helper.rb +++ b/app/helpers/tree_helper.rb @@ -96,7 +96,7 @@ def path_breadcrumbs(max_links = 6) part_path = File.join(part_path, part) unless part_path.empty? part_path = part if part_path.empty? - next if parts.count > max_links && !parts.last(2).include?(part) + next if parts.count > max_links && parts.last(2).exclude?(part) yield(part, part_path) end diff --git a/app/models/integrations/chat_message/pipeline_message.rb b/app/models/integrations/chat_message/pipeline_message.rb index 88db40bea7f7e..815b260f6a3b7 100644 --- a/app/models/integrations/chat_message/pipeline_message.rb +++ b/app/models/integrations/chat_message/pipeline_message.rb @@ -96,7 +96,7 @@ def actually_failed_jobs(builds) failed_jobs = builds.select do |build| # Select jobs which doesn't have a successful retry - build[:status] == 'failed' && !succeeded_job_names.include?(build[:name]) + build[:status] == 'failed' && succeeded_job_names.exclude?(build[:name]) end failed_jobs.uniq { |job| job[:name] }.reverse diff --git a/app/models/integrations/field.rb b/app/models/integrations/field.rb index 53c8f5f623eb6..5931a34fca95e 100644 --- a/app/models/integrations/field.rb +++ b/app/models/integrations/field.rb @@ -28,7 +28,7 @@ def initialize(name:, integration_class:, type: 'text', api_only: false, **attri invalid_attributes = attributes.keys - ATTRIBUTES if invalid_attributes.present? raise ArgumentError, "Invalid attributes #{invalid_attributes.inspect}" - elsif !TYPES.include?(self[:type]) + elsif TYPES.exclude?(self[:type]) raise ArgumentError, "Invalid type #{self[:type].inspect}" end end diff --git a/app/models/label.rb b/app/models/label.rb index aa53c0e0f3fbd..8637df72fedea 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -285,7 +285,7 @@ def issues_count(user, params = {}) def label_format_reference(format = :id) raise StandardError, 'Unknown format' unless [:id, :name].include?(format) - if format == :name && !name.include?('"') + if format == :name && name.exclude?('"') %("#{name}") else id diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 6987bccadcbbd..cccf2c918b02c 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -733,7 +733,7 @@ def rebase_async(user_id, skip_ci: false) def merge_participants participants = [author] - if auto_merge_enabled? && !participants.include?(merge_user) + if auto_merge_enabled? && participants.exclude?(merge_user) participants << merge_user end diff --git a/app/models/milestone.rb b/app/models/milestone.rb index da07d8dd9fc7e..ba5b84add7d9b 100644 --- a/app/models/milestone.rb +++ b/app/models/milestone.rb @@ -263,7 +263,7 @@ def timebox_format_reference(format = :iid) raise ArgumentError, _('Cannot refer to a group milestone by an internal id!') end - if format == :name && !name.include?('"') + if format == :name && name.exclude?('"') %("#{name}") else iid diff --git a/app/services/todo_service.rb b/app/services/todo_service.rb index 06352d3621506..afb69149ceade 100644 --- a/app/services/todo_service.rb +++ b/app/services/todo_service.rb @@ -235,7 +235,7 @@ def create_todos(users, attributes) ).distinct_user_ids end - if users_multiple_todos.present? && !Todo::ACTIONS_MULTIPLE_ALLOWED.include?(attributes.fetch(:action)) + if users_multiple_todos.present? && Todo::ACTIONS_MULTIPLE_ALLOWED.exclude?(attributes.fetch(:action)) excluded_user_ids += pending_todos( users_multiple_todos, attributes.slice(:project_id, :target_id, :target_type, :commit_id, :discussion, :action) diff --git a/app/services/work_items/parent_links/create_service.rb b/app/services/work_items/parent_links/create_service.rb index e7906f1fcdd7e..81d90f5feab8d 100644 --- a/app/services/work_items/parent_links/create_service.rb +++ b/app/services/work_items/parent_links/create_service.rb @@ -30,7 +30,7 @@ def linkable_issuables(work_items) def linkable?(work_item) can?(current_user, :admin_parent_link, work_item) && - !previous_related_issuables.include?(work_item) + previous_related_issuables.exclude?(work_item) end def previous_related_issuables diff --git a/config/application.rb b/config/application.rb index 51818579ccfd9..597f19c7f3c5a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -525,7 +525,7 @@ class Application < Rails::Application LOOSE_APP_ASSETS = lambda do |logical_path, filename| filename.start_with?(*asset_roots) && - !['.js', '.css', '.md', '.vue', '.graphql', ''].include?(File.extname(logical_path)) + ['.js', '.css', '.md', '.vue', '.graphql', ''].exclude?(File.extname(logical_path)) end app.config.assets.precompile << LOOSE_APP_ASSETS diff --git a/config/initializers/1_settings.rb b/config/initializers/1_settings.rb index dd5770447c3ff..2fa354f552e6b 100644 --- a/config/initializers/1_settings.rb +++ b/config/initializers/1_settings.rb @@ -938,7 +938,7 @@ Settings.kerberos['https'] = Settings.gitlab.https if Settings.kerberos['https'].nil? Settings.kerberos['port'] ||= Settings.kerberos.https ? 8443 : 8088 - if Settings.kerberos['enabled'] && !Settings.omniauth.providers.map(&:name).include?('kerberos') + if Settings.kerberos['enabled'] && Settings.omniauth.providers.map(&:name).exclude?('kerberos') Settings.omniauth.providers << Settingslogic.new({ 'name' => 'kerberos' }) end end diff --git a/danger/roulette/Dangerfile b/danger/roulette/Dangerfile index ca5a671ef29b7..8f2d01390e146 100644 --- a/danger/roulette/Dangerfile +++ b/danger/roulette/Dangerfile @@ -96,7 +96,7 @@ categories = Set.new(changes.keys - [:unknown]) categories << :database if helper.mr_labels.include?('database') # Ensure to spin for UX reviewer when ~UX is applied (e.g. to review changes to the UI) except when it's from wider community contribution where we want to assign from the corresponding group -categories << :ux if helper.mr_labels.include?('UX') && !helper.mr_labels.include?('Community contribution') +categories << :ux if helper.mr_labels.include?('UX') && helper.mr_labels.exclude?('Community contribution') # Ensure to spin for Product Intelligence reviewer when ~"product intelligence::review pending" is applied categories << :product_intelligence if helper.mr_labels.include?("product intelligence::review pending") diff --git a/ee/app/finders/security/pipeline_vulnerabilities_finder.rb b/ee/app/finders/security/pipeline_vulnerabilities_finder.rb index d334150843a0e..0b8dff4afc938 100644 --- a/ee/app/finders/security/pipeline_vulnerabilities_finder.rb +++ b/ee/app/finders/security/pipeline_vulnerabilities_finder.rb @@ -133,7 +133,7 @@ def filter(findings) next if !include_dismissed? && dismissal_feedback?(finding) next unless confidence_levels.include?(finding.confidence) next unless severity_levels.include?(finding.severity) - next if scanners.present? && !scanners.include?(finding.scanner.external_id) + next if scanners.present? && scanners.exclude?(finding.scanner.external_id) finding end diff --git a/ee/app/models/ee/vulnerability.rb b/ee/app/models/ee/vulnerability.rb index c6ef829bfa9d9..9e7d004566391 100644 --- a/ee/app/models/ee/vulnerability.rb +++ b/ee/app/models/ee/vulnerability.rb @@ -309,7 +309,7 @@ def order_by(method) def with_keyset_order(arel_function, name, direction, tie_breaker_direction = nil) raise "unknown sort direction given: #{direction}" unless %i[asc desc].include?(direction) - if tie_breaker_direction.present? && !%i[asc desc].include?(tie_breaker_direction) + if tie_breaker_direction.present? && %i[asc desc].exclude?(tie_breaker_direction) raise "unknown tie breaker sort direction given: #{tie_breaker_direction}" end diff --git a/ee/app/services/epic_issues/create_service.rb b/ee/app/services/epic_issues/create_service.rb index ba1de8bdbc661..494535607d17d 100644 --- a/ee/app/services/epic_issues/create_service.rb +++ b/ee/app/services/epic_issues/create_service.rb @@ -50,7 +50,7 @@ def linkable_issuables(issues) def linkable_issue?(issue) issue.supports_epic? && can?(current_user, :admin_issue, issue.project) && - !previous_related_issuables.include?(issue) + previous_related_issuables.exclude?(issue) end def previous_related_issuables diff --git a/ee/app/services/security/ingestion/tasks/ingest_remediations.rb b/ee/app/services/security/ingestion/tasks/ingest_remediations.rb index 4024e2ffa6684..224a21125313e 100644 --- a/ee/app/services/security/ingestion/tasks/ingest_remediations.rb +++ b/ee/app/services/security/ingestion/tasks/ingest_remediations.rb @@ -97,7 +97,7 @@ def dissassociate_unfound_remediations def new_report_remediations existing_remediation_checksums = existing_remediations.map(&:checksum) - report_remediations.select { |remediation| !existing_remediation_checksums.include?(remediation.checksum) } + report_remediations.select { |remediation| existing_remediation_checksums.exclude?(remediation.checksum) } end def existing_remediations diff --git a/ee/app/services/security/security_orchestration_policies/validate_policy_service.rb b/ee/app/services/security/security_orchestration_policies/validate_policy_service.rb index d35ebef3fb6de..48c0236ae770d 100644 --- a/ee/app/services/security/security_orchestration_policies/validate_policy_service.rb +++ b/ee/app/services/security/security_orchestration_policies/validate_policy_service.rb @@ -30,7 +30,7 @@ def policy_disabled? def invalid_policy_type? return true if policy[:type].blank? - !Security::OrchestrationPolicyConfiguration::AVAILABLE_POLICY_TYPES.include?(policy_type) + Security::OrchestrationPolicyConfiguration::AVAILABLE_POLICY_TYPES.exclude?(policy_type) end def blank_name? diff --git a/lib/api/maven_packages.rb b/lib/api/maven_packages.rb index 638ce6dbedc9a..a82f53cf738de 100644 --- a/lib/api/maven_packages.rb +++ b/lib/api/maven_packages.rb @@ -107,7 +107,7 @@ def head_request_on_aws_file?(file, supports_direct_download) def fetch_package(file_name:, project: nil, group: nil) order_by_package_file = file_name.include?(::Packages::Maven::Metadata.filename) && - !params[:path].include?(::Packages::Maven::FindOrCreatePackageService::SNAPSHOT_TERM) + params[:path].exclude?(::Packages::Maven::FindOrCreatePackageService::SNAPSHOT_TERM) ::Packages::Maven::PackageFinder.new( current_user, diff --git a/lib/gitlab/background_migration/delete_orphans_approval_merge_request_rules.rb b/lib/gitlab/background_migration/delete_orphans_approval_merge_request_rules.rb index b75bda51ef37b..4b7b7d42c7717 100644 --- a/lib/gitlab/background_migration/delete_orphans_approval_merge_request_rules.rb +++ b/lib/gitlab/background_migration/delete_orphans_approval_merge_request_rules.rb @@ -4,7 +4,7 @@ module Gitlab module BackgroundMigration # Deletes orphans records whenever report_type equals to scan_finding (i.e., 4) class DeleteOrphansApprovalMergeRequestRules < BatchedMigrationJob - scope_to -> (relation) { relation.where(report_type: 4) } + scope_to ->(relation) { relation.where(report_type: 4) } operation_name :delete_all diff --git a/lib/gitlab/background_migration/legacy_upload_mover.rb b/lib/gitlab/background_migration/legacy_upload_mover.rb index 1879a6c54275a..2b2a7d65d0885 100644 --- a/lib/gitlab/background_migration/legacy_upload_mover.rb +++ b/lib/gitlab/background_migration/legacy_upload_mover.rb @@ -109,7 +109,7 @@ def move_legacy_diff_file old_path = upload.absolute_path old_path_sub = '-/system/note/attachment' - if !File.exist?(old_path) || !old_path.include?(old_path_sub) + if !File.exist?(old_path) || old_path.exclude?(old_path_sub) log_legacy_diff_note_problem(old_path) return false end diff --git a/lib/gitlab/ci/build/rules/rule/clause/exists.rb b/lib/gitlab/ci/build/rules/rule/clause/exists.rb index c55615bb83bdb..d3cc9337fd9ba 100644 --- a/lib/gitlab/ci/build/rules/rule/clause/exists.rb +++ b/lib/gitlab/ci/build/rules/rule/clause/exists.rb @@ -66,12 +66,12 @@ def pattern_match?(glob, path) # matches glob patterns that only match files in the top level directory def top_level_glob?(glob) - !glob.include?('/') && !glob.include?('**') + glob.exclude?('/') && glob.exclude?('**') end # matches glob patterns that have no metacharacters for File#fnmatch? def exact_glob?(glob) - !glob.include?('*') && !glob.include?('?') && !glob.include?('[') && !glob.include?('{') + glob.exclude?('*') && glob.exclude?('?') && glob.exclude?('[') && glob.exclude?('{') end end end diff --git a/lib/gitlab/ci/parsers/coverage/sax_document.rb b/lib/gitlab/ci/parsers/coverage/sax_document.rb index ddd9c80f5ea22..eafeaf9d505ad 100644 --- a/lib/gitlab/ci/parsers/coverage/sax_document.rb +++ b/lib/gitlab/ci/parsers/coverage/sax_document.rb @@ -63,7 +63,7 @@ def parse_line(line) end def parse_source(node) - return unless project_path && paths && !node.include?(GO_SOURCE_PATTERN) + return unless project_path && paths && node.exclude?(GO_SOURCE_PATTERN) source = build_source_path(node) self.sources << source if source.present? diff --git a/lib/gitlab/ci/queue/metrics.rb b/lib/gitlab/ci/queue/metrics.rb index 5cee73238ca63..0273a13e6f2ec 100644 --- a/lib/gitlab/ci/queue/metrics.rb +++ b/lib/gitlab/ci/queue/metrics.rb @@ -76,7 +76,7 @@ def increment_queue_operation(operation) def observe_queue_depth(queue, size) return unless Feature.enabled?(:gitlab_ci_builds_queuing_metrics) - if !Rails.env.production? && !QUEUE_DEPTH_HISTOGRAMS.include?(queue) + if !Rails.env.production? && QUEUE_DEPTH_HISTOGRAMS.exclude?(queue) raise ArgumentError, "unknown queue depth label: #{queue}" end @@ -113,7 +113,7 @@ def observe_queue_time(metric, runner_type) end def self.increment_queue_operation(operation) - if !Rails.env.production? && !OPERATION_COUNTERS.include?(operation) + if !Rails.env.production? && OPERATION_COUNTERS.exclude?(operation) raise ArgumentError, "unknown queue operation: #{operation}" end diff --git a/lib/gitlab/database/each_database.rb b/lib/gitlab/database/each_database.rb index 02f008abf8578..dcf2ab9dec888 100644 --- a/lib/gitlab/database/each_database.rb +++ b/lib/gitlab/database/each_database.rb @@ -52,7 +52,7 @@ def with_shared_model_connections(shared_model, selected_databases, &blk) next unless shared_model.limit_connection_names.include?(connection_name.to_sym) end - next if selected_databases.present? && !selected_databases.include?(connection_name.to_sym) + next if selected_databases.present? && selected_databases.exclude?(connection_name.to_sym) with_shared_connection(connection_model.connection, connection_name) do yield shared_model, connection_name @@ -63,7 +63,7 @@ def with_shared_model_connections(shared_model, selected_databases, &blk) def with_model_connection(model, selected_databases, &blk) connection_name = model.connection_db_config.name - return if selected_databases.present? && !selected_databases.include?(connection_name.to_sym) + return if selected_databases.present? && selected_databases.exclude?(connection_name.to_sym) with_shared_connection(model.connection, connection_name) do yield model, connection_name diff --git a/lib/gitlab/email/handler/create_issue_handler.rb b/lib/gitlab/email/handler/create_issue_handler.rb index e21a88c4e0d19..c41c93b6ec027 100644 --- a/lib/gitlab/email/handler/create_issue_handler.rb +++ b/lib/gitlab/email/handler/create_issue_handler.rb @@ -73,7 +73,7 @@ def create_issue end def can_handle_legacy_format? - project_path && !incoming_email_token.include?('+') && !mail_key.include?(Gitlab::Email::Common::UNSUBSCRIBE_SUFFIX_LEGACY) + project_path && incoming_email_token.exclude?('+') && mail_key.exclude?(Gitlab::Email::Common::UNSUBSCRIBE_SUFFIX_LEGACY) end end end diff --git a/lib/gitlab/email/handler/service_desk_handler.rb b/lib/gitlab/email/handler/service_desk_handler.rb index 06365296a76f5..8b436bb7a2967 100644 --- a/lib/gitlab/email/handler/service_desk_handler.rb +++ b/lib/gitlab/email/handler/service_desk_handler.rb @@ -186,7 +186,7 @@ def from_address end def can_handle_legacy_format? - project_path && project_path.include?('/') && !mail_key.include?('+') + project_path && project_path.include?('/') && mail_key.exclude?('+') end def author diff --git a/lib/gitlab/graphql/queries.rb b/lib/gitlab/graphql/queries.rb index cf06a2729d9b8..b97a003813d36 100644 --- a/lib/gitlab/graphql/queries.rb +++ b/lib/gitlab/graphql/queries.rb @@ -78,7 +78,7 @@ def print_operation_definition(op, indent: "") # remove variable definitions only used in skipped (client) fields vars = op.variables.reject do |v| - @skipped_arguments.include?(v.name) && !@printed_arguments.include?(v.name) + @skipped_arguments.include?(v.name) && @printed_arguments.exclude?(v.name) end if vars.any? @@ -109,7 +109,7 @@ def print_field(field, indent: '') end def print_fragment_definition(fragment_def, indent: "") - if skips? && @skipped_fragments.include?(fragment_def.name) && !@used_fragments.include?(fragment_def.name) + if skips? && @skipped_fragments.include?(fragment_def.name) && @used_fragments.exclude?(fragment_def.name) return '' end diff --git a/lib/gitlab/import_export/attributes_permitter.rb b/lib/gitlab/import_export/attributes_permitter.rb index 8c7a6c13246df..67c6a1f064904 100644 --- a/lib/gitlab/import_export/attributes_permitter.rb +++ b/lib/gitlab/import_export/attributes_permitter.rb @@ -67,7 +67,7 @@ def permitted_attributes_for(relation_sym) end def permitted_attributes_defined?(relation_sym) - !DISABLED_RELATION_NAMES.include?(relation_sym) && @attributes_finder.included_attributes.key?(relation_sym) + DISABLED_RELATION_NAMES.exclude?(relation_sym) && @attributes_finder.included_attributes.key?(relation_sym) end private diff --git a/lib/gitlab/search_results.rb b/lib/gitlab/search_results.rb index 37414f9e2b1f2..8658fa343e23e 100644 --- a/lib/gitlab/search_results.rb +++ b/lib/gitlab/search_results.rb @@ -144,7 +144,7 @@ def apply_sort(results, scope: nil) sort_by = ::Gitlab::Search::SortOptions.sort_and_direction(order_by, sort) # Reset sort to default if the chosen one is not supported by scope - sort_by = nil if SCOPE_ONLY_SORT[sort_by] && !SCOPE_ONLY_SORT[sort_by].include?(scope) + sort_by = nil if SCOPE_ONLY_SORT[sort_by] && SCOPE_ONLY_SORT[sort_by].exclude?(scope) case sort_by when :created_at_asc diff --git a/lib/gitlab/task_helpers.rb b/lib/gitlab/task_helpers.rb index 54db31ffd6ccc..38ad7712e739c 100644 --- a/lib/gitlab/task_helpers.rb +++ b/lib/gitlab/task_helpers.rb @@ -62,7 +62,7 @@ def prompt(message, choices = nil) begin print(message) answer = $stdin.gets.chomp - end while choices.present? && !choices.include?(answer) + end while choices.present? && choices.exclude?(answer) answer end diff --git a/lib/gitlab/url_blocker.rb b/lib/gitlab/url_blocker.rb index 1e447923a391f..f845ffb7ae63b 100644 --- a/lib/gitlab/url_blocker.rb +++ b/lib/gitlab/url_blocker.rb @@ -204,7 +204,7 @@ def validate_port(port, ports) end def validate_scheme(scheme, schemes) - if scheme.blank? || (schemes.any? && !schemes.include?(scheme)) + if scheme.blank? || (schemes.any? && schemes.exclude?(scheme)) raise BlockedUrlError, "Only allowed schemes are #{schemes.join(', ')}" end end diff --git a/lib/gitlab_edition.rb b/lib/gitlab_edition.rb index c3e5885249836..2a6685375340c 100644 --- a/lib/gitlab_edition.rb +++ b/lib/gitlab_edition.rb @@ -49,7 +49,7 @@ def self.ee? # The behavior needs to be synchronised with # config/helpers/is_ee_env.js root.join('ee/app/models/license.rb').exist? && - !%w[true 1].include?(ENV['FOSS_ONLY'].to_s) + !%w[true 1].include?(ENV['FOSS_ONLY'].to_s) # rubocop:disable Rails/NegateInclude end def self.jh? @@ -58,7 +58,7 @@ def self.jh? @is_jh = ee? && root.join('jh').exist? && - !%w[true 1].include?(ENV['EE_ONLY'].to_s) + !%w[true 1].include?(ENV['EE_ONLY'].to_s) # rubocop:disable Rails/NegateInclude end def self.ee diff --git a/qa/qa/page/merge_request/show.rb b/qa/qa/page/merge_request/show.rb index 329bf5f714360..21ad80b9acecd 100644 --- a/qa/qa/page/merge_request/show.rb +++ b/qa/qa/page/merge_request/show.rb @@ -366,7 +366,7 @@ def try_to_merge! # Revisit after merge page re-architect is done https://gitlab.com/gitlab-org/gitlab/-/issues/300042 # To remove page refresh logic if possible wait_until_ready_to_merge - wait_until { !find_element(:merge_button).text.include?('when pipeline succeeds') } + wait_until { !find_element(:merge_button).text.include?('when pipeline succeeds') } # rubocop:disable Rails/NegateInclude click_element(:merge_button) end diff --git a/qa/qa/runtime/ip_address.rb b/qa/qa/runtime/ip_address.rb index fcb6db750bb61..f9a0771ec7537 100644 --- a/qa/qa/runtime/ip_address.rb +++ b/qa/qa/runtime/ip_address.rb @@ -13,7 +13,7 @@ module IPAddress def fetch_current_ip_address # When running on CI against a live environment such as staging.gitlab.com, # we use the public facing IP address - non_test_host = !URI.parse(Scenario.gitlab_address).host.include?('.test') + non_test_host = !URI.parse(Scenario.gitlab_address).host.include?('.test') # rubocop:disable Rails/NegateInclude has_no_public_ip = Env.running_in_ci? || Env.use_public_ip_api? ip_address = if has_no_public_ip && non_test_host diff --git a/qa/qa/support/run.rb b/qa/qa/support/run.rb index 242293f9eefee..90fc6733105ff 100644 --- a/qa/qa/support/run.rb +++ b/qa/qa/support/run.rb @@ -13,7 +13,7 @@ module Run alias_method :to_s, :response def success? - exitstatus == 0 && !response.include?('Error encountered') + exitstatus == 0 && !response.include?('Error encountered') # rubocop:disable Rails/NegateInclude end def to_i diff --git a/qa/qa/tools/delete_test_users.rb b/qa/qa/tools/delete_test_users.rb index 30d3a82fb1b7c..847a2d19e62fe 100644 --- a/qa/qa/tools/delete_test_users.rb +++ b/qa/qa/tools/delete_test_users.rb @@ -22,7 +22,7 @@ def initialize(delete_before: (Date.today - 1).to_s, dry_run: 'false', exclude_u raise ArgumentError, "Please provide GITLAB_QA_ADMIN_ACCESS_TOKEN" unless ENV['GITLAB_QA_ADMIN_ACCESS_TOKEN'] @api_client = Runtime::API::Client.new(ENV['GITLAB_ADDRESS'], personal_access_token: ENV['GITLAB_QA_ADMIN_ACCESS_TOKEN']) - @dry_run = !FALSY_VALUES.include?(dry_run.to_s.downcase) + @dry_run = FALSY_VALUES.exclude?(dry_run.to_s.downcase) @delete_before = Date.parse(delete_before) @page_no = '1' @exclude_users = Array(exclude_users.to_s.split(',')) + EXCLUDE_USERS @@ -61,7 +61,7 @@ def fetch_test_users JSON.parse(response.body).select do |user| user['username'].start_with?('qa-user-', 'test-user-') \ && (user['name'] == 'QA Tests' || user['name'].start_with?('QA User')) \ - && !@exclude_users.include?(user['username']) \ + && @exclude_users.exclude?(user['username']) \ && Date.parse(user.fetch('created_at', Date.today.to_s)) < @delete_before end end diff --git a/rubocop/cop/gitlab/feature_available_usage.rb b/rubocop/cop/gitlab/feature_available_usage.rb index fcf4992a19d79..16f23bb06c45a 100644 --- a/rubocop/cop/gitlab/feature_available_usage.rb +++ b/rubocop/cop/gitlab/feature_available_usage.rb @@ -39,7 +39,7 @@ def on_send(node) 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.exclude?(feature_name(node)) 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/graphql/id_type.rb b/rubocop/cop/graphql/id_type.rb index eb677aa4507c8..a86c31de2d495 100644 --- a/rubocop/cop/graphql/id_type.rb +++ b/rubocop/cop/graphql/id_type.rb @@ -21,7 +21,7 @@ def on_send(node) private def does_not_match?(arg) - !WHITELISTED_ARGUMENTS.include?(arg) + WHITELISTED_ARGUMENTS.exclude?(arg) end end end diff --git a/rubocop/cop/migration/add_reference.rb b/rubocop/cop/migration/add_reference.rb index 02a0ef899b4ae..6f2648c8f9370 100644 --- a/rubocop/cop/migration/add_reference.rb +++ b/rubocop/cop/migration/add_reference.rb @@ -41,7 +41,7 @@ def on_def(node) private def existing_table?(new_tables, table) - !new_tables.include?(table) + new_tables.exclude?(table) 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 8d7c73b99a064..a770dac9794cd 100644 --- a/rubocop/cop/rspec/factory_bot/inline_association.rb +++ b/rubocop/cop/rspec/factory_bot/inline_association.rb @@ -99,7 +99,7 @@ def on_send(node) def inside_assocation_definition?(node) node.each_ancestor(:block).any? do |parent| name = association_definition(parent) - name && !SKIP_NAMES.include?(name) + name && SKIP_NAMES.exclude?(name) end end end diff --git a/scripts/lib/gitlab.rb b/scripts/lib/gitlab.rb index 556e2037edf14..a7ca6b7c5df44 100644 --- a/scripts/lib/gitlab.rb +++ b/scripts/lib/gitlab.rb @@ -4,10 +4,10 @@ module Gitlab module_function def ee? - File.exist?(File.expand_path('../../ee/app/models/license.rb', __dir__)) && !%w[true 1].include?(ENV['FOSS_ONLY'].to_s) + File.exist?(File.expand_path('../../ee/app/models/license.rb', __dir__)) && !%w[true 1].include?(ENV['FOSS_ONLY'].to_s) # rubocop:disable Rails/NegateInclude end def jh? - ee? && Dir.exist?(File.expand_path('../../jh', __dir__)) && !%w[true 1].include?(ENV['EE_ONLY'].to_s) + ee? && Dir.exist?(File.expand_path('../../jh', __dir__)) && !%w[true 1].include?(ENV['EE_ONLY'].to_s) # rubocop:disable Rails/NegateInclude end end diff --git a/scripts/static-analysis b/scripts/static-analysis index c6cf09e056be8..a346675099aa0 100755 --- a/scripts/static-analysis +++ b/scripts/static-analysis @@ -134,7 +134,7 @@ class StaticAnalysis def warning_count(static_analysis) static_analysis.warned_results - .count { |result| !ALLOWED_WARNINGS.include?(result.stderr.strip) } + .count { |result| !ALLOWED_WARNINGS.include?(result.stderr.strip) } # rubocop:disable Rails/NegateInclude end def tasks_to_run(node_total) diff --git a/spec/lib/container_registry/blob_spec.rb b/spec/lib/container_registry/blob_spec.rb index 676adc74be2c8..0f8b894cbd840 100644 --- a/spec/lib/container_registry/blob_spec.rb +++ b/spec/lib/container_registry/blob_spec.rb @@ -100,7 +100,7 @@ context 'for a valid address' do before do stub_request(:get, location) - .with { |request| !request.headers.include?('Authorization') } + .with { |request| request.headers.exclude?('Authorization') } .to_return( status: 200, headers: { 'Content-Type' => 'application/json' }, @@ -115,7 +115,7 @@ context 'for a relative address' do before do stub_request(:get, 'http://registry.gitlab/relative') - .with { |request| !request.headers.include?('Authorization') } + .with { |request| request.headers.exclude?('Authorization') } .to_return( status: 200, headers: { 'Content-Type' => 'application/json' }, diff --git a/spec/lib/container_registry/client_spec.rb b/spec/lib/container_registry/client_spec.rb index cb2da24b7123d..b3e454fdc42c2 100644 --- a/spec/lib/container_registry/client_spec.rb +++ b/spec/lib/container_registry/client_spec.rb @@ -180,7 +180,7 @@ # https://github.com/bblimke/webmock/blob/master/lib/webmock/matchers/hash_excluding_matcher.rb stub_request(:get, redirect_location) .with(headers: redirect_header) do |request| - !request.headers.include?('Authorization') + request.headers.exclude?('Authorization') end .to_return(status: 200, body: "Successfully redirected") end diff --git a/spec/lib/gitlab/metrics/dashboard/stages/metric_endpoint_inserter_spec.rb b/spec/lib/gitlab/metrics/dashboard/stages/metric_endpoint_inserter_spec.rb index bb3c8626d32d5..93bb01ce89546 100644 --- a/spec/lib/gitlab/metrics/dashboard/stages/metric_endpoint_inserter_spec.rb +++ b/spec/lib/gitlab/metrics/dashboard/stages/metric_endpoint_inserter_spec.rb @@ -27,7 +27,7 @@ transform! expect(all_metrics).to satisfy_all do |metric| - metric[:prometheus_endpoint_path].present? && !metric[:prometheus_endpoint_path].include?("\n") + metric[:prometheus_endpoint_path].present? && metric[:prometheus_endpoint_path].exclude?("\n") end end diff --git a/spec/lib/gitlab/metrics/subscribers/active_record_spec.rb b/spec/lib/gitlab/metrics/subscribers/active_record_spec.rb index 005c1ae2d0aa5..540231b8024b3 100644 --- a/spec/lib/gitlab/metrics/subscribers/active_record_spec.rb +++ b/spec/lib/gitlab/metrics/subscribers/active_record_spec.rb @@ -219,7 +219,7 @@ # Emulate Marginalia pre-pending comments def sql(query, comments: true) - if comments && !%w[BEGIN COMMIT].include?(query) + if comments && %w[BEGIN COMMIT].exclude?(query) "/*application:web,controller:badges,action:pipeline,correlation_id:01EYN39K9VMJC56Z7808N7RSRH*/ #{query}" else query @@ -284,7 +284,7 @@ def sql(query, comments: true) # Emulate Marginalia pre-pending comments def sql(query, comments: true) - if comments && !%w[BEGIN COMMIT].include?(query) + if comments && %w[BEGIN COMMIT].exclude?(query) "/*application:web,controller:badges,action:pipeline,correlation_id:01EYN39K9VMJC56Z7808N7RSRH*/ #{query}" else query diff --git a/spec/support/matchers/pushed_frontend_feature_flags_matcher.rb b/spec/support/matchers/pushed_frontend_feature_flags_matcher.rb index ecd174edec9be..25a472e2c2bdc 100644 --- a/spec/support/matchers/pushed_frontend_feature_flags_matcher.rb +++ b/spec/support/matchers/pushed_frontend_feature_flags_matcher.rb @@ -17,7 +17,7 @@ def html(actual) failure_message do |actual| missing = expected.select do |feature_flag_name, enabled| - !html(actual).include?(to_js(feature_flag_name, enabled)) + html(actual).exclude?(to_js(feature_flag_name, enabled)) end formatted_missing_flags = missing.map { |feature_flag_name, enabled| to_js(feature_flag_name, enabled) }.join("\n") diff --git a/spec/support/shared_contexts/markdown_golden_master_shared_examples.rb b/spec/support/shared_contexts/markdown_golden_master_shared_examples.rb index 72e23e6d5faa0..4d292d265a70e 100644 --- a/spec/support/shared_contexts/markdown_golden_master_shared_examples.rb +++ b/spec/support/shared_contexts/markdown_golden_master_shared_examples.rb @@ -44,7 +44,7 @@ if focused_markdown_examples_string = ENV['FOCUSED_MARKDOWN_EXAMPLES'] focused_markdown_examples = focused_markdown_examples_string.split(',').map(&:strip) || [] - markdown_examples.reject! { |markdown_example| !focused_markdown_examples.include?(markdown_example.fetch(:name)) } + markdown_examples.reject! { |markdown_example| focused_markdown_examples.exclude?(markdown_example.fetch(:name)) } end markdown_examples.each do |markdown_example| diff --git a/spec/uploaders/object_storage_spec.rb b/spec/uploaders/object_storage_spec.rb index a4f6116f7d719..9b48f1fdd8e7a 100644 --- a/spec/uploaders/object_storage_spec.rb +++ b/spec/uploaders/object_storage_spec.rb @@ -283,7 +283,7 @@ def dynamic_segment # We need to check the Host header not including the port because AWS does not accept stub_request(:get, %r{s3.amazonaws.com/#{uploader.path}}) - .with { |request| !request.headers['Host'].to_s.include?(':443') } + .with { |request| request.headers['Host'].to_s.exclude?(':443') } .to_return(status: 200, body: '') end diff --git a/tooling/danger/specs.rb b/tooling/danger/specs.rb index c7baf920314f9..32e8e40452061 100644 --- a/tooling/danger/specs.rb +++ b/tooling/danger/specs.rb @@ -132,7 +132,7 @@ def comment(comment_text) def find_line_number(file_lines, searched_line, exclude_indexes: []) _, index = file_lines.each_with_index.find do |file_line, index| - file_line == searched_line && !exclude_indexes.include?(index) + file_line == searched_line && exclude_indexes.exclude?(index) end index -- GitLab