Commit 2be85d6b authored by Doug Stull's avatar Doug Stull

Resolve Style/NumericPredicate for lib items

- enforce standards...
parent 935b0bc3
......@@ -980,59 +980,7 @@ Style/NumericPredicate:
- 'ee/app/workers/geo/registry_sync_worker.rb'
- 'ee/app/workers/geo/repository_shard_sync_worker.rb'
- 'ee/app/workers/geo/repository_verification/primary/shard_worker.rb'
- 'ee/lib/api/helpers/packages/conan/api_helpers.rb'
- 'ee/lib/ee/gitlab/auth/ldap/person.rb'
- 'ee/lib/ee/gitlab/background_migration/prune_orphaned_geo_events.rb'
- 'ee/lib/ee/gitlab/checks/push_rules/file_size_check.rb'
- 'ee/lib/ee/gitlab/geo_git_access.rb'
- 'ee/lib/gitlab/geo/fdw.rb'
- 'ee/lib/gitlab/geo/log_cursor/lease.rb'
- 'ee/lib/tasks/gitlab/elastic.rake'
- 'lib/api/entities/feature.rb'
- 'lib/api/helpers/pagination_strategies.rb'
- 'lib/backup/files.rb'
- 'lib/banzai/filter/gollum_tags_filter.rb'
- 'lib/bitbucket_server/paginator.rb'
- 'lib/declarative_policy/runner.rb'
- 'lib/gitlab/auth/ldap/adapter.rb'
- 'lib/gitlab/bare_repository_import/importer.rb'
- 'lib/gitlab/ci/config/external/context.rb'
- 'lib/gitlab/ci/reports/accessibility_reports_comparer.rb'
- 'lib/gitlab/cycle_analytics/summary/value.rb'
- 'lib/gitlab/cycle_analytics/summary_helper.rb'
- 'lib/gitlab/danger/teammate.rb'
- 'lib/gitlab/database.rb'
- 'lib/gitlab/database/connection_timer.rb'
- 'lib/gitlab/database/migration_helpers.rb'
- 'lib/gitlab/exclusive_lease.rb'
- 'lib/gitlab/exclusive_lease_helpers/sleeping_lock.rb'
- 'lib/gitlab/experimentation.rb'
- 'lib/gitlab/file_hook.rb'
- 'lib/gitlab/git/commit.rb'
- 'lib/gitlab/git/repository.rb'
- 'lib/gitlab/git/rugged_impl/blob.rb'
- 'lib/gitlab/gitaly_client.rb'
- 'lib/gitlab/github_import/user_finder.rb'
- 'lib/gitlab/hashed_storage/migrator.rb'
- 'lib/gitlab/import_export/command_line_util.rb'
- 'lib/gitlab/multi_collection_paginator.rb'
- 'lib/gitlab/polling_interval.rb'
- 'lib/gitlab/project_search_results.rb'
- 'lib/gitlab/seeder.rb'
- 'lib/gitlab/sidekiq_cluster.rb'
- 'lib/gitlab/sidekiq_daemon/memory_killer.rb'
- 'lib/gitlab/sidekiq_middleware/memory_killer.rb'
- 'lib/gitlab/sidekiq_status.rb'
- 'lib/gitlab/slash_commands/presenters/issue_show.rb'
- 'lib/gitlab/task_helpers.rb'
- 'lib/gitlab/untrusted_regexp.rb'
- 'lib/gitlab/utils.rb'
- 'lib/system_check/sidekiq_check.rb'
- 'lib/tasks/gitlab/gitaly.rake'
- 'lib/tasks/gitlab/snippets.rake'
- 'lib/tasks/gitlab/workhorse.rake'
- 'ee/app/models/ee/project.rb'
- 'lib/gitlab/usage_data/topology.rb'
# Offense count: 117
# Cop supports --auto-correct.
......
......@@ -46,7 +46,7 @@ module EE
::Gitlab::Auth::Ldap::DN.new(dn).each_pair { |name, value| dn_components << { name: name, value: value } }
dn_components
.reverse
.take_while { |rdn| rdn[:name].casecmp('DC').zero? } # Domain Component
.take_while { |rdn| rdn[:name].casecmp('DC') == 0 } # Domain Component
.map { |rdn| rdn[:value] }
.reverse
.join('.')
......
......@@ -45,7 +45,7 @@ module EE
def delete_batch_of_orphans!
deleted = where(id: orphans.limit(BATCH_SIZE)).delete_all
vacuum! if deleted.positive?
vacuum! if deleted > 0
deleted
end
......@@ -64,7 +64,7 @@ module EE
return if ::Gitlab::Database.read_only?
deleted_rows = prune_orphaned_rows(table_name)
table_name = next_table(table_name) if deleted_rows.zero?
table_name = next_table(table_name) if deleted_rows == 0
::BackgroundMigrationWorker.perform_in(RESCHEDULE_DELAY, self.class.name.demodulize, table_name) if table_name
end
......
......@@ -8,7 +8,7 @@ module EE
LOG_MESSAGE = "Checking if any files are larger than the allowed size...".freeze
def validate!
return if push_rule.nil? || push_rule.max_file_size.zero?
return if push_rule.nil? || push_rule.max_file_size == 0
logger.log_timed(LOG_MESSAGE) do
max_file_size = push_rule.max_file_size
......
......@@ -82,7 +82,7 @@ module EE
end
def current_replication_lag_message
return if ::Gitlab::Database.read_write? || current_replication_lag.zero?
return if ::Gitlab::Database.read_write? || current_replication_lag == 0
"Current replication lag: #{current_replication_lag} seconds"
end
......
......@@ -63,7 +63,7 @@ module Gitlab
private
def fdw_capable?
has_foreign_server? && has_foreign_schema? && foreign_schema_tables_count.positive?
has_foreign_server? && has_foreign_schema? && foreign_schema_tables_count > 0
rescue ::Geo::TrackingBase::SecondaryNotConfigured
false
end
......@@ -74,7 +74,7 @@ module Gitlab
def has_foreign_server?
::Geo::TrackingBase.connection.execute(
"SELECT 1 FROM pg_foreign_server"
).count.positive?
).count > 0
end
def has_foreign_schema?
......@@ -85,7 +85,7 @@ module Gitlab
WHERE schema_name='#{FOREIGN_SCHEMA}'
SQL
::Geo::TrackingBase.connection.execute(sql).count.positive?
::Geo::TrackingBase.connection.execute(sql).count > 0
end
end
......
......@@ -23,7 +23,7 @@ module Gitlab
def self.try_obtain_with_ttl
lease = exclusive_lease.try_obtain_with_ttl
unless lease[:ttl].zero? || exclusive_lease.same_uuid?
unless lease[:ttl] == 0 || exclusive_lease.same_uuid?
$stdout.puts lease_taken_message
logger.debug(lease_taken_message)
......
......@@ -108,7 +108,7 @@ namespace :gitlab do
task projects_not_indexed: :environment do
not_indexed = Project.where.not(id: IndexStatus.select(:project_id).distinct)
if not_indexed.count.zero?
if not_indexed.count == 0
puts 'All projects are currently indexed'.color(:green)
else
display_unindexed(not_indexed)
......
......@@ -10,7 +10,7 @@ module API
value = model.gate_values[gate.key]
# By default all gate values are populated. Only show relevant ones.
if (value.is_a?(Integer) && value.zero?) || (value.is_a?(Set) && value.empty?)
if (value.is_a?(Integer) && value == 0) || (value.is_a?(Set) && value.empty?)
next
end
......
......@@ -48,7 +48,7 @@ module API
end
def offset_limit_exceeded?(offset_limit)
offset_limit.positive? && params[:page] * params[:per_page] > offset_limit
offset_limit > 0 && params[:page] * params[:per_page] > offset_limit
end
end
end
......
......@@ -26,7 +26,7 @@ module Backup
cmd = %W(rsync -a --exclude=lost+found #{app_files_dir} #{Gitlab.config.backup.path})
output, status = Gitlab::Popen.popen(cmd)
unless status.zero?
unless status == 0
puts output
raise Backup::Error, 'Backup failed'
end
......
......@@ -82,7 +82,7 @@ module Banzai
def process_tag(tag)
parts = tag.split('|')
return if parts.size.zero?
return if parts.empty?
process_image_tag(parts) || process_page_link_tag(parts)
end
......
......@@ -36,7 +36,7 @@ module BitbucketServer
def over_limit?
return false unless @limit
@limit.positive? && @total >= @limit
@limit > 0 && @total >= @limit
end
def next_offset
......
......@@ -170,7 +170,7 @@ module DeclarativePolicy
lowest_score = score
end
break if lowest_score.zero?
break if lowest_score == 0
end
[remaining_steps, remaining_enablers, remaining_preventers].each do |set|
......
......@@ -54,7 +54,7 @@ module Gitlab
if results.nil?
response = ldap.get_operation_result
unless response.code.zero?
unless response.code == 0
Rails.logger.warn("LDAP search error: #{response.message}") # rubocop:disable Gitlab/RailsLogger
end
......
......@@ -123,7 +123,7 @@ module Gitlab
cmd = %W(#{Gitlab.config.git.bin_path} --git-dir=#{repo_path} bundle create #{bundle_path} --all)
output, status = Gitlab::Popen.popen(cmd)
raise output unless status.zero?
raise output unless status == 0
bundle_path
end
......
......@@ -54,7 +54,7 @@ module Gitlab
end
def execution_expired?
return false if execution_deadline.zero?
return false if execution_deadline == 0
current_monotonic_time > execution_deadline
end
......
......@@ -17,7 +17,7 @@ module Gitlab
end
def status
head_reports.errors_count.positive? ? STATUS_FAILED : STATUS_SUCCESS
head_reports.errors_count > 0 ? STATUS_FAILED : STATUS_SUCCESS
end
def existing_errors
......
......@@ -34,7 +34,7 @@ module Gitlab
end
def to_s
value.zero? ? '0' : value.to_s
value == 0 ? '0' : value.to_s
end
def to_i
......
......@@ -4,7 +4,7 @@ module Gitlab
module CycleAnalytics
module SummaryHelper
def frequency(count, from, to)
return Summary::Value::None.new if count.zero?
return Summary::Value::None.new if count == 0
freq = (count / days(from, to)).round(1)
......
......@@ -80,7 +80,7 @@ module Gitlab
def offset_diff_compared_to_author(author)
diff = floored_offset_hours - author.floored_offset_hours
return "same timezone as `@#{author.username}`" if diff.zero?
return "same timezone as `@#{author.username}`" if diff == 0
ahead_or_behind = diff < 0 ? 'behind' : 'ahead of'
pluralized_hours = pluralize(diff.abs, 'hour', 'hours')
......
......@@ -74,7 +74,7 @@ module Gitlab
# @deprecated
def self.postgresql?
adapter_name.casecmp('postgresql').zero?
adapter_name.casecmp('postgresql') == 0
end
def self.read_only?
......
......@@ -23,7 +23,7 @@ module Gitlab
end
def interval_with_randomization
interval + rand(RANDOMIZATION_INTERVAL) if interval.positive?
interval + rand(RANDOMIZATION_INTERVAL) if interval > 0
end
def current_clock_value
......
......@@ -1062,7 +1062,7 @@ into similar problems in the future (e.g. when new tables are created).
AND pg_class.relname = '#{table}'
SQL
connection.select_value(check_sql).positive?
connection.select_value(check_sql) > 0
end
# Adds a check constraint to a table
......
......@@ -102,7 +102,7 @@ module Gitlab
Gitlab::Redis::SharedState.with do |redis|
ttl = redis.ttl(@redis_shared_state_key)
ttl if ttl.positive?
ttl if ttl > 0
end
end
......
......@@ -39,7 +39,7 @@ module Gitlab
end
def first_attempt?
attempts.zero?
attempts == 0
end
def sleep_sec
......
......@@ -170,7 +170,7 @@ module Gitlab
Experiment = Struct.new(:key, :environment, :tracking_category, keyword_init: true) do
def enabled?
experiment_percentage.positive?
experiment_percentage > 0
end
def enabled_for_environment?
......
......@@ -27,7 +27,7 @@ module Gitlab
end
exit_status = result.status&.exitstatus
[exit_status.zero?, result.stderr]
[exit_status == 0, result.stderr]
rescue => e
[false, e.message]
end
......
......@@ -261,7 +261,7 @@ module Gitlab
end
def has_zero_stats?
stats.total.zero?
stats.total == 0
rescue
true
end
......@@ -423,7 +423,7 @@ module Gitlab
end
def message_from_gitaly_body
return @raw_commit.subject.dup if @raw_commit.body_size.zero?
return @raw_commit.subject.dup if @raw_commit.body_size == 0
return @raw_commit.body.dup if full_body_fetched_from_gitaly?
if @raw_commit.body_size > MAX_COMMIT_MESSAGE_DISPLAY_SIZE
......
......@@ -815,7 +815,7 @@ module Gitlab
def fsck
msg, status = gitaly_repository_client.fsck
raise GitError.new("Could not fsck repository: #{msg}") unless status.zero?
raise GitError.new("Could not fsck repository: #{msg}") unless status == 0
end
def create_from_bundle(bundle_path)
......
......@@ -48,7 +48,7 @@ module Gitlab
name: blob_entry[:name],
size: blob.size,
# Rugged::Blob#content is expensive; don't call it if we don't have to.
data: limit.zero? ? '' : blob.content(limit),
data: limit == 0 ? '' : blob.content(limit),
mode: blob_entry[:filemode].to_s(8),
path: path,
commit_id: sha,
......
......@@ -476,7 +476,7 @@ module Gitlab
return unless stack_counter
max = max_call_count
return if max.zero?
return if max == 0
stack_counter.select { |_, v| v == max }.keys
end
......
......@@ -161,7 +161,7 @@ module Gitlab
# The cache key may be empty to indicate a previously looked up user for
# which we couldn't find an ID.
[exists, number.positive? ? number : nil]
[exists, number > 0 ? number : nil]
end
end
end
......
......@@ -101,7 +101,7 @@ module Gitlab
def any_non_empty_queue?(*workers)
workers.any? do |worker|
!Sidekiq::Queue.new(worker.queue).size.zero?
Sidekiq::Queue.new(worker.queue).size != 0 # rubocop:disable Style/ZeroLengthPredicate
end
end
......
......@@ -47,8 +47,8 @@ module Gitlab
def execute(cmd)
output, status = Gitlab::Popen.popen(cmd)
@shared.error(Gitlab::ImportExport::Error.new(output.to_s)) unless status.zero? # rubocop:disable Gitlab/ModuleWithInstanceVariables
status.zero?
@shared.error(Gitlab::ImportExport::Error.new(output.to_s)) unless status == 0 # rubocop:disable Gitlab/ModuleWithInstanceVariables
status == 0
end
def git_bin_path
......
......@@ -34,7 +34,7 @@ module Gitlab
@second_collection_pages ||= Hash.new do |hash, page|
second_collection_page = page - first_collection_page_count
offset = if second_collection_page < 1 || first_collection_page_count.zero?
offset = if second_collection_page < 1 || first_collection_page_count == 0
0
else
per_page - first_collection_last_page_size
......
......@@ -20,7 +20,7 @@ module Gitlab
end
def self.polling_enabled?
!Gitlab::CurrentSettings.polling_interval_multiplier.zero?
Gitlab::CurrentSettings.polling_interval_multiplier != 0
end
end
end
......@@ -81,7 +81,7 @@ module Gitlab
counts = %i(limited_milestones_count limited_notes_count
limited_merge_requests_count limited_issues_count
limited_blobs_count wiki_blobs_count)
counts.all? { |count_method| public_send(count_method).zero? } # rubocop:disable GitlabSecurity/PublicSend
counts.all? { |count_method| public_send(count_method) == 0 } # rubocop:disable GitlabSecurity/PublicSend
end
private
......
......@@ -66,7 +66,7 @@ module Gitlab
estimated_minutes = (size.to_f / ESTIMATED_INSERT_PER_MINUTE).round
humanized_minutes = 'minute'.pluralize(estimated_minutes)
if estimated_minutes.zero?
if estimated_minutes == 0
"Rough estimated time: less than a minute ⏰"
else
"Rough estimated time: #{estimated_minutes} #{humanized_minutes} ⏰"
......
......@@ -126,7 +126,7 @@ module Gitlab
def self.concurrency(queues, min_concurrency, max_concurrency)
concurrency_from_queues = queues.length + 1
max = max_concurrency.positive? ? max_concurrency : concurrency_from_queues
max = max_concurrency > 0 ? max_concurrency : concurrency_from_queues
min = [min_concurrency, max].min
concurrency_from_queues.clamp(min, max)
......
......@@ -239,7 +239,7 @@ module Gitlab
memory_growth_kb = get_job_options(job, 'memory_killer_memory_growth_kb', 0).to_i
max_memory_growth_kb = get_job_options(job, 'memory_killer_max_memory_growth_kb', DEFAULT_MAX_MEMORY_GROWTH_KB).to_i
return 0 if memory_growth_kb.zero?
return 0 if memory_growth_kb == 0
time_elapsed = [Gitlab::Metrics::System.monotonic_time - job[:started_at], 0].max
[memory_growth_kb * time_elapsed, max_memory_growth_kb].min
......
......@@ -55,7 +55,7 @@ module Gitlab
def get_rss
output, status = Gitlab::Popen.popen(%W(ps -o rss= -p #{pid}), Rails.root.to_s)
return 0 unless status.zero?
return 0 unless status == 0
output.to_i
end
......
......@@ -50,7 +50,7 @@ module Gitlab
#
# Returns true or false.
def self.all_completed?(job_ids)
self.num_running(job_ids).zero?
self.num_running(job_ids) == 0
end
# Returns true if the given job is running or enqueued.
......
......@@ -23,14 +23,14 @@ module Gitlab
def text
message = ["**#{status_text(resource)}**"]
if resource.upvotes.zero? && resource.downvotes.zero? && resource.user_notes_count.zero?
if resource.upvotes == 0 && resource.downvotes == 0 && resource.user_notes_count == 0
return message.join
end
message << " · "
message << ":+1: #{resource.upvotes} " unless resource.upvotes.zero?
message << ":-1: #{resource.downvotes} " unless resource.downvotes.zero?
message << ":speech_balloon: #{resource.user_notes_count}" unless resource.user_notes_count.zero?
message << ":+1: #{resource.upvotes} " unless resource.upvotes == 0
message << ":-1: #{resource.downvotes} " unless resource.downvotes == 0
message << ":speech_balloon: #{resource.user_notes_count}" unless resource.user_notes_count == 0
message.join
end
......
......@@ -95,7 +95,7 @@ module Gitlab
def run_command!(command)
output, status = Gitlab::Popen.popen(command)
raise Gitlab::TaskFailedError.new(output) unless status.zero?
raise Gitlab::TaskFailedError.new(output) unless status == 0
output
end
......
......@@ -31,7 +31,7 @@ module Gitlab
def scan(text)
matches = scan_regexp.scan(text).to_a
matches.map!(&:first) if regexp.number_of_capturing_groups.zero?
matches.map!(&:first) if regexp.number_of_capturing_groups == 0
matches
end
......@@ -68,7 +68,7 @@ module Gitlab
# groups, so work around it
def scan_regexp
@scan_regexp ||=
if regexp.number_of_capturing_groups.zero?
if regexp.number_of_capturing_groups == 0
RE2::Regexp.new('(' + regexp.source + ')')
else
regexp
......
......@@ -213,7 +213,7 @@ module Gitlab
def normalize_localhost_address(instance)
ip_addr = IPAddr.new(instance)
is_local_ip = ip_addr.loopback? || ip_addr.to_i.zero?
is_local_ip = ip_addr.loopback? || ip_addr.to_i == 0
is_local_ip ? 'localhost' : instance
rescue IPAddr::InvalidAddressError
......
......@@ -50,7 +50,7 @@ module Gitlab
def ensure_utf8_size(str, bytes:)
raise ArgumentError, 'Empty string provided!' if str.empty?
raise ArgumentError, 'Negative string size provided!' if bytes.negative?
raise ArgumentError, 'Negative string size provided!' if bytes < 0
truncated = str.each_char.each_with_object(+'') do |char, object|
if object.bytesize + char.bytesize > bytes
......
......@@ -32,7 +32,7 @@ module SystemCheck
def only_one_sidekiq_running
process_count = sidekiq_process_count
return if process_count.zero?
return if process_count == 0
$stdout.print 'Number of Sidekiq processes ... '
......
......@@ -17,7 +17,7 @@ Usage: rake "gitlab:gitaly:install[/installation/dir,/storage/path]")
command = []
_, status = Gitlab::Popen.popen(%w[which gmake])
command << (status.zero? ? 'gmake' : 'make')
command << (status == 0 ? 'gmake' : 'make')
if Rails.env.test?
command.push(
......
......@@ -13,7 +13,7 @@ namespace :gitlab do
raise "Please supply the list of ids through the SNIPPET_IDS env var"
end
raise "Invalid limit value" if limit.zero?
raise "Invalid limit value" if limit == 0
if migration_running?
raise "There are already snippet migrations running. Please wait until they are finished."
......@@ -37,7 +37,7 @@ namespace :gitlab do
def parse_snippet_ids!
ids = ENV['SNIPPET_IDS'].delete(' ').split(',').map do |id|
id.to_i.tap do |value|
raise "Invalid id provided" if value.zero?
raise "Invalid id provided" if value == 0
end
end
......@@ -68,10 +68,10 @@ namespace :gitlab do
# bundle exec rake gitlab:snippets:list_non_migrated LIMIT=50
desc 'GitLab | Show non migrated snippets'
task list_non_migrated: :environment do
raise "Invalid limit value" if limit.zero?
raise "Invalid limit value" if limit == 0
non_migrated_count = non_migrated_snippets.count
if non_migrated_count.zero?
if non_migrated_count == 0
puts "All snippets have been successfully migrated"
else
puts "There are #{non_migrated_count} snippets that haven't been migrated. Showing a batch of ids of those snippets:\n"
......
......@@ -15,7 +15,7 @@ namespace :gitlab do
checkout_or_clone_version(version: version, repo: args.repo, target_dir: args.dir, clone_opts: %w[--depth 1])
_, status = Gitlab::Popen.popen(%w[which gmake])
command = status.zero? ? 'gmake' : 'make'
command = status == 0 ? 'gmake' : 'make'
Dir.chdir(args.dir) do
run_command!([command])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment