rubocop
rubocop copied to clipboard
Add new cop `Style/CollectionQuerying`
Adds new cop to identify places where expressions with Enumerable#count can be replaced with an appropriate predicate method.
The cop will register code such as:
x.count.positive?
x.count > 0
x.count != 0
x.count(&:foo?).positive?
x.count { |item| item.foo? }.positive?
as offenses, and autocorrect it to:
x.any?
x.any?(&:foo?)
x.any? { |item| item.foo? }
It does not register e.g. x.count(foo) as an offense because count and predicate methods function differently in that form (this has been documented in more detail in cop docs). It also doesn't register that form because it would yield false positives, e.g. for String#count (and that's not the case for forms without arguments, or with a block).
It recognizes the following combinations:
x.count.positive? # x.any?
x.count > 0 # x.any?
x.count != 0 # x.any?
x.count.zero? # x.none?
x.count == 0 # x.none?
x.count == 1 # x.one?
x.count > 1 # x.many? (only with activesupport)
Target Ruby and Rails versions
any?, none? and one? have been implemented on Enumerable since at least v2.3.
many? is registered as an offense only when ActiveSupportExtensionsEnabled config option is enabled since this method comes from Active Support. Enumerable#many? has been implemented in AS in its present form since v2.2.0.
Performance aspect
There's also a performance aspect to this cop, for example, x.count(&:foo?).positive? will iterate over every element in collection, while x.any?(&:foo?) will stop as soon as the first element returns a truthy value for #foo?:
Benchmark (block)
require 'benchmark/ips'
Benchmark.ips do |x|
collection = (1..100).to_a
x.report('count.positive?') do
collection.count { |element| element > 10 }.positive?
end
x.report('any?') do
collection.any? { |element| element > 10 }
end
x.compare!
end
ruby 3.4.4 (2025-05-14 revision a38531fd3f) +PRISM [x86_64-darwin23]
Warming up --------------------------------------
count.positive? 15.238k i/100ms
any? 121.718k i/100ms
Calculating -------------------------------------
count.positive? 149.776k (± 7.1%) i/s (6.68 μs/i) - 746.662k in 5.015937s
any? 1.271M (± 1.1%) i/s (786.62 ns/i) - 6.451M in 5.075191s
Comparison:
any?: 1271264.4 i/s
count.positive?: 149776.0 i/s - 8.49x slower
Benchmark (no arguments)
require 'benchmark/ips'
Benchmark.ips do |x|
collection = (1..100).to_a
x.report('count.positive?') do
collection.count.positive?
end
x.report('any?') do
collection.any?
end
x.compare!
end
ruby 3.4.4 (2025-05-14 revision a38531fd3f) +PRISM [x86_64-darwin23]
Warming up --------------------------------------
count.positive? 991.376k i/100ms
any? 1.262M i/100ms
Calculating -------------------------------------
count.positive? 9.772M (± 7.8%) i/s (102.33 ns/i) - 48.577M in 5.008627s
any? 12.547M (± 1.5%) i/s (79.70 ns/i) - 63.105M in 5.030579s
Comparison:
any?: 12547027.7 i/s
count.positive?: 9772235.7 i/s - 1.28x slower
Impact
I believe this cop will have a wide impact; this GH search shows at least 122k results (8 offenses have been caught in this codebase alone). Additionally I ran the cop on some known public projects (mastodon, dev.to, discourse, gitlabhq, openproject, canvas-lms) with the help of real-world-rails, and it caught 269 offenses (report in next comment).
Before submitting the PR make sure the following are checked:
- [x] The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
- [x] Wrote good commit messages.
- [ ] Commit message starts with
[Fix #issue-number](if the related issue exists). - [x] Feature branch is up-to-date with
master(if not - rebase it). - [x] Squashed related commits together.
- [x] Added tests.
- [x] Ran
bundle exec rake default. It executes all tests and runs RuboCop on its own code. - [x] Added an entry (file) to the changelog folder named
{change_type}_{change_description}.mdif the new code introduces user-observable changes. See changelog entry format for details.
real-world-rails report (GH wouldn't let me post it in PR description because of character limit):
Report
./apps/mastodon/app/controllers/api/v1/filters_controller.rb:31:166: C: [Correctable] Style/CollectionQuerying: Use many? instead.
raise Mastodon::ValidationError, I18n.t('filters.errors.deprecated_api_multiple_keywords') if @filter.custom_filter.changed? && @filter.custom_filter.keywords.count > 1
^^^^^^^^^
./apps/mastodon/app/policies/backup_policy.rb:7:78: C: [Correctable] Style/CollectionQuerying: Use none? instead.
user_signed_in? && current_user.backups.where(created_at: MIN_AGE.ago..).count.zero?
^^^^^^^^^^^
./apps/mastodon/lib/tasks/tests.rake:115:54: C: [Correctable] Style/CollectionQuerying: Use one? instead.
unless Identity.where(provider: 'foo', uid: 0).count == 1
^^^^^^^^^^
./apps/mastodon/lib/tasks/tests.rake:120:68: C: [Correctable] Style/CollectionQuerying: Use one? instead.
unless WebauthnCredential.where(user_id: 1, nickname: 'foo').count == 1
^^^^^^^^^^
./apps/mastodon/lib/tasks/tests.rake:125:89: C: [Correctable] Style/CollectionQuerying: Use one? instead.
unless AccountAlias.where(account_id: 1, uri: 'https://example.com/users/foobar').count == 1
^^^^^^^^^^
./apps/dev.to/app/controllers/concerns/api/articles_controller.rb:134:32: C: [Correctable] Style/CollectionQuerying: Use many? instead.
@articles = if @articles.count > 1
^^^^^^^^^
./apps/dev.to/app/controllers/stripe_active_cards_controller.rb:57:31: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if customer.subscriptions.count.positive?
^^^^^^^^^^^^^^^
./apps/dev.to/app/models/article.rb:672:35: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return if collection.articles.count.positive?
^^^^^^^^^^^^^^^
./apps/dev.to/app/models/organization.rb:122:30: C: [Correctable] Style/CollectionQuerying: Use one? instead.
organization_memberships.count == 1 && articles.count.zero? && credits.count.zero?
^^^^^^^^^^
./apps/dev.to/app/models/organization.rb:122:53: C: [Correctable] Style/CollectionQuerying: Use none? instead.
organization_memberships.count == 1 && articles.count.zero? && credits.count.zero?
^^^^^^^^^^^
./apps/dev.to/app/models/organization.rb:122:76: C: [Correctable] Style/CollectionQuerying: Use none? instead.
organization_memberships.count == 1 && articles.count.zero? && credits.count.zero?
^^^^^^^^^^^
./apps/dev.to/app/sanitizers/rendered_markdown_scrubber.rb:47:23: C: [Correctable] Style/CollectionQuerying: Use one? instead.
node.attributes.count == 1 &&
^^^^^^^^^^
./apps/dev.to/app/services/broadcasts/welcome_notification/generator.rb:125:40: C: [Correctable] Style/CollectionQuerying: Use many? instead.
user.cached_followed_tag_names.count > 1
^^^^^^^^^
./apps/dev.to/app/services/moderator/banish_user.rb:55:53: C: [Correctable] Style/CollectionQuerying: Use one? instead.
organization.destroy! if organization.users.count == 1
^^^^^^^^^^
./apps/dev.to/lib/data_update_scripts/20201208151516_set_onboarding_profile_fields_for_existing_forems.rb:4:26: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return unless User.count.positive?
^^^^^^^^^^^^^^^
./apps/discourse/app/controllers/admin/themes_controller.rb:27:26: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if upload.errors.count > 0
^^^^^^^^^
./apps/discourse/app/controllers/admin/watched_words_controller.rb:41:43: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if watched_word_group&.watched_words&.count == 1
^^^^^^^^^^
./apps/discourse/app/controllers/admin/web_hooks_controller.rb:153:59: C: [Correctable] Style/CollectionQuerying: Use none? instead.
raise Discourse::InvalidParameters if web_hook_events.count.zero?
^^^^^^^^^^^
./apps/discourse/app/controllers/invites_controller.rb:583:79: C: [Correctable] Style/CollectionQuerying: Use none? instead.
!SiteSetting.enable_local_logins && Discourse.enabled_auth_providers.count == 0 &&
^^^^^^^^^^
./apps/discourse/app/controllers/users/omniauth_callbacks_controller.rb:82:79: C: [Correctable] Style/CollectionQuerying: Use many? instead.
(SiteSetting.enable_local_logins || Discourse.enabled_authenticators.count > 1)
^^^^^^^^^
./apps/discourse/app/jobs/onceoff/migrate_censored_words.rb:7:14: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if row.count > 0
^^^^^^^^^
./apps/discourse/app/models/category.rb:1272:10: C: [Correctable] Style/CollectionQuerying: Use any? instead.
tags.count > 0 || tag_groups.count > 0
^^^^^^^^^
./apps/discourse/app/models/category.rb:1272:34: C: [Correctable] Style/CollectionQuerying: Use any? instead.
tags.count > 0 || tag_groups.count > 0
^^^^^^^^^
./apps/discourse/app/models/invite.rb:100:26: C: [Correctable] Style/CollectionQuerying: Use any? instead.
self.invited_users.count > 0
^^^^^^^^^
./apps/discourse/app/models/post.rb:554:11: C: [Correctable] Style/CollectionQuerying: Use any? instead.
flags.count != 0
^^^^^^^^^^
./apps/discourse/app/models/post_analyzer.rb:66:58: C: [Correctable] Style/CollectionQuerying: Use any? instead.
(Post.allowed_image_classes & dom_class.split).count > 0
^^^^^^^^^
./apps/discourse/app/models/quoted_post.rb:74:77: C: [Correctable] Style/CollectionQuerying: Use any? instead.
QuotedPost.where(post_id: post.id, quoted_post_id: reply_post_id).count > 0
^^^^^^^^^
./apps/discourse/app/models/screened_ip_address.rb:104:81: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return false if ScreenedIpAddress.where(action_type: actions[:allow_admin]).count == 0
^^^^^^^^^^
./apps/discourse/app/models/upload.rb:539:18: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if scope.count == 0
^^^^^^^^^^
./apps/discourse/app/services/inline_uploads.rb:26:27: C: [Correctable] Style/CollectionQuerying: Use one? instead.
node.children.count == 1 &&
^^^^^^^^^^
./apps/discourse/app/services/inline_uploads.rb:30:49: C: [Correctable] Style/CollectionQuerying: Use many? instead.
node.name == "a" && node.children.count > 1 &&
^^^^^^^^^
./apps/discourse/app/services/post_alerter.rb:861:77: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return post.topic.first_smtp_enabled_group if post.topic.allowed_groups.count == 1
^^^^^^^^^^
./apps/discourse/app/services/user_destroyer.rb:18:79: C: [Correctable] Style/CollectionQuerying: Use any? instead.
raise PostsExistError if !opts[:delete_posts] && user.posts.joins(:topic).count != 0
^^^^^^^^^^
./apps/discourse/app/services/user_merger.rb:59:21: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return if posts.count == 0
^^^^^^^^^^
./apps/discourse/config/initializers/006-ensure_login_hint.rb:9:46: C: [Correctable] Style/CollectionQuerying: Use none? instead.
User.where(admin: true).human_users.count == 0
^^^^^^^^^^
./apps/discourse/db/migrate/20131022045114_add_uncategorized_category.rb:7:40: C: [Correctable] Style/CollectionQuerying: Use any? instead.
name << SecureRandom.hex if result.count > 0
^^^^^^^^^
./apps/discourse/db/migrate/20170227211458_add_featured_topics_to_categories.rb:11:15: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if result.count > 0 && result[0]["value"].to_i > 0
^^^^^^^^^
./apps/discourse/db/migrate/20170308201552_add_subcategory_list_style_to_categories.rb:15:15: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if result.count > 0
^^^^^^^^^
./apps/discourse/db/migrate/20200409033412_create_bookmarks_from_post_action_bookmarks.rb:35:38: C: [Correctable] Style/CollectionQuerying: Use none? instead.
break if post_action_bookmarks.count.zero?
^^^^^^^^^^^
./apps/discourse/db/migrate/20210224162050_remove_emoji_one_from_emoji_set_site_setting.rb:6:22: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return if result.count.zero?
^^^^^^^^^^^
./apps/discourse/lib/autospec/simple_runner.rb:21:40: C: [Correctable] Style/CollectionQuerying: Use many? instead.
multiple_files = specs.split.count > 1 || specs == "spec" # Only parallelize multiple files
^^^^^^^^^
./apps/discourse/lib/backup_restore/uploads_restorer.rb:34:29: C: [Correctable] Style/CollectionQuerying: Use many? instead.
if upload_directories.count > 1
^^^^^^^^^
./apps/discourse/lib/content_security_policy/builder.rb:88:70: C: [Correctable] Style/CollectionQuerying: Use many? instead.
@directives[directive].delete(:none) if @directives[directive].count > 1
^^^^^^^^^
./apps/discourse/lib/discourse_tagging.rb:98:33: C: [Correctable] Style/CollectionQuerying: Use none? instead.
(category.tags.count == 0 && category.tag_groups.count == 0)
^^^^^^^^^^
./apps/discourse/lib/discourse_tagging.rb:98:67: C: [Correctable] Style/CollectionQuerying: Use none? instead.
(category.tags.count == 0 && category.tag_groups.count == 0)
^^^^^^^^^^
./apps/discourse/lib/discourse_tagging.rb:426:33: C: [Correctable] Style/CollectionQuerying: Use any? instead.
category ? (category.tags.count > 0 || category.tag_groups.count > 0) : false
^^^^^^^^^
./apps/discourse/lib/discourse_tagging.rb:426:66: C: [Correctable] Style/CollectionQuerying: Use any? instead.
category ? (category.tags.count > 0 || category.tag_groups.count > 0) : false
^^^^^^^^^
./apps/discourse/lib/email/receiver.rb:1654:91: C: [Correctable] Style/CollectionQuerying: Use none? instead.
UserDestroyer.new(Discourse.system_user).destroy(user, quiet: true) if user.posts.count == 0
^^^^^^^^^^
./apps/discourse/lib/file_store/s3_store.rb:424:19: C: [Correctable] Style/CollectionQuerying: Use any? instead.
while files.count > 0
^^^^^^^^^
./apps/discourse/lib/guardian.rb:544:7: C: [Correctable] Style/CollectionQuerying: Use none? instead.
).count == 0
^^^^^^^^^^
./apps/discourse/lib/guardian/post_guardian.rb:404:75: C: [Correctable] Style/CollectionQuerying: Use one? instead.
Category.post_create_allowed(self).where(id: topic.category.id).count == 1
^^^^^^^^^^
./apps/discourse/lib/guardian/topic_guardian.rb:8:29: C: [Correctable] Style/CollectionQuerying: Use many? instead.
topic.allowed_users.count > 1 && topic.user != target_user &&
^^^^^^^^^
./apps/discourse/lib/guardian/topic_guardian.rb:61:80: C: [Correctable] Style/CollectionQuerying: Use one? instead.
(!category || Category.topic_create_allowed(self).where(id: category_id).count == 1)
^^^^^^^^^^
./apps/discourse/lib/post_action_creator.rb:298:44: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if post_action && post_action.errors.count == 0
^^^^^^^^^^
./apps/discourse/lib/post_creator.rb:440:41: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return unless @post && @post.errors.count == 0 && @topic && @topic.category_id
^^^^^^^^^^
./apps/discourse/lib/tasks/posts.rake:552:33: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if missing[:post_uploads].count > 0
^^^^^^^^^
./apps/discourse/lib/tasks/site_settings.rake:86:20: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if dead_settings.count > 0
^^^^^^^^^
./apps/discourse/lib/tasks/uploads.rake:962:10: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if all.count > 0
^^^^^^^^^
./apps/discourse/lib/upload_recovery.rb:23:70: C: [Correctable] Style/CollectionQuerying: Use any? instead.
next if (Post.allowed_image_classes & dom_class.split).count > 0
^^^^^^^^^
./apps/discourse/plugins/automation/app/services/discourse_automation/user_badge_granted_handler.rb:13:91: C: [Correctable] Style/CollectionQuerying: Use many? instead.
return if only_first_grant && UserBadge.where(user_id: user_id, badge_id: badge_id).count > 1
^^^^^^^^^
./apps/discourse/plugins/automation/lib/discourse_automation/scriptable.rb:157:24: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if report.data.count > 0
^^^^^^^^^
./apps/discourse/plugins/chat/app/models/chat/channel_archive.rb:15:88: C: [Correctable] Style/CollectionQuerying: Use none? instead.
self.archived_messages >= self.total_messages && self.chat_channel.chat_messages.count.zero?
^^^^^^^^^^^
./apps/discourse/plugins/chat/app/serializers/chat/direct_message_serializer.rb:9:45: C: [Correctable] Style/CollectionQuerying: Use many? instead.
users = users - [scope.user] if users.count > 1
^^^^^^^^^
./apps/discourse/plugins/chat/db/migrate/20221104054957_backfill_channel_slugs.rb:11:24: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return if channels.count.zero?
^^^^^^^^^^^
./apps/discourse/script/bulk_import/vbulletin.rb:38:49: C: [Correctable] Style/CollectionQuerying: Use any? instead.
@has_post_thanks = mysql_query(<<-SQL).to_a.count > 0
^^^^^^^^^
./apps/discourse/script/bulk_import/vbulletin.rb:161:19: C: [Correctable] Style/CollectionQuerying: Use many? instead.
if user_ids.count > 1
^^^^^^^^^
./apps/discourse/script/bulk_import/vbulletin.rb:718:30: C: [Correctable] Style/CollectionQuerying: Use many? instead.
.select { |e, ids| ids.count > 1 }
^^^^^^^^^
./apps/discourse/script/import_scripts/lithium.rb:136:27: C: [Correctable] Style/CollectionQuerying: Use any? instead.
location = result.count > 0 ? result.first["nvalue"] : nil
^^^^^^^^^
./apps/discourse/script/import_scripts/lithium.rb:226:48: C: [Correctable] Style/CollectionQuerying: Use any? instead.
elsif attr[:profile].present? && profile.count > 0
^^^^^^^^^
./apps/discourse/script/import_scripts/lithium.rb:228:57: C: [Correctable] Style/CollectionQuerying: Use any? instead.
fields[name] = result.first["nvalue"] if result.count > 0
^^^^^^^^^
./apps/discourse/script/import_scripts/lithium.rb:372:14: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if roles.count > 0
^^^^^^^^^
./apps/discourse/script/import_scripts/lithium.rb:444:27: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if result.count > 0
^^^^^^^^^
./apps/discourse/script/import_scripts/muut.rb:116:60: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if thread["replies"].present? && thread["replies"].count > 0
^^^^^^^^^
./apps/discourse/script/import_scripts/vanilla.rb:148:31: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if first_level_categories.count > 0
^^^^^^^^^
./apps/discourse/script/import_scripts/vanilla.rb:154:34: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if second_level_categories.count > 0
^^^^^^^^^
./apps/discourse/script/import_scripts/vbulletin.rb:192:53: C: [Correctable] Style/CollectionQuerying: Use any? instead.
next if GroupUser.where(group_id: group.id).count > 0
^^^^^^^^^
./apps/discourse/spec/integrity/coding_style_spec.rb:13:9: C: [Correctable] Style/CollectionQuerying: Use any? instead.
lines.count > 0 ? file : nil
^^^^^^^^^
./apps/discourse/spec/system/login_spec.rb:14:58: C: [Correctable] Style/CollectionQuerying: Use any? instead.
wait_for(timeout: 5) { ActionMailer::Base.deliveries.count != 0 }
^^^^^^^^^^
./apps/gitlabhq/app/controllers/concerns/check_initial_setup.rb:11:39: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return false unless User.limit(2).count == 1 # Count as much 2 to know if we have exactly one
^^^^^^^^^^
./apps/gitlabhq/app/controllers/concerns/onboarding/status.rb:14:15: C: [Correctable] Style/CollectionQuerying: Use one? instead.
members.count == 1
^^^^^^^^^^
./apps/gitlabhq/app/controllers/projects/environments_controller.rb:123:47: C: [Correctable] Style/CollectionQuerying: Use one? instead.
job = stop_actions.first if stop_actions&.count == 1
^^^^^^^^^^
./apps/gitlabhq/app/controllers/projects/issues_controller.rb:165:41: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if service.discussions_to_resolve.count(&:resolved?) > 0
^^^^^^^^^^^^^^^^^^^^^^
./apps/gitlabhq/app/finders/deployments_finder.rb:163:49: C: [Correctable] Style/CollectionQuerying: Use one? instead.
params[:status].present? && params[:status].count == 1 && params[:status].first.to_s == 'success'
^^^^^^^^^^
./apps/gitlabhq/app/helpers/users/group_callouts_helper.rb:32:60: C: [Correctable] Style/CollectionQuerying: Use many? instead.
group.member_count > 1 || group.members_with_parents.count > 1
^^^^^^^^^
./apps/gitlabhq/app/models/ci/runner.rb:388:23: C: [Correctable] Style/CollectionQuerying: Use one? instead.
runner_projects.count == 1
^^^^^^^^^^
./apps/gitlabhq/app/models/concerns/id_in_ordered.rb:12:36: C: [Correctable] Style/CollectionQuerying: Use many? instead.
return id_in(ids) unless ids.count > 1
^^^^^^^^^
./apps/gitlabhq/app/models/concerns/issuable.rb:197:17: C: [Correctable] Style/CollectionQuerying: Use many? instead.
assignees.count > 1
^^^^^^^^^
./apps/gitlabhq/app/models/concerns/spammable.rb:68:33: C: [Correctable] Style/CollectionQuerying: Use many? instead.
return false if self.errors.count > 1 # captcha should not be rendered if are still other errors
^^^^^^^^^
./apps/gitlabhq/app/models/fork_network_member.rb:20:63: C: [Correctable] Style/CollectionQuerying: Use none? instead.
fork_network.destroy if fork_network.fork_network_members.count == 0
^^^^^^^^^^
./apps/gitlabhq/app/models/integration.rb:644:15: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if events.count == 1
^^^^^^^^^^
./apps/gitlabhq/app/models/milestone.rb:199:30: C: [Correctable] Style/CollectionQuerying: Use none? instead.
active? && issues.opened.count == 0
^^^^^^^^^^
./apps/gitlabhq/app/models/network/graph.rb:259:47: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return leaves if commit.parents(@map).count == 0
^^^^^^^^^^
./apps/gitlabhq/app/models/user.rb:1035:34: C: [Correctable] Style/CollectionQuerying: Use one? instead.
User.non_internal.limit(2).count == 1
^^^^^^^^^^
./apps/gitlabhq/app/presenters/project_presenter.rb:413:33: C: [Correctable] Style/CollectionQuerying: Use one? instead.
cluster_link = clusters.count == 1 ? project_cluster_path(project, clusters.first) : project_clusters_path(project)
^^^^^^^^^^
./apps/gitlabhq/app/services/authorized_project_update/find_records_due_for_refresh_service.rb:94:93: C: [Correctable] Style/CollectionQuerying: Use many? instead.
.select { |project_id, authorizations| authorizations.count > 1 }
^^^^^^^^^
./apps/gitlabhq/app/services/ci/runners/set_runner_associated_projects_service.rb:53:59: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return error_responses.first if error_responses.count == 1
^^^^^^^^^^
./apps/gitlabhq/app/services/merge_requests/add_context_service.rb:53:20: C: [Correctable] Style/CollectionQuerying: Use any? instead.
commit_ids.count { |commit_id| existing_oid.start_with?(commit_id) } > 0
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
./apps/gitlabhq/app/services/merge_requests/build_service.rb:272:19: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if commits&.count == 1
^^^^^^^^^^
./apps/gitlabhq/app/services/projects/auto_devops/disable_service.rb:26:48: C: [Correctable] Style/CollectionQuerying: Use none? instead.
auto_devops_pipelines.success.limit(1).count == 0 &&
^^^^^^^^^^
./apps/gitlabhq/gems/gitlab-housekeeper/lib/gitlab/housekeeper/keeps/rubocop_fixer.rb:64:35: C: [Correctable] Style/CollectionQuerying: Use one? instead.
next unless data.keys.count == 1
^^^^^^^^^^
./apps/gitlabhq/keeps/overdue_finalize_background_migration.rb:187:28: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return unless result.count == 1
^^^^^^^^^^
./apps/gitlabhq/lib/api/ci/runners.rb:80:96: C: [Correctable] Style/CollectionQuerying: Use many? instead.
forbidden!("Runner associated with more than one project") if runner.runner_projects.count > 1
^^^^^^^^^
./apps/gitlabhq/lib/api/ci/runners.rb:366:129: C: [Correctable] Style/CollectionQuerying: Use one? instead.
forbidden!("Only one project associated with the runner. Please remove the runner instead") if runner.runner_projects.count == 1
^^^^^^^^^^
./apps/gitlabhq/lib/gitlab/ci/config/interpolation/template.rb:86:20: C: [Correctable] Style/CollectionQuerying: Use many? instead.
blocks.count > 1 || node.length != blocks.first.length
^^^^^^^^^
./apps/gitlabhq/lib/gitlab/ci/config/yaml/documents.rb:35:23: C: [Correctable] Style/CollectionQuerying: Use many? instead.
documents.count > 1 && parsed_first_document.key?(:spec)
^^^^^^^^^
./apps/gitlabhq/lib/gitlab/ci/config/yaml/documents.rb:39:36: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return {} if documents.count == 0
^^^^^^^^^^
./apps/gitlabhq/lib/gitlab/ci/pipeline/expression/parser.rb:36:77: C: [Correctable] Style/CollectionQuerying: Use many? instead.
raise ParseError, 'Unreachable nodes in parse tree' if results.count > 1
^^^^^^^^^
./apps/gitlabhq/lib/gitlab/ci/yaml_processor.rb:128:38: C: [Correctable] Style/CollectionQuerying: Use many? instead.
.select { |_, items| items.count > 1 }
^^^^^^^^^
./apps/gitlabhq/lib/gitlab/database/query_analyzers/prevent_set_operator_mismatch/common_table_expressions.rb:63:29: C: [Correctable] Style/CollectionQuerying: Use many? instead.
if final_type.count > 1
^^^^^^^^^
./apps/gitlabhq/lib/gitlab/database/query_analyzers/prevent_set_operator_mismatch/select_stmt.rb:58:45: C: [Correctable] Style/CollectionQuerying: Use many? instead.
types << Type::INVALID if types.count > 1
^^^^^^^^^
./apps/gitlabhq/lib/gitlab/gitaly_client/analysis_service.rb:45:35: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return [] if request_enum.count == 0
^^^^^^^^^^
./apps/gitlabhq/lib/gitlab/legacy_github_import/importer.rb:195:36: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return unless raw[:labels].count > 0
^^^^^^^^^
./apps/gitlabhq/lib/gitlab/middleware/multipart.rb:48:76: C: [Correctable] Style/CollectionQuerying: Use one? instead.
raise "unexpected field: #{field.inspect}" unless parsed_field.count == 1
^^^^^^^^^^
./apps/gitlabhq/lib/gitlab/middleware/multipart.rb:71:53: C: [Correctable] Style/CollectionQuerying: Use one? instead.
unless hash_path.is_a?(Hash) && hash_path.count == 1
^^^^^^^^^^
./apps/gitlabhq/lib/gitlab/quick_actions/issue_actions.rb:58:48: C: [Correctable] Style/CollectionQuerying: Use one? instead.
quick_action_target.project.boards.count == 1
^^^^^^^^^^
./apps/gitlabhq/lib/gitlab/sidekiq_config.rb:127:64: C: [Correctable] Style/CollectionQuerying: Use one? instead.
.select { |workers| workers.map(&:get_weight).uniq.count == 1 }
^^^^^^^^^^
./apps/gitlabhq/lib/gitlab/usage/metrics/instrumentations/redis_hll_metric.rb:43:45: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return uniques.first if uniques.count == 1
^^^^^^^^^^
./apps/gitlabhq/lib/gitlab/usage_data_counters/quick_action_activity_unique_counter.rb:67:19: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if args.count == 1 && args.first == 'me'
^^^^^^^^^^
./apps/gitlabhq/lib/gitlab/usage_data_counters/quick_action_activity_unique_counter.rb:107:19: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if args.count == 1
^^^^^^^^^^
./apps/gitlabhq/qa/qa/support/page_error_checker.rb:40:36: C: [Correctable] Style/CollectionQuerying: Use one? instead.
"There #{severe_errors.count == 1 ? 'was' : 'were'} #{severe_errors.count} "\
^^^^^^^^^^
./apps/gitlabhq/qa/qa/support/page_error_checker.rb:41:50: C: [Correctable] Style/CollectionQuerying: Use one? instead.
"SEVERE level error#{severe_errors.count == 1 ? '' : 's'}:\n\n#{error_report_for(severe_errors)}"
^^^^^^^^^^
./apps/gitlabhq/scripts/feature_flags/used-feature-flags:95:21: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if additional_flags.count > 0
^^^^^^^^^
./apps/gitlabhq/scripts/feature_flags/used-feature-flags:108:17: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if unused_flags.count > 0
^^^^^^^^^
./apps/gitlabhq/scripts/internal_events/cli/helpers/event_options.rb:59:16: C: [Correctable] Style/CollectionQuerying: Use many? instead.
events.count { |event| action == event.action } > 1
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
./apps/gitlabhq/scripts/internal_events/cli/usage_viewer.rb:116:44: C: [Correctable] Style/CollectionQuerying: Use many? instead.
args = "\n #{args}\n" if args.lines.count > 1
^^^^^^^^^
./apps/gitlabhq/scripts/qa/quarantine-types-check:23:30: C: [Correctable] Style/CollectionQuerying: Use many? instead.
unless data_hash['examples'].count > 1
^^^^^^^^^
./apps/gitlabhq/scripts/qa/testcases-check:56:46: C: [Correctable] Style/CollectionQuerying: Use many? instead.
duplicates = testcase_list.select { |k, v| v.count > 1 }
^^^^^^^^^
./apps/gitlabhq/spec/db/schema_spec.rb:431:37: C: [Correctable] Style/CollectionQuerying: Use one? instead.
next if primary_key_columns.count == 1
^^^^^^^^^^
./apps/gitlabhq/spec/lib/gitlab/database/dictionary_spec.rb:19:40: C: [Correctable] Style/CollectionQuerying: Use many? instead.
.select { |_, schemas| schemas.count > 1 }
^^^^^^^^^
./apps/gitlabhq/spec/lib/gitlab/usage_data_counters/code_review_events_spec.rb:27:27: C: [Correctable] Style/CollectionQuerying: Use one? instead.
definition.events.count == 1
^^^^^^^^^^
./apps/gitlabhq/spec/lib/gitlab/usage_data_counters/code_review_events_spec.rb:44:25: C: [Correctable] Style/CollectionQuerying: Use many? instead.
definition.events.count > 1
^^^^^^^^^
./apps/gitlabhq/spec/services/projects/container_repository/third_party/cleanup_tags_service_spec.rb:323:33: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return if selected_tags.count.zero?
^^^^^^^^^^^
./apps/gitlabhq/spec/support/helpers/sharding_key_spec_helpers.rb:16:12: C: [Correctable] Style/CollectionQuerying: Use any? instead.
result.count > 0
^^^^^^^^^
./apps/gitlabhq/spec/support/helpers/sharding_key_spec_helpers.rb:37:12: C: [Correctable] Style/CollectionQuerying: Use any? instead.
result.count > 0
^^^^^^^^^
./apps/gitlabhq/spec/support/helpers/sharding_key_spec_helpers.rb:57:12: C: [Correctable] Style/CollectionQuerying: Use any? instead.
result.count > 0
^^^^^^^^^
./apps/gitlabhq/spec/support/helpers/sharding_key_spec_helpers.rb:90:12: C: [Correctable] Style/CollectionQuerying: Use any? instead.
result.count > 0
^^^^^^^^^
./apps/gitlabhq/spec/support/matchers/query_matcher.rb:11:16: C: [Correctable] Style/CollectionQuerying: Use any? instead.
@counter.count > 0
^^^^^^^^^
./apps/gitlabhq/spec/support/shared_examples/quick_actions/issuable/issuable_quick_actions_shared_examples.rb:55:33: C: [Correctable] Style/CollectionQuerying: Use one? instead.
expect(noteable.todos.count == 1).to eq(can_use_quick_action)
^^^^^^^^^^
./apps/openproject/app/contracts/shares/base_contract.rb:53:72: C: [Correctable] Style/CollectionQuerying: Use many? instead.
errors.add(:roles, :more_than_one) if active_non_inherited_roles.count > 1
^^^^^^^^^
./apps/openproject/app/contracts/user_preferences/params_contract.rb:48:31: C: [Correctable] Style/CollectionQuerying: Use many? instead.
if global_notifications.count > 1
^^^^^^^^^
./apps/openproject/app/controllers/admin_controller.rb:50:20: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if @menu_nodes.count == 1
^^^^^^^^^^
./apps/openproject/app/helpers/user_consent_helper.rb:58:29: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if Setting.consent_info.count == 0
^^^^^^^^^^
./apps/openproject/app/models/custom_option.rb:48:67: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return if CustomOption.where(custom_field_id:).where.not(id:).count > 0
^^^^^^^^^
./apps/openproject/app/models/journable/historic_active_record_relation.rb:300:31: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if relation.select_values.count == 0
^^^^^^^^^^
./apps/openproject/app/models/journable/historic_active_record_relation.rb:302:34: C: [Correctable] Style/CollectionQuerying: Use one? instead.
elsif relation.select_values.count == 1 and
^^^^^^^^^^
./apps/openproject/app/models/queries/filters/strategies/boolean_list.rb:54:14: C: [Correctable] Style/CollectionQuerying: Use many? instead.
values.count(&:present?) > 1
^^^^^^^^^^^^^^^^^^^^^
./apps/openproject/app/models/queries/filters/strategies/relation.rb:57:14: C: [Correctable] Style/CollectionQuerying: Use many? instead.
values.count(&:present?) > 1
^^^^^^^^^^^^^^^^^^^^^
./apps/openproject/app/models/work_package.rb:200:84: C: [Correctable] Style/CollectionQuerying: Use any? instead.
TimeEntry.on_work_packages(work_packages).count > 0
^^^^^^^^^
./apps/openproject/app/models/work_packages/costs.rb:42:104: C: [Correctable] Style/CollectionQuerying: Use any? instead.
->(work_packages) { CostEntry.on_work_packages(work_packages).count.positive? },
^^^^^^^^^^^^^^^
./apps/openproject/app/seeders/demo_data/group_seeder.rb:39:13: C: [Correctable] Style/CollectionQuerying: Use none? instead.
Group.count.zero?
^^^^^^^^^^^
./apps/openproject/app/seeders/demo_data/overview_seeder.rb:28:23: C: [Correctable] Style/CollectionQuerying: Use none? instead.
Grids::Overview.count.zero? && demo_projects_exist?
^^^^^^^^^^^
./apps/openproject/app/seeders/demo_data/projects_seeder.rb:47:15: C: [Correctable] Style/CollectionQuerying: Use none? instead.
Project.count.zero?
^^^^^^^^^^^
./apps/openproject/app/seeders/development_data/custom_fields_seeder.rb:102:48: C: [Correctable] Style/CollectionQuerying: Use none? instead.
CustomField.where("name LIKE 'CF DEV%'").count == 0
^^^^^^^^^^
./apps/openproject/app/seeders/development_data/projects_seeder.rb:50:78: C: [Correctable] Style/CollectionQuerying: Use none? instead.
recent_installation? && Project.where(identifier: project_identifiers).count == 0
^^^^^^^^^^
./apps/openproject/app/services/ldap/base_service.rb:107:18: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if entries.count == 0
^^^^^^^^^^
./apps/openproject/app/services/ldap/base_service.rb:112:18: C: [Correctable] Style/CollectionQuerying: Use many? instead.
if entries.count > 1
^^^^^^^^^
./apps/openproject/db/migrate/20190920102446_clean_custom_values.rb:37:19: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if invalid_cv.count > 0
^^^^^^^^^
./apps/openproject/lib/api/errors/multiple_errors.rb:37:39: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return errors.first if errors.count == 1
^^^^^^^^^^
./apps/openproject/lib/open_project/scm/adapters/git.rb:102:54: C: [Correctable] Style/CollectionQuerying: Use any? instead.
raise Exceptions::SCMEmpty unless branches.count > 0
^^^^^^^^^
./apps/openproject/lib/tasks/attachment_migrations.rake:67:20: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if Journal.count > 0
^^^^^^^^^
./apps/openproject/modules/backlogs/spec/models/burndown_spec.rb:36:111: C: [Correctable] Style/CollectionQuerying: Use many? instead.
story.journals[-2].update_columns(validity_period: story.journals[-2].created_at...day) if story.journals.count > 1
^^^^^^^^^
./apps/openproject/modules/bim/db/migrate/20201105154216_seed_custom_style_with_bim_theme.rb:44:25: C: [Correctable] Style/CollectionQuerying: Use none? instead.
(DesignColor.count == 0 &&
^^^^^^^^^^
./apps/openproject/modules/bim/db/migrate/20210521080035_update_xkt_to_version8.rb:47:17: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if IfcModel.count.zero?
^^^^^^^^^^^
./apps/openproject/modules/meeting/app/components/meeting_sections/show_component.rb:71:74: C: [Correctable] Style/CollectionQuerying: Use many? instead.
@force_wrapper || !@meeting_section.untitled? || @meeting.sections.count > 1
^^^^^^^^^
./apps/openproject/modules/meeting/app/controllers/concerns/meetings/agenda_component_streams.rb:205:56: C: [Correctable] Style/CollectionQuerying: Use one? instead.
elsif meeting_agenda_item.meeting.agenda_items.count == 1
^^^^^^^^^^
./apps/openproject/modules/meeting/app/controllers/concerns/meetings/agenda_component_streams.rb:281:41: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if current_section.agenda_items.count == 1
^^^^^^^^^^
./apps/openproject/modules/meeting/app/controllers/meeting_sections_controller.rb:55:117: C: [Correctable] Style/CollectionQuerying: Use many? instead.
update_section_header_via_turbo_stream(meeting_section: @meeting.sections.last(2).first) if @meeting.sections.count > 1
^^^^^^^^^
./apps/openproject/modules/reporting/app/controllers/cost_reports_controller.rb:340:24: C: [Correctable] Style/CollectionQuerying: Use any? instead.
t.cost_entries.count > 0
^^^^^^^^^
./apps/openproject/modules/reporting/lib/widget/filters/operators.rb:33:58: C: [Correctable] Style/CollectionQuerying: Use one? instead.
hide_select_box = filter_class.available_operators.count == 1 || filter_class.heavy?
^^^^^^^^^^
./apps/openproject/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb:132:25: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return [] if path.count == 0
^^^^^^^^^^
./apps/openproject/spec/support/components/wysiwyg/wysiwyg_editor.rb:83:19: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if images.count > 0
^^^^^^^^^
./apps/openproject/spec/support/rspec_cleanup.rb:21:21: C: [Correctable] Style/CollectionQuerying: Use none? instead.
next if cls.count == 0
^^^^^^^^^^
./apps/canvas-lms/app/controllers/assignments_controller.rb:77:56: C: [Correctable] Style/CollectionQuerying: Use any? instead.
HAS_ASSIGNMENTS: @context.active_assignments.count > 0,
^^^^^^^^^
./apps/canvas-lms/app/controllers/calendar_events_api_controller.rb:839:78: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if @event.appointment_group && @event.appointment_group.appointments.count == 0
^^^^^^^^^^
./apps/canvas-lms/app/controllers/calendar_events_api_controller.rb:866:79: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if event.appointment_group && @event.appointment_group.appointments.count == 0
^^^^^^^^^^
./apps/canvas-lms/app/controllers/courses_controller.rb:549:22: C: [Correctable] Style/CollectionQuerying: Use many? instead.
if enrollments.count > 1
^^^^^^^^^
./apps/canvas-lms/app/controllers/learner_passport_controller.rb:853:151: C: [Correctable] Style/CollectionQuerying: Use any? instead.
pathway[:learner_groups] = learner_passport_learner_groups.select { |lg| pathway[:learner_groups].include?(lg[:id]) } if pathway[:learner_groups].count > 0
^^^^^^^^^
./apps/canvas-lms/app/controllers/lti/ims/tool_setting_controller.rb:203:34: C: [Correctable] Style/CollectionQuerying: Use one? instead.
valid = json["@graph"].count == 1
^^^^^^^^^^
./apps/canvas-lms/app/controllers/provisional_grades_controller.rb:259:85: C: [Correctable] Style/CollectionQuerying: Use one? instead.
selected_provisional_grade = provisional_grades.first if provisional_grades.count == 1
^^^^^^^^^^
./apps/canvas-lms/app/controllers/quizzes/quizzes_controller.rb:1028:126: C: [Correctable] Style/CollectionQuerying: Use any? instead.
@any_submissions_pending_review = submitted_with_submissions.where("quiz_submissions.workflow_state = 'pending_review'").count > 0
^^^^^^^^^
./apps/canvas-lms/app/controllers/rubrics_api_controller.rb:402:24: C: [Correctable] Style/CollectionQuerying: Use many? instead.
if inclusion_items.count > 1
^^^^^^^^^
./apps/canvas-lms/app/controllers/rubrics_api_controller.rb:404:27: C: [Correctable] Style/CollectionQuerying: Use one? instead.
elsif inclusion_items.count == 1
^^^^^^^^^^
./apps/canvas-lms/app/controllers/wiki_pages_api_controller.rb:595:81: C: [Correctable] Style/CollectionQuerying: Use any? instead.
render json: { conflict: @context.wiki.wiki_pages.not_deleted.where(title:).count > 0 }
^^^^^^^^^
./apps/canvas-lms/app/controllers/wiki_pages_api_controller.rb:688:56: C: [Correctable] Style/CollectionQuerying: Use any? instead.
editing_roles_changed = existing_editing_roles.count { |role| editing_roles.exclude?(role) } > 0
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
./apps/canvas-lms/app/controllers/wiki_pages_api_controller.rb:689:48: C: [Correctable] Style/CollectionQuerying: Use any? instead.
editing_roles_changed |= editing_roles.count { |role| existing_editing_roles.exclude?(role) } > 0
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
./apps/canvas-lms/app/graphql/mutations/base_learning_outcome_mutation.rb:46:38: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return {} unless ratings_input.count.positive? && context
^^^^^^^^^^^^^^^
./apps/canvas-lms/app/graphql/mutations/create_submission_draft.rb:105:28: C: [Correctable] Style/CollectionQuerying: Use many? instead.
if submission_drafts.count > 1 && !@retried
^^^^^^^^^
./apps/canvas-lms/app/graphql/types/user_type.rb:293:80: C: [Correctable] Style/CollectionQuerying: Use any? instead.
contexts_collection = contexts_collection[0][1] if contexts_collection.count > 0
^^^^^^^^^
./apps/canvas-lms/app/graphql/types/user_type.rb:294:71: C: [Correctable] Style/CollectionQuerying: Use any? instead.
users_collection = users_collection[0][1] if users_collection.count > 0
^^^^^^^^^
./apps/canvas-lms/app/helpers/canvas_outcomes_helper.rb:152:33: C: [Correctable] Style/CollectionQuerying: Use any? instead.
response.first[:alignments].count > 0
^^^^^^^^^
./apps/canvas-lms/app/helpers/canvas_outcomes_helper.rb:173:112: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return true if get_request_page(context, domain, "api/authoritative_results", jwt, params, 1, 1)[:results].count > 0
^^^^^^^^^
./apps/canvas-lms/app/helpers/conversations_helper.rb:171:108: C: [Correctable] Style/CollectionQuerying: Use one? instead.
@recipients.reject! { |u| u.id == current_user.id } unless @recipients == [current_user] && recipients.count == 1
^^^^^^^^^^
./apps/canvas-lms/app/helpers/gradebooks_helper.rb:196:23: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if override_dates.count == 1
^^^^^^^^^^
./apps/canvas-lms/app/models/abstract_assignment.rb:4198:20: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if overrides.count { |o| !!o[:due_at_overridden] && o[:due_at].blank? && o[:workflow_state] != "deleted" } > 0
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
./apps/canvas-lms/app/models/account.rb:2074:30: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if allowed_service_names.count > 0 && !["+", "-"].include?(allowed_service_names[0][0, 1])
^^^^^^^^^
./apps/canvas-lms/app/models/account.rb:2109:32: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if allowed_service_names.count > 0
^^^^^^^^^
./apps/canvas-lms/app/models/account/help_links.rb:149:14: C: [Correctable] Style/CollectionQuerying: Use many? instead.
if links.count { |link| link[:is_featured] } > 1
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
./apps/canvas-lms/app/models/account/help_links.rb:151:17: C: [Correctable] Style/CollectionQuerying: Use many? instead.
elsif links.count { |link| link[:is_new] } > 1
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
./apps/canvas-lms/app/models/account_notification.rb:60:21: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return if roles.count > 0 && (roles & ["StudentEnrollment", "ObserverEnrollment"]).none?
^^^^^^^^^
./apps/canvas-lms/app/models/appointment_group.rb:149:56: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if (@new_sub_context_codes & context_subs).count == 0
^^^^^^^^^^
./apps/canvas-lms/app/models/attachment.rb:1736:95: C: [Correctable] Style/CollectionQuerying: Use any? instead.
while SubmissionDraftAttachment.where(attachment_id: attachments).limit(1000).destroy_all.count > 0 do end
^^^^^^^^^
./apps/canvas-lms/app/models/content_export.rb:617:46: C: [Correctable] Style/CollectionQuerying: Use any? instead.
context.assignments.active.type_quiz_lti.count.positive?
^^^^^^^^^^^^^^^
./apps/canvas-lms/app/models/content_migration.rb:829:156: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return true if outcome.learning_outcome_results.where("workflow_state <> 'deleted' AND context_type='Course' AND context_code='course_#{context.id}'").count > 0
^^^^^^^^^
./apps/canvas-lms/app/models/context_module.rb:693:50: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if content_tags.not_deleted.where(position:).count != 0
^^^^^^^^^^
./apps/canvas-lms/app/models/course.rb:3933:37: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if student_view_students.active.count == 0
^^^^^^^^^^
./apps/canvas-lms/app/models/courses/export_warnings.rb:30:113: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if assignments.active.joins(:grading_standard).where.not(grading_standards: { workflow_state: "active" }).count > 0
^^^^^^^^^
./apps/canvas-lms/app/models/discussion_entry.rb:245:36: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if discussion_entry_versions.count == 0 && !message_old.nil?
^^^^^^^^^^
./apps/canvas-lms/app/models/discussion_topic.rb:179:25: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if unlocked_teacher.count > 0
^^^^^^^^^
./apps/canvas-lms/app/models/group_membership.rb:114:40: C: [Correctable] Style/CollectionQuerying: Use one? instead.
record.group.group_memberships.count == 1 &&
^^^^^^^^^^
./apps/canvas-lms/app/models/importers/learning_outcome_importer.rb:39:110: C: [Correctable] Style/CollectionQuerying: Use any? instead.
next if LearningOutcome.active.where(id: o.fetch_outcome_copies, context_id: migration.context_id).count > 0
^^^^^^^^^
./apps/canvas-lms/app/models/notification.rb:704:32: C: [Correctable] Style/CollectionQuerying: Use any? instead.
user.teacher_enrollments.count > 0 || user.ta_enrollments.count > 0
^^^^^^^^^
./apps/canvas-lms/app/models/notification.rb:704:65: C: [Correctable] Style/CollectionQuerying: Use any? instead.
user.teacher_enrollments.count > 0 || user.ta_enrollments.count > 0
^^^^^^^^^
./apps/canvas-lms/app/models/quizzes/quiz.rb:943:75: C: [Correctable] Style/CollectionQuerying: Use one? instead.
needs_review = true if [old_version.points_possible, points_possible].count(&:present?) == 1 ||
^^^^^^^^^^^^^^^^^^^^^^
./apps/canvas-lms/app/models/quizzes/quiz_regrade_run.rb:49:89: C: [Correctable] Style/CollectionQuerying: Use one? instead.
!!(new && old.nil?) && Quizzes::QuizRegradeRun.where(quiz_regrade_id: quiz_regrade).count == 1
^^^^^^^^^^
./apps/canvas-lms/app/models/rubric_association.rb:175:52: C: [Correctable] Style/CollectionQuerying: Use none? instead.
rubric.destroy if rubric.rubric_associations.count == 0 && rubric.rubric_assessments.count == 0
^^^^^^^^^^
./apps/canvas-lms/app/models/rubric_association.rb:175:92: C: [Correctable] Style/CollectionQuerying: Use none? instead.
rubric.destroy if rubric.rubric_associations.count == 0 && rubric.rubric_assessments.count == 0
^^^^^^^^^^
./apps/canvas-lms/app/models/rubric_association.rb:240:64: C: [Correctable] Style/CollectionQuerying: Use none? instead.
rubric.destroy if cnt == 0 && rubric.rubric_associations.count == 0 && !rubric.public
^^^^^^^^^^
./apps/canvas-lms/app/models/speed_grader/assignment.rb:274:54: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if assignment.quiz.assignment_overrides.to_a.count(&:active?) == 0
^^^^^^^^^^^^^^^^^^^^^
./apps/canvas-lms/app/models/speed_grader/assignment.rb:453:24: C: [Correctable] Style/CollectionQuerying: Use none? instead.
unless pgs.count == 0 || (pgs.count == 1 && pgs.first.scorer_id == current_user.id)
^^^^^^^^^^
./apps/canvas-lms/app/models/speed_grader/assignment.rb:453:43: C: [Correctable] Style/CollectionQuerying: Use one? instead.
unless pgs.count == 0 || (pgs.count == 1 && pgs.first.scorer_id == current_user.id)
^^^^^^^^^^
./apps/canvas-lms/app/models/student_enrollment.rb:165:47: C: [Correctable] Style/CollectionQuerying: Use many? instead.
if section_ids_the_student_is_enrolled_in.count > 1 && course.course_paces.published.for_section(section_ids_the_student_is_enrolled_in).size > 1
^^^^^^^^^
./apps/canvas-lms/app/models/user_learning_object_scopes.rb:390:81: C: [Correctable] Style/CollectionQuerying: Use none? instead.
as.lazy.reject { |a| Assignments::NeedsGradingCountQuery.new(a, self).count == 0 }.take(limit).to_a
^^^^^^^^^^
./apps/canvas-lms/app/presenters/mark_done_presenter.rb:46:32: C: [Correctable] Style/CollectionQuerying: Use one? instead.
item_ids.first if item_ids.count == 1
^^^^^^^^^^
./apps/canvas-lms/build/new-jenkins/crystalball_merge_coverage.rb:37:37: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if spec.empty? || changed_files.count.zero?
^^^^^^^^^^^
./apps/canvas-lms/config/initializers/active_record.rb:1363:88: C: [Correctable] Style/CollectionQuerying: Use many? instead.
raise "multiple shard values passed to union: #{primary_shards}" if primary_shards.count > 1
^^^^^^^^^
./apps/canvas-lms/doc/yard_plugins/lti_variable_expansion_plugin.rb:36:68: C: [Correctable] Style/CollectionQuerying: Use any? instead.
deprecated_str = " *[deprecated]*" if object.tags(:deprecated).count > 0
^^^^^^^^^
./apps/canvas-lms/doc/yard_plugins/lti_variable_expansion_plugin.rb:39:28: C: [Correctable] Style/CollectionQuerying: Use any? instead.
example = example_tags.count > 0 && example_tags.first
^^^^^^^^^
./apps/canvas-lms/doc/yard_plugins/lti_variable_expansion_plugin.rb:51:34: C: [Correctable] Style/CollectionQuerying: Use any? instead.
duplicates = duplicates_tags.count > 0 && duplicates_tags.first
^^^^^^^^^
./apps/canvas-lms/gems/plugins/qti_exporter/lib/qti/assessment_item_converter.rb:210:69: C: [Correctable] Style/CollectionQuerying: Use many? instead.
if @doc.css("responseDeclaration[baseType=\"string\"]").count > 1
^^^^^^^^^
./apps/canvas-lms/gems/plugins/qti_exporter/lib/qti/assessment_test_converter.rb:185:22: C: [Correctable] Style/CollectionQuerying: Use many? instead.
if bank_refs.count > 1
^^^^^^^^^
./apps/canvas-lms/gems/plugins/qti_exporter/lib/qti/assessment_test_converter.rb:188:25: C: [Correctable] Style/CollectionQuerying: Use one? instead.
elsif bank_refs.count == 1
^^^^^^^^^^
./apps/canvas-lms/gems/plugins/qti_exporter/lib/qti/calculated_interaction.rb:130:32: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if @question[:variables].count == 1
^^^^^^^^^^
./apps/canvas-lms/lib/api/v1/context_module.rb:62:28: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return nil if tags.count == 0
^^^^^^^^^^
./apps/canvas-lms/lib/brand_account_chain_resolver.rb:60:16: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if actives.count == 1
^^^^^^^^^^
./apps/canvas-lms/lib/brand_account_chain_resolver.rb:69:60: C: [Correctable] Style/CollectionQuerying: Use one? instead.
break unless next_children.present? && next_children.count == 1
^^^^^^^^^^
./apps/canvas-lms/lib/canvas/live_events.rb:986:66: C: [Correctable] Style/CollectionQuerying: Use any? instead.
aligned_to_outcomes: rubric_assessment.aligned_outcome_ids.count.positive?,
^^^^^^^^^^^^^^^
./apps/canvas-lms/lib/canvas/migration/archive.rb:51:59: C: [Correctable] Style/CollectionQuerying: Use one? instead.
@nested_dir = root_dirs.first.name if root_dirs.count == 1
^^^^^^^^^^
./apps/canvas-lms/lib/canvas/migration/helpers/selective_content_formatter.rb:130:64: C: [Correctable] Style/CollectionQuerying: Use any? instead.
next unless course_data[type2] && course_data[type2].count > 0
^^^^^^^^^
./apps/canvas-lms/lib/cc/assignment_groups.rb:23:58: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return nil unless @course.assignment_groups.active.count > 0
^^^^^^^^^
./apps/canvas-lms/lib/cc/basic_lti_links.rb:23:63: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return nil unless @course.context_external_tools.active.count > 0
^^^^^^^^^
./apps/canvas-lms/lib/cc/events.rb:24:46: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return nil unless calendar_event_scope.count > 0
^^^^^^^^^
./apps/canvas-lms/lib/cc/exporter/web_zip/zip_package.rb:281:45: C: [Correctable] Style/CollectionQuerying: Use any? instead.
:all if modul.completion_requirements.count > 0
^^^^^^^^^
./apps/canvas-lms/lib/cc/external_feeds.rb:23:48: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return nil unless @course.external_feeds.count > 0
^^^^^^^^^
./apps/canvas-lms/lib/cc/module_meta.rb:23:61: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return nil unless @course.context_modules.not_deleted.count > 0
^^^^^^^^^
./apps/canvas-lms/lib/cc/qti/qti_items.rb:405:70: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return nil unless question["answers"] && question["answers"].count > 0
^^^^^^^^^
./apps/canvas-lms/lib/cc/rubrics.rb:23:53: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return nil unless @course.rubric_associations.count > 0
^^^^^^^^^
./apps/canvas-lms/lib/data_fixup/populate_root_account_id_on_models.rb:547:12: C: [Correctable] Style/CollectionQuerying: Use one? instead.
(names.count == 1) ? names.first : "COALESCE(#{names.join(", ")})"
^^^^^^^^^^
./apps/canvas-lms/lib/data_fixup/populate_root_account_ids_on_learning_outcomes.rb:30:32: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if Account.root_accounts.count == 1
^^^^^^^^^^
./apps/canvas-lms/lib/data_fixup/rebuild_quiz_submissions_from_quiz_submission_events.rb:189:28: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if seen_question_ids.count > 0
^^^^^^^^^
./apps/canvas-lms/lib/dates_overridable.rb:247:20: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if overrides.count > 0 && overrides.count == context.active_section_count
^^^^^^^^^
./apps/canvas-lms/lib/lti/variable_expander.rb:2036:34: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if val&.count == 1 && (course_id = val.first["course_id"])
^^^^^^^^^^
./apps/canvas-lms/lib/messageable_user/calculator.rb:466:61: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if section_or_id.respond_to?(:count) && section_or_id.count > 0
^^^^^^^^^
./apps/canvas-lms/lib/user_list_v2.rb:131:18: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if results.count == 1
^^^^^^^^^^
./apps/canvas-lms/lib/user_list_v2.rb:133:67: C: [Correctable] Style/CollectionQuerying: Use one? instead.
elsif results.uniq { |r| Shard.global_id_for(r[:user_id]) }.count == 1
^^^^^^^^^^
./apps/canvas-lms/spec/initializers/periodic_jobs_spec.rb:33:27: C: [Correctable] Style/CollectionQuerying: Use any? instead.
expect(Delayed::Job.count > 0).to be(true)
^^^^^^^^^
./apps/canvas-lms/spec/initializers/periodic_jobs_spec.rb:40:27: C: [Correctable] Style/CollectionQuerying: Use any? instead.
expect(Delayed::Job.count > 0).to be(true)
^^^^^^^^^
./apps/canvas-lms/spec/initializers/periodic_jobs_spec.rb:47:27: C: [Correctable] Style/CollectionQuerying: Use any? instead.
expect(Delayed::Job.count > 0).to be(true)
^^^^^^^^^
./apps/canvas-lms/spec/lib/canvas/live_events_spec.rb:3046:71: C: [Correctable] Style/CollectionQuerying: Use any? instead.
aligned_to_outcomes: @rubric_assessment.aligned_outcome_ids.count.positive?,
^^^^^^^^^^^^^^^
./apps/canvas-lms/spec/lib/canvas/live_events_spec.rb:3071:71: C: [Correctable] Style/CollectionQuerying: Use any? instead.
aligned_to_outcomes: @rubric_assessment.aligned_outcome_ids.count.positive?,
^^^^^^^^^^^^^^^
./apps/canvas-lms/spec/models/account_notification_spec.rb:457:54: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if u.enrollments.active_or_pending_by_date.count == 0 && u.user_account_associations.count > 0
^^^^^^^^^^
./apps/canvas-lms/spec/models/account_notification_spec.rb:457:96: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if u.enrollments.active_or_pending_by_date.count == 0 && u.user_account_associations.count > 0
^^^^^^^^^
./apps/canvas-lms/spec/models/assessment_question_bank_spec.rb:74:26: C: [Correctable] Style/CollectionQuerying: Use many? instead.
expect(aq_ids.uniq.count > 1).to be_truthy
^^^^^^^^^
./apps/canvas-lms/spec/requests/pace_contexts_spec.rb:116:56: C: [Correctable] Style/CollectionQuerying: Use any? instead.
expected_pace_type = (section.course_paces.count > 0) ? "Section" : "Course"
^^^^^^^^^
./apps/canvas-lms/spec/selenium/admin/admin_sub_accounts_spec.rb:32:27: C: [Correctable] Style/CollectionQuerying: Use one? instead.
(created_sub_accounts.count == 1) ? created_sub_accounts[0] : created_sub_accounts
^^^^^^^^^^
./apps/canvas-lms/spec/selenium/dashboard/dashboard_teacher_spec.rb:295:32: C: [Correctable] Style/CollectionQuerying: Use one? instead.
until all_todo_links.count == 1 || num_attempts == max_attempts
^^^^^^^^^^
./apps/canvas-lms/spec/selenium/master_courses/blueprint_associations_spec.rb:47:27: C: [Correctable] Style/CollectionQuerying: Use one? instead.
(created_sub_accounts.count == 1) ? created_sub_accounts[0] : created_sub_accounts
^^^^^^^^^^
./apps/canvas-lms/spec/selenium/outcomes/account_admin_state_outcomes_spec.rb:157:70: C: [Correctable] Style/CollectionQuerying: Use one? instead.
wait_for(method: nil, timeout: 2) { find_outcome_modal_items.count == 1 }
^^^^^^^^^^
./apps/canvas-lms/spec/selenium/shared_components/copy_to_tray_page.rb:112:59: C: [Correctable] Style/CollectionQuerying: Use one? instead.
wait_for(method: nil, timeout: 1) { dropdowns_in_tray.count == 1 }
^^^^^^^^^^
./apps/canvas-lms/spec/support/crystalball.rb:231:37: C: [Correctable] Style/CollectionQuerying: Use any? instead.
elsif file_changes["new"].count.positive?
^^^^^^^^^^^^^^^
49358 files inspected, 269 offenses detected, 269 offenses autocorrectable
real-world-ruby-apps report:
Report
./apps/CocoaPods/lib/cocoapods/command/lib/lint.rb:138:25: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if podspecs.count.zero?
^^^^^^^^^^^
./apps/CocoaPods/lib/cocoapods/command/repo/lint.rb:72:37: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if report.pods_by_error.count.zero?
^^^^^^^^^^^
./apps/CocoaPods/lib/cocoapods/command/spec.rb:46:17: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if sets.count == 1
^^^^^^^^^^
./apps/CocoaPods/lib/cocoapods/installer/analyzer/pod_variant_set.rb:25:56: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return { variants.first => nil } if variants.count == 1
^^^^^^^^^^
./apps/CocoaPods/lib/cocoapods/installer/analyzer/pod_variant_set.rb:58:30: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if scoped_variants.count == 1
^^^^^^^^^^
./apps/CocoaPods/lib/cocoapods/installer/analyzer/pod_variant_set.rb:93:57: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if grouped_variants.all? { |set| set.variants.count == 1 }
^^^^^^^^^^
./apps/CocoaPods/lib/cocoapods/installer/user_project_integrator.rb:214:34: C: [Correctable] Style/CollectionQuerying: Use one? instead.
elsif user_project_paths.count == 1
^^^^^^^^^^
./apps/CocoaPods/lib/cocoapods/installer/xcode/target_validator.rb:108:70: C: [Correctable] Style/CollectionQuerying: Use one? instead.
next if swift_target_definitions.uniq(&:swift_version).count == 1
^^^^^^^^^^
./apps/CocoaPods/lib/cocoapods/installer/xcode/target_validator.rb:143:64: C: [Correctable] Style/CollectionQuerying: Use one? instead.
"which #{non_module_dependencies.count == 1 ? 'does' : 'do'} not define modules. " \
^^^^^^^^^^
./apps/CocoaPods/lib/cocoapods/resolver.rb:499:42: C: [Correctable] Style/CollectionQuerying: Use one? instead.
dependencies = conflicts.count == 1 ? 'dependency' : 'dependencies'
^^^^^^^^^^
./apps/CocoaPods/lib/cocoapods/sources_manager.rb:145:89: C: [Correctable] Style/CollectionQuerying: Use any? instead.
changed_spec_paths[source] = changed_source_paths if changed_source_paths.count > 0
^^^^^^^^^
./apps/CocoaPods/lib/cocoapods/target/aggregate_target.rb:123:27: C: [Correctable] Style/CollectionQuerying: Use one? instead.
unless symbol_types.count == 1
^^^^^^^^^^
./apps/CocoaPods/lib/cocoapods/target/aggregate_target.rb:141:27: C: [Correctable] Style/CollectionQuerying: Use one? instead.
unless symbol_types.count == 1
^^^^^^^^^^
./apps/CocoaPods/lib/cocoapods/target/pod_target.rb:961:24: C: [Correctable] Style/CollectionQuerying: Use one? instead.
elsif whitelists.count == 1
^^^^^^^^^^
./apps/CocoaPods/lib/cocoapods/validator.rb:164:26: C: [Correctable] Style/CollectionQuerying: Use any? instead.
elsif subspecs.count > 0
^^^^^^^^^
./apps/CocoaPods/lib/cocoapods/validator.rb:704:32: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if (dynamic_frameworks.count > 0 || dynamic_libraries.count > 0) && consumer.platform_name == :ios &&
^^^^^^^^^
./apps/CocoaPods/lib/cocoapods/validator.rb:704:63: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if (dynamic_frameworks.count > 0 || dynamic_libraries.count > 0) && consumer.platform_name == :ios &&
^^^^^^^^^
./apps/CocoaPods/spec/unit/installer/analyzer_spec.rb:805:42: C: [Correctable] Style/CollectionQuerying: Use one? instead.
pod_target.dependent_targets.count == 1
^^^^^^^^^^
./apps/CocoaPods/spec/unit/installer/analyzer_spec.rb:833:47: C: [Correctable] Style/CollectionQuerying: Use one? instead.
pod_target_ios8.dependent_targets.count == 1
^^^^^^^^^^
./apps/CocoaPods/spec/unit/installer/analyzer_spec.rb:839:47: C: [Correctable] Style/CollectionQuerying: Use one? instead.
pod_target_ios9.dependent_targets.count == 1
^^^^^^^^^^
./apps/CocoaPods/spec/unit/installer/analyzer_spec.rb:863:43: C: [Correctable] Style/CollectionQuerying: Use one? instead.
result.targets[0].pod_targets.count == 1
^^^^^^^^^^
./apps/CocoaPods/spec/unit/installer/analyzer_spec.rb:865:43: C: [Correctable] Style/CollectionQuerying: Use one? instead.
result.targets[1].pod_targets.count == 1
^^^^^^^^^^
./apps/CocoaPods/spec/unit/installer/analyzer_spec.rb:1120:42: C: [Correctable] Style/CollectionQuerying: Use one? instead.
pod_target.dependent_targets.count == 1
^^^^^^^^^^
./apps/CocoaPods/spec/unit/installer/analyzer_spec.rb:1129:42: C: [Correctable] Style/CollectionQuerying: Use one? instead.
pod_target.dependent_targets.count == 1
^^^^^^^^^^
./apps/CocoaPods/spec/unit/installer/analyzer_spec.rb:1155:43: C: [Correctable] Style/CollectionQuerying: Use one? instead.
result.targets[0].pod_targets.count == 1
^^^^^^^^^^
./apps/CocoaPods/spec/unit/installer/analyzer_spec.rb:1157:43: C: [Correctable] Style/CollectionQuerying: Use one? instead.
result.targets[1].pod_targets.count == 1
^^^^^^^^^^
./apps/CocoaPods/spec/unit/installer/analyzer_spec.rb:1175:43: C: [Correctable] Style/CollectionQuerying: Use one? instead.
result.targets[0].pod_targets.count == 1
^^^^^^^^^^
./apps/CocoaPods/spec/unit/installer/analyzer_spec.rb:1195:43: C: [Correctable] Style/CollectionQuerying: Use one? instead.
result.targets[0].pod_targets.count == 1
^^^^^^^^^^
./apps/LicenseFinder/lib/license_finder/package_managers/bundler.rb:87:35: C: [Correctable] Style/CollectionQuerying: Use any? instead.
content.grep(/BUNDLE_PATH/).count.positive?
^^^^^^^^^^^^^^^
./apps/bashly/lib/bashly/script/command.rb:225:39: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return true if command.args.count(&:unique).positive? ||
^^^^^^^^^^^^^^^^^^^^^^^^^
./apps/bashly/lib/bashly/script/command.rb:226:27: C: [Correctable] Style/CollectionQuerying: Use any? instead.
command.flags.count(&:unique).positive?
^^^^^^^^^^^^^^^^^^^^^^^^^
./apps/brakeman/lib/brakeman/commandline.rb:62:50: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if options[:exit_on_warn] && vulns[:new].count > 0
^^^^^^^^^
./apps/chef/knife/lib/chef/knife/environment_compare.rb:110:25: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if total.uniq.count == 1
^^^^^^^^^^
./apps/chef/lib/chef/formatters/error_inspectors/compile_error_inspector.rb:129:40: C: [Correctable] Style/CollectionQuerying: Use any? instead.
backtrace_lines_in_cookbooks.count > 0 ? backtrace_lines_in_cookbooks : exception.backtrace
^^^^^^^^^
./apps/chef/lib/chef/provider/package/windows/exe.rb:95:36: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if uninstall_entries.count != 0
^^^^^^^^^^
./apps/chef/lib/chef/provider/package/windows/msi.rb:55:36: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if uninstall_entries.count != 0
^^^^^^^^^^
./apps/chef/lib/chef/resource/_rest_resource.rb:379:12: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if arr.count == 1
^^^^^^^^^^
./apps/chef/lib/chef/resource/habitat_user_toml.rb:76:37: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return unless result.each.count > 0
^^^^^^^^^
./apps/chef/lib/chef/resource/remote_file.rb:138:61: C: [Correctable] Style/CollectionQuerying: Use one? instead.
elsif args[0].is_a?(Chef::DelayedEvaluator) && args.count == 1
^^^^^^^^^^
./apps/github-changelog-generator/lib/github_changelog_generator/octo_fetcher.rb:121:15: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if tags.count == 0
^^^^^^^^^^
./apps/homebrew/Library/Homebrew/cask/upgrade.rb:127:61: C: [Correctable] Style/CollectionQuerying: Use one? instead.
raise caught_exceptions.fetch(0) if caught_exceptions.count == 1
^^^^^^^^^^
./apps/homebrew/Library/Homebrew/cmd/developer.rb:37:30: C: [Correctable] Style/CollectionQuerying: Use one? instead.
verb = (env_vars.count == 1) ? "is" : "are"
^^^^^^^^^^
./apps/homebrew/Library/Homebrew/dev-cmd/bottle.rb:739:101: C: [Correctable] Style/CollectionQuerying: Use one? instead.
tag_hashes.uniq { |tag_hash| "#{tag_hash["cellar"]}-#{tag_hash["sha256"]}" }.count == 1
^^^^^^^^^^
./apps/homebrew/Library/Homebrew/download_strategy.rb:298:37: C: [Correctable] Style/CollectionQuerying: Use one? instead.
@cached_location = if downloads.count == 1
^^^^^^^^^^
./apps/homebrew/Library/Homebrew/livecheck/skip_conditions.rb:314:70: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if skip_hash[:messages].is_a?(Array) && skip_hash[:messages].count.positive?
^^^^^^^^^^^^^^^
./apps/homebrew/Library/Homebrew/rubocops/extend/formula_cop.rb:204:57: C: [Correctable] Style/CollectionQuerying: Use none? instead.
next if list_contents.nil? || list_contents.count.zero?
^^^^^^^^^^^
./apps/homebrew/Library/Homebrew/rubocops/extend/formula_cop.rb:210:77: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return false if @tap_style_exceptions.nil? || @tap_style_exceptions.count.zero?
^^^^^^^^^^^
./apps/homebrew/Library/Homebrew/style.rb:178:61: C: [Correctable] Style/CollectionQuerying: Use one? instead.
args << "--format" << "clang" if ENV["CI"] || files.count { |f| !f.directory? } == 1
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
./apps/homebrew/Library/Homebrew/uninstall.rb:51:67: C: [Correctable] Style/CollectionQuerying: Use one? instead.
#{keg.name} #{versions.to_sentence} #{(versions.count == 1) ? "is" : "are"} still installed.
^^^^^^^^^^
./apps/homebrew/Library/Homebrew/uninstall.rb:134:18: C: [Correctable] Style/CollectionQuerying: Use one? instead.
"#{(reqs.count == 1) ? "is" : "are"} required by #{deps.to_sentence}, " \
^^^^^^^^^^
./apps/homebrew/Library/Homebrew/uninstall.rb:135:26: C: [Correctable] Style/CollectionQuerying: Use one? instead.
"which #{(deps.count == 1) ? "is" : "are"} currently installed"
^^^^^^^^^^
./apps/homebrew/Library/Homebrew/uninstall.rb:153:27: C: [Correctable] Style/CollectionQuerying: Use one? instead.
because #{(reqs.count == 1) ? "it" : "they"} #{are_required_by_deps}.
^^^^^^^^^^
./apps/homebrew/Library/Homebrew/unversioned_cask_checker.rb:75:12: C: [Correctable] Style/CollectionQuerying: Use one? instead.
apps.count == 1
^^^^^^^^^^
./apps/homebrew/Library/Homebrew/unversioned_cask_checker.rb:80:17: C: [Correctable] Style/CollectionQuerying: Use one? instead.
qlplugins.count == 1
^^^^^^^^^^
./apps/homebrew/Library/Homebrew/unversioned_cask_checker.rb:85:12: C: [Correctable] Style/CollectionQuerying: Use one? instead.
pkgs.count == 1
^^^^^^^^^^
./apps/homebrew/Library/Homebrew/unversioned_cask_checker.rb:225:83: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return unique_info_plist_versions.first if unique_info_plist_versions.count == 1
^^^^^^^^^^
./apps/homebrew/Library/Homebrew/unversioned_cask_checker.rb:232:28: C: [Correctable] Style/CollectionQuerying: Use one? instead.
elsif packages.count == 1
^^^^^^^^^^
./apps/jekyll/test/test_post_reader.rb:28:42: C: [Correctable] Style/CollectionQuerying: Use any? instead.
assert expected_skipped_file_names.count.positive?,
^^^^^^^^^^^^^^^
./apps/licensee/lib/licensee/content_helper.rb:248:23: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return if lines.count == 1
^^^^^^^^^^
./apps/licensee/lib/licensee/projects/project.rb:27:50: C: [Correctable] Style/CollectionQuerying: Use one? instead.
@license = if licenses_without_copyright.count == 1 || lgpl?
^^^^^^^^^^
./apps/licensee/lib/licensee/projects/project.rb:41:46: C: [Correctable] Style/CollectionQuerying: Use one? instead.
matched_files.first if matched_files.count == 1 || lgpl?
^^^^^^^^^^
./apps/licensee/lib/licensee/projects/project.rb:51:46: C: [Correctable] Style/CollectionQuerying: Use one? instead.
license_files.first if license_files.count == 1 || lgpl?
^^^^^^^^^^
./apps/linguist/lib/linguist/generated.rb:720:33: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return false unless lines.count > 0
^^^^^^^^^
./apps/mdless/lib/mdless/console.rb:583:20: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if notes.count.positive?
^^^^^^^^^^^^^^^
./apps/optcarrot/lib/optcarrot/apu.rb:417:60: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return false if @length_counter && @length_counter.count == 0
^^^^^^^^^^
./apps/optcarrot/lib/optcarrot/apu.rb:461:25: C: [Correctable] Style/CollectionQuerying: Use any? instead.
@length_counter.count > 0
^^^^^^^^^
./apps/pry/lib/pry/slop.rb:334:58: C: [Correctable] Style/CollectionQuerying: Use any? instead.
keys.all? { |key| (opt = fetch_option(key)) && opt.count > 0 }
^^^^^^^^^
./apps/pry/lib/pry/slop.rb:502:33: C: [Correctable] Style/CollectionQuerying: Use any? instead.
option.value = option.count > 0
^^^^^^^^^
./apps/pry/lib/pry/slop.rb:534:31: C: [Correctable] Style/CollectionQuerying: Use any? instead.
option.value = option.count > 0
^^^^^^^^^
./apps/puma/lib/puma/cluster.rb:154:16: C: [Correctable] Style/CollectionQuerying: Use none? instead.
@workers.count { |w| !w.booted? } == 0
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
./apps/puppet/lib/puppet/network/http/handler.rb:23:14: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if dupes.count > 0
^^^^^^^^^
./apps/puppet/lib/puppet/pops/evaluator/evaluator_impl.rb:895:33: C: [Correctable] Style/CollectionQuerying: Use one? instead.
body = if o.body.statements.count == 1
^^^^^^^^^^
./apps/puppet/lib/puppet/pops/lookup/hiera_config.rb:768:41: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if defaults.nil? || FUNCTION_KEYS.count { |key| defaults.include?(key) } == 0
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
./apps/puppet/lib/puppet/provider/package/nim.rb:272:31: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if packages[package_name].count == 1
^^^^^^^^^^
./apps/puppet/lib/puppet/util/command_line.rb:173:60: C: [Correctable] Style/CollectionQuerying: Use any? instead.
elsif @command_line.subcommand_name.nil? && args.count > 0
^^^^^^^^^
./apps/puppet/lib/puppet/util/profiler/aggregate.rb:32:15: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if rest.count > 0
^^^^^^^^^
./apps/puppet/spec/unit/pops/validator/validator_spec.rb:29:22: C: [Correctable] Style/CollectionQuerying: Use any? instead.
}) if env_params.count > 0
^^^^^^^^^
./apps/rdoc/lib/rdoc/rdoc.rb:128:18: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if file_list.count {|name, mtime| ...
^^^^^^^^^^^^^^^^^^^^
./apps/rufus-scheduler/spec/job_cron_spec.rb:239:26: C: [Correctable] Style/CollectionQuerying: Use any? instead.
wait_until { job.count > 0 }
^^^^^^^^^
./apps/rufus-scheduler/spec/job_every_spec.rb:130:16: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if j.count == 1
^^^^^^^^^^
./apps/rufus-scheduler/spec/job_every_spec.rb:233:26: C: [Correctable] Style/CollectionQuerying: Use any? instead.
wait_until { job.count > 0 }
^^^^^^^^^
./apps/rufus-scheduler/spec/job_every_spec.rb:251:26: C: [Correctable] Style/CollectionQuerying: Use any? instead.
wait_until { job.count > 0 }
^^^^^^^^^
./apps/rufus-scheduler/spec/job_every_spec.rb:269:26: C: [Correctable] Style/CollectionQuerying: Use any? instead.
wait_until { job.count > 0 }
^^^^^^^^^
./apps/rufus-scheduler/spec/scheduler_spec.rb:973:28: C: [Correctable] Style/CollectionQuerying: Use any? instead.
wait_until { job.count > 0 }
^^^^^^^^^
./apps/yard/lib/yard/handlers/ruby/decorator_handler_methods.rb:58:19: C: [Correctable] Style/CollectionQuerying: Use one? instead.
elsif nodes.count == 1 && nodes.first.nil?
^^^^^^^^^^
19489 files inspected, 94 offenses detected, 94 offenses autocorrectable
I love this cop suggestion, but we'll have to polish a few things before we can merge it. Most importantly we should add a matching rule to the style guide (I believe that's non-controversial).
I'm also not a fan of the name, so I'll think a bit about some alternatives.
Before we merge this:
- add the link to the style guide that was added recently
- mention in the docs why the cop ignores size and length
Might be a good idea to add some aggressive mode that actually checks for them as well - would be useful for one-off refactoring runs I guess.
Before we merge this: add the link to the style guide that was added recently mention in the docs why the cop ignores size and length
Done 👍
Might be a good idea to add some aggressive mode that actually checks for them as well - would be useful for one-off refactoring runs I guess.
I agree, I ran the cop on real-world-rails and made it check just for length and size methods, and it did find a lot of valid offenses (and some false positives as well). If you don't mind, I'd add logic for those methods in a follow-up PR to not increase the scope too much for now.
real-world-rails report
./apps/mastodon/app/controllers/concerns/web_app_controller_concern.rb:14:107: C: [Correctable] Style/CollectionQuerying: Use one? instead.
!(ENV['ONE_CLICK_SSO_LOGIN'] == 'true' && ENV['OMNIAUTH_ONLY'] == 'true' && Devise.omniauth_providers.length == 1) && current_user.nil?
^^^^^^^^^^^
./apps/mastodon/app/controllers/settings/two_factor_authentication/webauthn_credentials_controller.rb:48:50: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if current_user.webauthn_credentials.size == 1
^^^^^^^^^
./apps/mastodon/app/helpers/application_helper.rb:60:90: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if omniauth_only? && Devise.mappings[:user].omniauthable? && User.omniauth_providers.size == 1
^^^^^^^^^
./apps/mastodon/app/helpers/context_helper.rb:64:22: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if context_array.size == 1
^^^^^^^^^
./apps/mastodon/app/models/tag.rb:155:16: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if names.size == 1
^^^^^^^^^
./apps/mastodon/app/serializers/initial_state_serializer.rb:127:153: C: [Correctable] Style/CollectionQuerying: Use one? instead.
"/auth/auth/#{Devise.omniauth_providers[0]}" if ENV['ONE_CLICK_SSO_LOGIN'] == 'true' && ENV['OMNIAUTH_ONLY'] == 'true' && Devise.omniauth_providers.length == 1
^^^^^^^^^^^
./apps/mastodon/app/services/account_search_service.rb:262:24: C: [Correctable] Style/CollectionQuerying: Use one? instead.
split_query_string.size == 1
^^^^^^^^^
./apps/mastodon/config/initializers/content_security_policy.rb:18:43: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return unless Devise.omniauth_providers.length == 1
^^^^^^^^^^^
./apps/mastodon/lib/active_record/batches.rb:10:34: C: [Correctable] Style/CollectionQuerying: Use one? instead.
flatten = column_names.size == 1
^^^^^^^^^
./apps/mastodon/lib/paperclip/image_extractor.rb:14:58: C: [Correctable] Style/CollectionQuerying: Use any? instead.
attachment.instance.thumbnail = image if image.size.positive?
^^^^^^^^^^^^^^
./apps/dev.to/app/controllers/concerns/development_dependency_checks.rb:13:39: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return if Sidekiq::ProcessSet.new.size.positive?
^^^^^^^^^^^^^^
./apps/dev.to/app/helpers/admin/organizations_helper.rb:9:31: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if organization.credits.length.positive?
^^^^^^^^^^^^^^^^
./apps/dev.to/app/models/organization.rb:139:48: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return unless change && articles.published.size.positive?
^^^^^^^^^^^^^^
./apps/dev.to/app/models/user.rb:626:48: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return unless change && articles.published.size.positive?
^^^^^^^^^^^^^^
./apps/dev.to/app/policies/article_policy.rb:173:31: C: [Correctable] Style/CollectionQuerying: Use any? instead.
tag_ids_moderated_by_user.size.positive?
^^^^^^^^^^^^^^
./apps/dev.to/app/services/feed_events/bulk_upsert.rb:29:23: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if valid_events.size == 1
^^^^^^^^^
./apps/dev.to/app/services/feeds/import.rb:170:19: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if articles.length.positive?
^^^^^^^^^^^^^^^^
./apps/dev.to/app/workers/reactions/bust_reactable_cache_worker.rb:21:75: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if Reaction.for_articles([reaction.reactable_id]).public_category.size == 1
^^^^^^^^^
./apps/dev.to/bin/untranslated_erb:37:38: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return true if s.nil? || s.strip.size == 0
^^^^^^^^^
./apps/dev.to/spec/models/article_spec.rb:338:38: C: [Correctable] Style/CollectionQuerying: Use any? instead.
expect(test_article.tag_list.length.positive?).to be(true)
^^^^^^^^^^^^^^^^
./apps/discourse/app/controllers/application_controller.rb:845:44: C: [Correctable] Style/CollectionQuerying: Use one? instead.
Discourse.enabled_authenticators.length == 1 && !cookies[:authentication_data]
^^^^^^^^^^^
./apps/discourse/app/controllers/notifications_controller.rb:119:20: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if invalid.size > 0
^^^^^^^^
./apps/discourse/app/controllers/safe_mode_controller.rb:26:18: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if safe_mode.length > 0
^^^^^^^^^^
./apps/discourse/app/controllers/session_controller.rb:667:76: C: [Correctable] Style/CollectionQuerying: Use one? instead.
!SiteSetting.enable_local_logins && Discourse.enabled_authenticators.length == 1
^^^^^^^^^^^
./apps/discourse/app/controllers/tags_controller.rb:172:23: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if @list.topics.size == 0 && params[:tag_id] != "none" && !Tag.where_name(@tag_id).exists?
^^^^^^^^^
./apps/discourse/app/controllers/topics_controller.rb:429:16: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if changes.length > 0
^^^^^^^^^^
./apps/discourse/app/controllers/uploads_controller.rb:86:52: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if (params[:short_urls] && params[:short_urls].length > 0)
^^^^^^^^^^
./apps/discourse/app/jobs/base.rb:325:21: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if exceptions.length > 0
^^^^^^^^^^
./apps/discourse/app/jobs/onceoff/grant_emoji.rb:18:63: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if (doc.css("img.emoji") - doc.css(".quote img")).size > 0
^^^^^^^^
./apps/discourse/app/jobs/onceoff/grant_onebox.rb:23:41: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if doc.search("a.onebox").size > 0
^^^^^^^^
./apps/discourse/app/jobs/regular/process_bulk_invite_emails.rb:12:29: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if pending_invite_ids.length > 0
^^^^^^^^^^
./apps/discourse/app/jobs/regular/pull_hotlinked_images.rb:84:24: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if hotlinked_map.size > 0
^^^^^^^^
./apps/discourse/app/jobs/scheduled/pending_queued_posts_reminder.rb:12:26: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if queued_post_ids.size > 0 && last_notified_id.to_i < queued_post_ids.max
^^^^^^^^
./apps/discourse/app/jobs/scheduled/pending_reviewables_reminder.rb:24:27: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if reviewable_ids.size > 0 && self.class.last_notified_id < reviewable_ids[0]
^^^^^^^^
./apps/discourse/app/jobs/scheduled/pending_reviewables_reminder.rb:26:32: C: [Correctable] Style/CollectionQuerying: Use any? instead.
mentions = usernames.size > 0 ? "@#{usernames.join(", @")} " : ""
^^^^^^^^
./apps/discourse/app/models/category.rb:441:27: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if category_slugs.length == 1
^^^^^^^^^^^
./apps/discourse/app/models/category.rb:902:75: C: [Correctable] Style/CollectionQuerying: Use any? instead.
filters.each { |filter| relation = filter.call(relation) } if filters.length > 0
^^^^^^^^^^
./apps/discourse/app/models/concerns/cached_counting.rb:100:17: C: [Correctable] Style/CollectionQuerying: Use any? instead.
while QUEUE.length > 0
^^^^^^^^^^
./apps/discourse/app/models/discourse_connect.rb:219:16: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if split.length > 0
^^^^^^^^^^
./apps/discourse/app/models/discourse_connect.rb:230:16: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if split.length > 0
^^^^^^^^^^
./apps/discourse/app/models/emoji.rb:175:23: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if denied_emoji.size > 0
^^^^^^^^
./apps/discourse/app/models/global_setting.rb:159:21: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if db_variables.length > 0
^^^^^^^^^^
./apps/discourse/app/models/notification.rb:335:14: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if ids.length > 0
^^^^^^^^^^
./apps/discourse/app/models/optimized_image.rb:86:33: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return nil if extension.length == 1
^^^^^^^^^^^
./apps/discourse/app/models/post.rb:395:27: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return hosts if hosts.length == 0
^^^^^^^^^^^
./apps/discourse/app/models/post.rb:744:12: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if ids.length > 0
^^^^^^^^^^
./apps/discourse/app/models/post.rb:1126:74: C: [Correctable] Style/CollectionQuerying: Use any? instead.
UploadReference.insert_all(upload_references) if upload_references.size > 0
^^^^^^^^
./apps/discourse/app/models/post_timing.rb:186:19: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if join_table.length > 0
^^^^^^^^^^
./apps/discourse/app/models/post_timing.rb:222:16: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if timings.length > 0
^^^^^^^^^^
./apps/discourse/app/models/quoted_post.rb:28:13: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if uniq.length == 0
^^^^^^^^^^^
./apps/discourse/app/models/remote_theme.rb:437:29: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if missing_scheme_names.length > 0
^^^^^^^^^^
./apps/discourse/app/models/tag_user.rb:89:37: C: [Correctable] Style/CollectionQuerying: Use any? instead.
changed = true if result.rows.length > 0
^^^^^^^^^^
./apps/discourse/app/models/theme_field.rb:539:79: C: [Correctable] Style/CollectionQuerying: Use one? instead.
hash[option] = @allowed_values[plural][0] if @allowed_values[plural]&.length == 1
^^^^^^^^^^^
./apps/discourse/app/models/topic_list.rb:16:34: C: [Correctable] Style/CollectionQuerying: Use none? instead.
@preload = nil if @preload.length == 0
^^^^^^^^^^^
./apps/discourse/app/models/topic_posters_summary.rb:38:57: C: [Correctable] Style/CollectionQuerying: Use one? instead.
topic_poster.extras << " single" if user_ids.uniq.size == 1
^^^^^^^^^
./apps/discourse/app/models/topic_user.rb:372:15: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if rows.length == 1
^^^^^^^^^^^
./apps/discourse/app/models/topic_user.rb:394:15: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if rows.length == 0
^^^^^^^^^^^
./apps/discourse/app/models/upload.rb:147:53: C: [Correctable] Style/CollectionQuerying: Use none? instead.
fix_image_extension if (!extension || extension.length == 0)
^^^^^^^^^^^
./apps/discourse/app/models/user_action.rb:248:39: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if action_types && action_types.length > 0
^^^^^^^^^^
./apps/discourse/app/serializers/admin_plugin_serializer.rb:67:26: C: [Correctable] Style/CollectionQuerying: Use one? instead.
plugin_settings.keys.length == 1 && plugin_settings.keys.first == enabled_setting
^^^^^^^^^^^
./apps/discourse/app/serializers/category_serializer.rb:57:18: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if perms.length == 0 && !object.read_restricted
^^^^^^^^^^^
./apps/discourse/app/serializers/post_serializer.rb:516:64: C: [Correctable] Style/CollectionQuerying: Use any? instead.
object.wiki && object.post_number == 1 && object.revisions.size > 0
^^^^^^^^
./apps/discourse/app/serializers/user_serializer.rb:164:10: C: [Correctable] Style/CollectionQuerying: Use any? instead.
keys.length > 0 ? keys : nil
^^^^^^^^^^
./apps/discourse/app/services/badge_granter.rb:35:18: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if usernames.size > 0
^^^^^^^^
./apps/discourse/app/services/badge_granter.rb:38:15: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if emails.size > 0
^^^^^^^^
./apps/discourse/app/services/post_action_notifier.rb:33:18: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if usernames.length > 0
^^^^^^^^^^
./apps/discourse/app/services/post_alerter.rb:109:18: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if clients.length > 0
^^^^^^^^^^
./apps/discourse/app/services/search_indexer.rb:87:27: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if additional_words.length > 0
^^^^^^^^^^
./apps/discourse/app/services/search_indexer.rb:144:43: C: [Correctable] Style/CollectionQuerying: Use any? instead.
search_data.values.select { |d| d.length > 0 }.join(" ")
^^^^^^^^^^
./apps/discourse/app/services/username_checker_service.rb:9:29: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if username && username.length > 0
^^^^^^^^^^
./apps/discourse/config/initializers/000-development_reload_warnings.rb:30:25: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if not_autoloaded.length > 0
^^^^^^^^^^
./apps/discourse/db/migrate/20131210181901_migrate_word_counts.rb:9:20: C: [Correctable] Style/CollectionQuerying: Use any? instead.
while post_ids.length > 0
^^^^^^^^^^
./apps/discourse/db/migrate/20131210181901_migrate_word_counts.rb:24:21: C: [Correctable] Style/CollectionQuerying: Use any? instead.
while topic_ids.length > 0
^^^^^^^^^^
./apps/discourse/db/migrate/20180420141134_remove_staff_tags_setting.rb:14:15: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if result.length > 0
^^^^^^^^^^
./apps/discourse/db/migrate/20180710172959_disallow_multi_levels_theme_components.rb:17:17: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if @handled.size > 0
^^^^^^^^
./apps/discourse/db/migrate/20191211170000_add_hashed_api_key.rb:27:20: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if to_update.size > 0
^^^^^^^^
./apps/discourse/db/migrate/20200403100259_add_key_hash_to_user_api_key.rb:14:21: C: [Correctable] Style/CollectionQuerying: Use none? instead.
break if rows.size == 0
^^^^^^^^^
./apps/discourse/db/migrate/20200810194943_change_selectable_avatars_site_setting.rb:32:20: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return if urls.size == 0 && sha1s.size == 0
^^^^^^^^^
./apps/discourse/db/migrate/20200810194943_change_selectable_avatars_site_setting.rb:32:39: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return if urls.size == 0 && sha1s.size == 0
^^^^^^^^^
./apps/discourse/db/migrate/20200810194943_change_selectable_avatars_site_setting.rb:35:13: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if urls.size > 0
^^^^^^^^
./apps/discourse/db/migrate/20200810194943_change_selectable_avatars_site_setting.rb:38:14: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if sha1s.size > 0
^^^^^^^^
./apps/discourse/db/migrate/20200810194943_change_selectable_avatars_site_setting.rb:44:26: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return if upload_ids.size == 0
^^^^^^^^^
./apps/discourse/db/migrate/20210929215543_add_token_hash_to_email_token.rb:13:21: C: [Correctable] Style/CollectionQuerying: Use none? instead.
break if rows.size == 0
^^^^^^^^^
./apps/discourse/db/migrate/20211213060445_email_tokens_token_to_nullable.rb:12:49: C: [Correctable] Style/CollectionQuerying: Use any? instead.
execute <<~SQL if DB.query_single(<<~SQL).length > 0
^^^^^^^^^^
./apps/discourse/db/post_migrate/20231120190818_trigger_post_rebake_category_style_quotes.rb:21:47: C: [Correctable] Style/CollectionQuerying: Use any? instead.
DB.exec(<<~SQL, ids: ids) if ids && ids.length > 0
^^^^^^^^^^
./apps/discourse/db/post_migrate/20231127165331_trigger_auto_linking_for_videos_since_placeholder.rb:23:47: C: [Correctable] Style/CollectionQuerying: Use any? instead.
DB.exec(<<~SQL, ids: ids) if ids && ids.length > 0
^^^^^^^^^^
./apps/discourse/lib/auth/discord_authenticator.rb:61:26: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if allowed_guild_ids.length > 0
^^^^^^^^^^
./apps/discourse/lib/autospec/manager.rb:108:57: C: [Correctable] Style/CollectionQuerying: Use none? instead.
puts "@@@@@@@@@@@@ ...queue is empty" if @queue.length == 0
^^^^^^^^^^^
./apps/discourse/lib/autospec/manager.rb:110:38: C: [Correctable] Style/CollectionQuerying: Use none? instead.
@signal.wait(@mutex) if @queue.length == 0 || last_failed
^^^^^^^^^^^
./apps/discourse/lib/autospec/manager.rb:151:21: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if failed_specs.length > 0
^^^^^^^^^^
./apps/discourse/lib/autospec/manager.rb:165:78: C: [Correctable] Style/CollectionQuerying: Use any? instead.
@queue.unshift ["focus", failed_specs.join(" "), runner] if failed_specs.length > 0
^^^^^^^^^^
./apps/discourse/lib/autospec/manager.rb:255:21: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return if files.length == 0
^^^^^^^^^^^
./apps/discourse/lib/autospec/manager.rb:298:14: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if specs.length == 0
^^^^^^^^^^^
./apps/discourse/lib/autospec/manager.rb:338:15: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if @queue.length == 0
^^^^^^^^^^^
./apps/discourse/lib/autospec/manager.rb:348:16: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if specs.length == 0
^^^^^^^^^^^
./apps/discourse/lib/cooked_post_processor.rb:58:54: C: [Correctable] Style/CollectionQuerying: Use any? instead.
(@doc.css("img.emoji") - @doc.css(".quote img")).size > 0
^^^^^^^^
./apps/discourse/lib/cooked_post_processor.rb:402:45: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if !onebox || onebox.element_children.size == 1
^^^^^^^^^
./apps/discourse/lib/cooked_post_processor.rb:410:45: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if !onebox || onebox.element_children.size == 1
^^^^^^^^^
./apps/discourse/lib/db_helper.rb:115:17: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if rows.size > 0
^^^^^^^^
./apps/discourse/lib/discourse.rb:155:38: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if !unsafe_shell && (command.length == 1) && command[0].include?(" ")
^^^^^^^^^^^
./apps/discourse/lib/discourse.rb:715:22: C: [Correctable] Style/CollectionQuerying: Use any? instead.
while @dbs.size > 0
^^^^^^^^
./apps/discourse/lib/discourse_diff.rb:172:31: C: [Correctable] Style/CollectionQuerying: Use any? instead.
tokens << t.join if t.size > 0
^^^^^^^^
./apps/discourse/lib/discourse_diff.rb:178:27: C: [Correctable] Style/CollectionQuerying: Use any? instead.
tokens << t.join if t.size > 0
^^^^^^^^
./apps/discourse/lib/discourse_diff.rb:193:15: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if result.size > 0 && result[0] == "<" && index_of_next_chevron
^^^^^^^^
./apps/discourse/lib/discourse_tagging.rb:93:63: C: [Correctable] Style/CollectionQuerying: Use any? instead.
tags = Tag.where(id: tags.map(&:id)).all.to_a if tags.size > 0
^^^^^^^^
./apps/discourse/lib/discourse_tagging.rb:136:42: C: [Correctable] Style/CollectionQuerying: Use none? instead.
(tag_ids & parent_tag_ids).size == 0 ? parent_tag_ids.first : nil
^^^^^^^^^
./apps/discourse/lib/discourse_tagging.rb:157:48: C: [Correctable] Style/CollectionQuerying: Use any? instead.
next if (tag_ids & parent_tag_ids).size > 0 # tag already has a parent tag
^^^^^^^^
./apps/discourse/lib/discourse_tagging.rb:196:17: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if tags.size == 0
^^^^^^^^^
./apps/discourse/lib/discourse_updates.rb:175:15: C: [Correctable] Style/CollectionQuerying: Use any? instead.
entries.size > 0
^^^^^^^^
./apps/discourse/lib/email/message_builder.rb:280:42: C: [Correctable] Style/CollectionQuerying: Use any? instead.
result[name] = value if name.length > 0 && value.length > 0
^^^^^^^^^^
./apps/discourse/lib/email/message_builder.rb:280:62: C: [Correctable] Style/CollectionQuerying: Use any? instead.
result[name] = value if name.length > 0 && value.length > 0
^^^^^^^^^^
./apps/discourse/lib/file_store/to_s3_migration.rb:281:17: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if failed.size > 0
^^^^^^^^
./apps/discourse/lib/freedom_patches/translate_accelerator.rb:223:51: C: [Correctable] Style/CollectionQuerying: Use one? instead.
no_options = options.empty? || (options.size == 1 && options.has_key?(:locale))
^^^^^^^^^
./apps/discourse/lib/gaps.rb:23:13: C: [Correctable] Style/CollectionQuerying: Use none? instead.
@before.size == 0 && @after.size == 0
^^^^^^^^^
./apps/discourse/lib/gaps.rb:23:33: C: [Correctable] Style/CollectionQuerying: Use none? instead.
@before.size == 0 && @after.size == 0
^^^^^^^^^
./apps/discourse/lib/gaps.rb:37:24: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if current_gap.size > 0
^^^^^^^^
./apps/discourse/lib/guardian/topic_guardian.rb:300:31: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if allowed_category_ids.size == 0
^^^^^^^^^
./apps/discourse/lib/html_to_markdown.rb:313:45: C: [Correctable] Style/CollectionQuerying: Use any? instead.
suffix = node.ancestors("ul, ol, li").size > 0 ? "" : "\n"
^^^^^^^^
./apps/discourse/lib/i18n/backend/discourse_i18n.rb:114:39: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return result if result.size > 0
^^^^^^^^
./apps/discourse/lib/imap/providers/generic.rb:129:70: C: [Correctable] Style/CollectionQuerying: Use any? instead.
imap.uid_store(uid, "+#{attribute}", additions) if additions.length > 0
^^^^^^^^^^
./apps/discourse/lib/imap/providers/generic.rb:131:68: C: [Correctable] Style/CollectionQuerying: Use any? instead.
imap.uid_store(uid, "-#{attribute}", removals) if removals.length > 0
^^^^^^^^^^
./apps/discourse/lib/imap/sync.rb:331:18: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if to_sync.size > 0
^^^^^^^^
./apps/discourse/lib/imap/sync.rb:347:57: C: [Correctable] Style/CollectionQuerying: Use any? instead.
topic_is_archived = topic.group_archived_messages.size > 0
^^^^^^^^
./apps/discourse/lib/imap/sync.rb:370:61: C: [Correctable] Style/CollectionQuerying: Use any? instead.
tags.add("plus:#{plus_part[1..-1]}") if plus_part.length > 0
^^^^^^^^^^
./apps/discourse/lib/middleware/anonymous_cache.rb:354:34: C: [Correctable] Style/CollectionQuerying: Use any? instead.
env[Rack::RACK_INPUT].size > 0
^^^^^^^^
./apps/discourse/lib/middleware/omniauth_bypass_middleware.rb:33:80: C: [Correctable] Style/CollectionQuerying: Use one? instead.
!SiteSetting.enable_local_logins && Discourse.enabled_authenticators.length == 1
^^^^^^^^^^^
./apps/discourse/lib/middleware/request_tracker.rb:35:67: C: [Correctable] Style/CollectionQuerying: Use none? instead.
@detailed_request_loggers = nil if @@detailed_request_loggers.length == 0
^^^^^^^^^^^
./apps/discourse/lib/mini_sql_multisite_connection.rb:103:13: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if args.length > 0
^^^^^^^^^^
./apps/discourse/lib/new_post_manager.rb:226:18: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if matches.size == 1
^^^^^^^^^
./apps/discourse/lib/onebox/engine/wikipedia_onebox.rb:96:23: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if img && img.size > 0
^^^^^^^^
./apps/discourse/lib/onebox/mixins/git_blob_onebox.rb:123:51: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if m.nil? || l.size == m[0].size || l.size == 0
^^^^^^^^^
./apps/discourse/lib/onebox/mixins/github_body.rb:18:21: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if body.length == 0
^^^^^^^^^^^
./apps/discourse/lib/oneboxer.rb:580:29: C: [Correctable] Style/CollectionQuerying: Use one? instead.
unless error_keys.length == 1 && skip_if_only_error.include?(error_keys.first)
^^^^^^^^^^^
./apps/discourse/lib/onpdiff.rb:128:18: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if ses.size > 0 && ses[-1][1] == t
^^^^^^^^
./apps/discourse/lib/onpdiff.rb:137:18: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if ses.size > 0 && ses[-1][1] == t
^^^^^^^^
./apps/discourse/lib/onpdiff.rb:145:18: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if ses.size > 0 && ses[-1][1] == :common
^^^^^^^^
./apps/discourse/lib/post_revisor.rb:665:27: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if modifications.keys.size == 1 && (tags_diff = modifications["tags"]).present?
^^^^^^^^^
./apps/discourse/lib/pretty_text/helpers.rb:54:14: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if map.length > 0
^^^^^^^^^^
./apps/discourse/lib/s3_helper.rb:281:67: C: [Correctable] Style/CollectionQuerying: Use any? instead.
"Failed to download #{filename} because #{err.message.length > 0 ? err.message : err.class.to_s}"
^^^^^^^^^^
./apps/discourse/lib/sidekiq/pausable.rb:44:40: C: [Correctable] Style/CollectionQuerying: Use none? instead.
stop_extend_lease_thread if @dbs.size == 0
^^^^^^^^^
./apps/discourse/lib/site_settings/type_supervisor.rb:273:17: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if diff.length > 0
^^^^^^^^^^
./apps/discourse/lib/site_settings/validations.rb:42:53: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if (category_ids & default_categories_selected).size > 0
^^^^^^^^
./apps/discourse/lib/site_settings/validations.rb:113:90: C: [Correctable] Style/CollectionQuerying: Use any? instead.
validate_error :default_tags_already_selected if (tag_names & default_tags_selected).size > 0
^^^^^^^^
./apps/discourse/lib/stylesheet/watcher.rb:125:31: C: [Correctable] Style/CollectionQuerying: Use any? instead.
@queue.pop while @queue.length > 0
^^^^^^^^^^
./apps/discourse/lib/tasks/annotate.rake:10:23: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if non_core_plugins.length > 0
^^^^^^^^^^
./apps/discourse/lib/tasks/cdn.rake:46:20: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if failed_assets.length > 0
^^^^^^^^^^
./apps/discourse/lib/tasks/db.rake:187:21: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if exceptions.length > 0
^^^^^^^^^^
./apps/discourse/lib/tasks/db.rake:430:45: C: [Correctable] Style/CollectionQuerying: Use none? instead.
next if db_name != "default" && renames.length == 0 && missing.length == 0 && extra.length == 0
^^^^^^^^^^^
./apps/discourse/lib/tasks/db.rake:430:68: C: [Correctable] Style/CollectionQuerying: Use none? instead.
next if db_name != "default" && renames.length == 0 && missing.length == 0 && extra.length == 0
^^^^^^^^^^^
./apps/discourse/lib/tasks/db.rake:430:89: C: [Correctable] Style/CollectionQuerying: Use none? instead.
next if db_name != "default" && renames.length == 0 && missing.length == 0 && extra.length == 0
^^^^^^^^^^^
./apps/discourse/lib/tasks/db.rake:432:16: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if renames.length > 0
^^^^^^^^^^
./apps/discourse/lib/tasks/db.rake:452:16: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if missing.length > 0
^^^^^^^^^^
./apps/discourse/lib/tasks/db.rake:471:14: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if extra.length > 0
^^^^^^^^^^
./apps/discourse/lib/tasks/plugin.rake:198:12: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if files.length > 0
^^^^^^^^^^
./apps/discourse/lib/tasks/posts.rake:591:18: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if uploads.length > 0
^^^^^^^^^^
./apps/discourse/lib/tasks/posts.rake:607:29: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if raw.scan(upload).length == 0
^^^^^^^^^^^
./apps/discourse/lib/tasks/posts.rake:610:29: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if raw.scan(upload).length == 0
^^^^^^^^^^^
./apps/discourse/lib/tasks/posts.rake:613:80: C: [Correctable] Style/CollectionQuerying: Use none? instead.
upload = upload.sub(Discourse.base_url + "/", "/") if raw.scan(upload).length == 0
^^^^^^^^^^^
./apps/discourse/lib/tasks/posts.rake:614:29: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if raw.scan(upload).length == 0
^^^^^^^^^^^
./apps/discourse/lib/tasks/posts.rake:619:48: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if sha.length == 40 && raw.scan(sha).length == 1
^^^^^^^^^^^
./apps/discourse/lib/tasks/posts.rake:624:29: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if raw.scan(upload).length == 0
^^^^^^^^^^^
./apps/discourse/lib/tasks/posts.rake:631:47: C: [Correctable] Style/CollectionQuerying: Use any? instead.
lookup << [post_id, uploads] if uploads.length > 0
^^^^^^^^^^
./apps/discourse/lib/tasks/release_note.rake:102:21: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return if changes.length == 0
^^^^^^^^^^^
./apps/discourse/lib/tasks/s3.rake:221:23: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if assets_to_delete.size > 0
^^^^^^^^
./apps/discourse/lib/tasks/uploads.rake:345:41: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if downloaded && downloaded.size > 0
^^^^^^^^
./apps/discourse/lib/tasks/uploads.rake:379:22: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if missing_uploads.size > 0
^^^^^^^^
./apps/discourse/lib/temporary_db.rb:40:60: C: [Correctable] Style/CollectionQuerying: Use none? instead.
@initdb_path = "#{pg_bin_path}/initdb" if @initdb_path.length == 0
^^^^^^^^^^^
./apps/discourse/lib/temporary_db.rb:57:60: C: [Correctable] Style/CollectionQuerying: Use none? instead.
@pg_ctl_path = "#{pg_bin_path}/pg_ctl" if @pg_ctl_path.length == 0
^^^^^^^^^^^
./apps/discourse/lib/text_sentinel.rb:66:35: C: [Correctable] Style/CollectionQuerying: Use any? instead.
@text.gsub(symbols_regex, "").size > 0
^^^^^^^^
./apps/discourse/lib/theme_store/zip_importer.rb:35:19: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if root_files.size == 1 && File.directory?(root_files[0])
^^^^^^^^^
./apps/discourse/lib/tiny_japanese_segmenter.rb:1386:44: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return [] if text.nil? || text.strip.length == 0
^^^^^^^^^^^
./apps/discourse/lib/topic_query.rb:113:46: C: [Correctable] Style/CollectionQuerying: Use none? instead.
@custom_filters = nil if @custom_filters.length == 0
^^^^^^^^^^^
./apps/discourse/lib/topic_query.rb:1264:29: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if tags_arg && tags_arg.size > 0
^^^^^^^^
./apps/discourse/lib/topic_view.rb:14:34: C: [Correctable] Style/CollectionQuerying: Use none? instead.
@preload = nil if @preload.length == 0
^^^^^^^^^^^
./apps/discourse/lib/topic_view.rb:199:24: C: [Correctable] Style/CollectionQuerying: Use any? instead.
@page > 1 && posts.size > 0 ? @page - 1 : nil
^^^^^^^^
./apps/discourse/lib/topic_view.rb:313:85: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if desired_post.wiki && desired_post.post_number == 1 && desired_post.revisions.size > 0
^^^^^^^^
./apps/discourse/lib/truncate_logs_formatter.rb:16:15: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if args.length == 1
^^^^^^^^^^^
./apps/discourse/lib/validators/watched_words_validator.rb:6:18: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if matches.size == 1
^^^^^^^^^
./apps/discourse/lib/wizard.rb:47:15: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if @steps.size == 1
^^^^^^^^^
./apps/discourse/plugins/chat/app/services/chat/search_chatable.rb:88:38: C: [Correctable] Style/CollectionQuerying: Use one? instead.
channel.allowed_user_ids.length == 1 &&
^^^^^^^^^^^
./apps/discourse/plugins/chat/app/services/chat/search_chatable.rb:90:32: C: [Correctable] Style/CollectionQuerying: Use one? instead.
channel_user_ids.length == 1 && user_ids.include?(channel_user_ids.first)
^^^^^^^^^^^
./apps/discourse/plugins/chat/lib/chat/user_notifications_extension.rb:155:24: C: [Correctable] Style/CollectionQuerying: Use one? instead.
elsif channels.size == 1
^^^^^^^^^
./apps/discourse/plugins/chat/lib/chat/user_notifications_extension.rb:174:17: C: [Correctable] Style/CollectionQuerying: Use one? instead.
elsif dms.size == 1
^^^^^^^^^
./apps/discourse/plugins/discourse-local-dates/plugin.rb:32:48: C: [Correctable] Style/CollectionQuerying: Use any? instead.
next if cooked_date.ancestors("aside").length > 0
^^^^^^^^^^
./apps/discourse/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/advanced_user_narrative.rb:281:72: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if Nokogiri::HTML5.fragment(@post.cooked).css(".hashtag-cooked").size > 0
^^^^^^^^
./apps/discourse/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/advanced_user_narrative.rb:336:62: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if Nokogiri::HTML5.fragment(@post.cooked).css(".poll").size > 0
^^^^^^^^
./apps/discourse/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/advanced_user_narrative.rb:361:64: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if Nokogiri::HTML5.fragment(@post.cooked).css("details").size > 0
^^^^^^^^
./apps/discourse/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/new_user_narrative.rb:345:54: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if Nokogiri::HTML5.fragment(cooked).css("img").size > 0
^^^^^^^^
./apps/discourse/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/new_user_narrative.rb:433:13: C: [Correctable] Style/CollectionQuerying: Use any? instead.
.size > 0
^^^^^^^^
./apps/discourse/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/new_user_narrative.rb:461:28: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if doc.css(".quote").size > 0
^^^^^^^^
./apps/discourse/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/new_user_narrative.rb:489:28: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if doc.css(".emoji").size > 0
^^^^^^^^
./apps/discourse/plugins/poll/db/migrate/20180820080623_migrate_polls_data.rb:64:62: C: [Correctable] Style/CollectionQuerying: Use any? instead.
r.polls = r.polls[0] if Array === r.polls && r.polls.size > 0
^^^^^^^^
./apps/discourse/plugins/poll/db/migrate/20180820080623_migrate_polls_data.rb:65:62: C: [Correctable] Style/CollectionQuerying: Use any? instead.
r.votes = r.votes[0] if Array === r.votes && r.votes.size > 0
^^^^^^^^
./apps/discourse/plugins/poll/lib/polls_updater.rb:50:38: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if old_poll.poll_votes.size > 0
^^^^^^^^
./apps/discourse/plugins/poll/lib/tasks/migrate_old_polls.rake:49:43: C: [Correctable] Style/CollectionQuerying: Use none? instead.
next if lists.blank? || lists.length == 0
^^^^^^^^^^^
./apps/discourse/script/analyze_sidekiq_queues.rb:23:16: C: [Correctable] Style/CollectionQuerying: Use one? instead.
next if jobs.length == 1
^^^^^^^^^^^
./apps/discourse/script/bench.rb:152:69: C: [Correctable] Style/CollectionQuerying: Use any? instead.
discourse_env_vars.each { |w| puts "#{w}: #{ENV[w]}" if ENV[w].to_s.length > 0 }
^^^^^^^^^^
./apps/discourse/script/db_timestamps_mover.rb:144:12: C: [Correctable] Style/CollectionQuerying: Use one? instead.
elsif ARGV.length == 1 && is_i?(ARGV[0])
^^^^^^^^^^^
./apps/discourse/script/import_scripts/bespoke_1.rb:51:14: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if users.length > 0
^^^^^^^^^^
./apps/discourse/script/import_scripts/bespoke_1.rb:249:16: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if posts.length > 0 && posts.length % BATCH_SIZE == 0
^^^^^^^^^^
./apps/discourse/script/import_scripts/bespoke_1.rb:254:80: C: [Correctable] Style/CollectionQuerying: Use any? instead.
import_post_batch!(posts, topic_map, count - posts.length, total) if posts.length > 0
^^^^^^^^^^
./apps/discourse/script/import_scripts/discuz_x.rb:889:38: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return discuzx_link if results.size.zero?
^^^^^^^^^^
./apps/discourse/script/import_scripts/disqus.rb:196:20: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if t[:posts].size == 0
^^^^^^^^^
./apps/discourse/script/import_scripts/google_groups.rb:100:27: C: [Correctable] Style/CollectionQuerying: Use none? instead.
break if topic_urls.size == 0
^^^^^^^^^
./apps/discourse/script/import_scripts/ipboard.rb:221:59: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if user["avatar_url"] && user["avatar_url"].length > 0
^^^^^^^^^^
./apps/discourse/script/import_scripts/ipboard.rb:785:28: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if content_class.length > 0 && content_class != "forums_Topic"
^^^^^^^^^^
./apps/discourse/script/import_scripts/ipboard.rb:788:27: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if content_type.length > 0 && content_type != "forums"
^^^^^^^^^^
./apps/discourse/script/import_scripts/ipboard.rb:933:28: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if content_class.length > 0 && content_class != "forums_Topic"
^^^^^^^^^^
./apps/discourse/script/import_scripts/ipboard.rb:936:27: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if content_type.length > 0 && content_type != "forums"
^^^^^^^^^^
./apps/discourse/script/import_scripts/jforum.rb:588:33: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return rows if last_columns.length == 0
^^^^^^^^^^^
./apps/discourse/script/import_scripts/jive.rb:54:14: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if users.length > 0
^^^^^^^^^^
./apps/discourse/script/import_scripts/jive.rb:383:18: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if posts.length > 0 && posts.length % BATCH_SIZE == 0
^^^^^^^^^^
./apps/discourse/script/import_scripts/jive.rb:389:80: C: [Correctable] Style/CollectionQuerying: Use any? instead.
import_post_batch!(posts, topic_map, count - posts.length, total) if posts.length > 0
^^^^^^^^^^
./apps/discourse/script/import_scripts/phpbb3/database/database_base.rb:19:35: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return rows if last_columns.length == 0
^^^^^^^^^^^
./apps/discourse/script/import_scripts/phpbb3/support/bbcode/xml_to_markdown.rb:116:76: C: [Correctable] Style/CollectionQuerying: Use none? instead.
md_node.prefix_linebreaks = md_node.postfix_linebreaks = @list_stack.size == 0 ? 2 : 1
^^^^^^^^^
./apps/discourse/script/import_scripts/phpbb3/support/bbcode/xml_to_markdown.rb:117:69: C: [Correctable] Style/CollectionQuerying: Use none? instead.
md_node.prefix_linebreak_type = LINEBREAK_HTML if @list_stack.size == 0
^^^^^^^^^
./apps/discourse/script/import_scripts/quandora/quandora_question.rb:63:68: C: [Correctable] Style/CollectionQuerying: Use any? instead.
p[:reply_to_post_number] = parent[0][:post_number] if parent.size > 0
^^^^^^^^
./apps/discourse/script/import_scripts/sourceforge.rb:71:23: C: [Correctable] Style/CollectionQuerying: Use none? instead.
next if posts.size == 0
^^^^^^^^^
./apps/discourse/script/import_scripts/telligent.rb:802:10: C: [Correctable] Style/CollectionQuerying: Use one? instead.
keys.size == 1 ? File.join(@filestore_root_directory, @files[keys.first]) : nil
^^^^^^^^^
./apps/discourse/script/import_scripts/vbulletin.rb:194:35: C: [Correctable] Style/CollectionQuerying: Use none? instead.
next if user_ids_in_group.size == 0
^^^^^^^^^
./apps/discourse/script/import_scripts/xenforo.rb:350:30: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if to_user_array.size > 0
^^^^^^^^
./apps/discourse/script/memstats.rb:104:69: C: [Correctable] Style/CollectionQuerying: Use any? instead.
mappings << consume_mapping(map_lines, totals) if map_lines.size > 0
^^^^^^^^
./apps/discourse/script/promote_migrations:30:55: C: [Correctable] Style/CollectionQuerying: Use any? instead.
raise "Unknown arguments: #{ARGV.join(', ')}" if ARGV.length > 0
^^^^^^^^^^
./apps/discourse/script/promote_migrations:79:28: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if current_post_migrations.length == 0
^^^^^^^^^^^
./apps/discourse/spec/lib/scheduler/defer_spec.rb:31:28: C: [Correctable] Style/CollectionQuerying: Use none? instead.
wait_for(200) { @defer.length == 0 }
^^^^^^^^^^^
./apps/discourse/spec/lib/scheduler/defer_spec.rb:62:34: C: [Correctable] Style/CollectionQuerying: Use one? instead.
wait_for(200) { l.errors.length == 1 }
^^^^^^^^^^^
./apps/discourse/spec/lib/signal_trap_logger_spec.rb:15:37: C: [Correctable] Style/CollectionQuerying: Use one? instead.
wait_for { fake_logger.errors.size == 1 && fake_logger.infos.size == 1 }
^^^^^^^^^
./apps/discourse/spec/lib/signal_trap_logger_spec.rb:15:68: C: [Correctable] Style/CollectionQuerying: Use one? instead.
wait_for { fake_logger.errors.size == 1 && fake_logger.infos.size == 1 }
^^^^^^^^^
./apps/gitlabhq/app/finders/snippets_finder.rb:254:37: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return queries.first if queries.length == 1
^^^^^^^^^^^
./apps/gitlabhq/app/graphql/mutations/packages/destroy_files.rb:44:28: C: [Correctable] Style/CollectionQuerying: Use one? instead.
unless project_ids.size == 1 && project_ids.include?(project.id)
^^^^^^^^^
./apps/gitlabhq/app/graphql/resolvers/concerns/caching_array_resolver.rb:57:15: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if keys.size == 1
^^^^^^^^^
./apps/gitlabhq/app/graphql/resolvers/design_management/version/design_at_version_resolver.rb:49:28: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return if passed.size == 1
^^^^^^^^^
./apps/gitlabhq/app/graphql/types/deployments_order_by_input_type.rb:19:103: C: [Correctable] Style/CollectionQuerying: Use one? instead.
raise GraphQL::ExecutionError, 'orderBy parameter must contain one key-value pair.' unless to_h.size == 1
^^^^^^^^^
./apps/gitlabhq/app/helpers/markup_helper.rb:32:26: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if fragment.children.size == 1 && fragment.children[0].name == 'a'
^^^^^^^^^
./apps/gitlabhq/app/models/ci/runner.rb:588:32: C: [Correctable] Style/CollectionQuerying: Use one? instead.
unless runner_namespaces.size == 1
^^^^^^^^^
./apps/gitlabhq/app/models/concerns/has_wiki_page_meta_attributes.rb:134:63: C: [Correctable] Style/CollectionQuerying: Use one? instead.
slugs.insert_all(slug_attrs) unless !is_new && slug_attrs.size == 1
^^^^^^^^^
./apps/gitlabhq/app/models/concerns/has_wiki_page_meta_attributes.rb:136:59: C: [Correctable] Style/CollectionQuerying: Use one? instead.
@canonical_slug = canonical_slug if is_new || strings.size == 1 # rubocop:disable Gitlab/ModuleWithInstanceVariables
^^^^^^^^^
./apps/gitlabhq/app/models/deploy_key.rb:42:31: C: [Correctable] Style/CollectionQuerying: Use one? instead.
self.deploy_keys_projects.size == 1
^^^^^^^^^
./apps/gitlabhq/app/models/group.rb:577:16: C: [Correctable] Style/CollectionQuerying: Use one? instead.
all_owners.size == 1 && all_owners.first.user_id == user.id
^^^^^^^^^
./apps/gitlabhq/app/models/members/last_group_owner_assigner.rb:11:34: C: [Correctable] Style/CollectionQuerying: Use one? instead.
@group_single_owner = owners.size == 1
^^^^^^^^^
./apps/gitlabhq/app/models/onboarding/progress.rb:48:18: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if actions.size == 1
^^^^^^^^^
./apps/gitlabhq/app/models/repository.rb:155:34: C: [Correctable] Style/CollectionQuerying: Use one? instead.
follow: Array(opts[:path]).length == 1 && Feature.disabled?(:remove_file_commit_history_following, type: :ops),
^^^^^^^^^^^
./apps/gitlabhq/app/services/ci/components/usages/create_service.rb:27:23: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if errors.size == 1 && errors.first.type == :taken # Only unique validation failed
^^^^^^^^^
./apps/gitlabhq/app/services/ci/find_exposed_artifacts_service.rb:69:15: C: [Correctable] Style/CollectionQuerying: Use one? instead.
entries.size == 1 && entries.first.file?
^^^^^^^^^
./apps/gitlabhq/config/initializers/remove_active_job_execute_callback.rb:17:32: C: [Correctable] Style/CollectionQuerying: Use one? instead.
callbacks.send(:chain).size == 1 &&
^^^^^^^^^
./apps/gitlabhq/config/initializers/wikicloth_ruby_3_patch.rb:127:33: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if p !~ /=/ && temp.length == 1 && p == params.last
^^^^^^^^^^^
./apps/gitlabhq/config/initializers/wikicloth_ruby_3_patch.rb:215:52: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return elem.tag!(params.first) if params.length == 1
^^^^^^^^^^^
./apps/gitlabhq/gems/gitlab-housekeeper/lib/gitlab/housekeeper/gitlab_client.rb:120:107: C: [Correctable] Style/CollectionQuerying: Use one? instead.
raise Error, "More than one matching MR exists: iids: #{data.pluck('iid').join(',')}" unless data.size == 1
^^^^^^^^^
./apps/gitlabhq/lib/api/ml/mlflow/api_helpers.rb:69:36: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if order_by_column_split.size == 1
^^^^^^^^^
./apps/gitlabhq/lib/banzai/filter/gollum_tags_filter.rb:65:18: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if parts.size == 1
^^^^^^^^^
./apps/gitlabhq/lib/gitlab/changelog/release.rb:101:40: C: [Correctable] Style/CollectionQuerying: Use one? instead.
'single_change' => entries.length == 1,
^^^^^^^^^^^
./apps/gitlabhq/lib/gitlab/database/migrations/sidekiq_helpers.rb:135:25: C: [Correctable] Style/CollectionQuerying: Use one? instead.
(src_stores.size == 1 && dst_stores.size == 1 && src_stores.first == dst_stores.first)
^^^^^^^^^
./apps/gitlabhq/lib/gitlab/database/migrations/sidekiq_helpers.rb:135:49: C: [Correctable] Style/CollectionQuerying: Use one? instead.
(src_stores.size == 1 && dst_stores.size == 1 && src_stores.first == dst_stores.first)
^^^^^^^^^
./apps/gitlabhq/lib/gitlab/fp/rop_helpers.rb:26:72: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return public_singleton_methods[0] if public_singleton_methods.size == 1
^^^^^^^^^
./apps/gitlabhq/lib/gitlab/git/diff_collection.rb:161:19: C: [Correctable] Style/CollectionQuerying: Use one? instead.
@iterator.size == 1 || !@enforce_limits || @expanded
^^^^^^^^^
./apps/gitlabhq/lib/gitlab/graphql/validators/exactly_one_of_validator.rb:14:72: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return if args.slice(*@mutually_exclusive_arg_names).compact.size == 1
^^^^^^^^^
./apps/gitlabhq/lib/gitlab/instrumentation/redis_cluster_validator.rb:191:30: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return if commands.size == 1 && REDIS_COMMANDS.dig(command_name, :single_key)
^^^^^^^^^
./apps/gitlabhq/lib/gitlab/pagination/keyset.rb:18:38: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return false unless order_by.size == 1 && order_by[:id]
^^^^^^^^^
./apps/gitlabhq/lib/gitlab/slash_commands/global_slack_handler.rb:66:21: C: [Correctable] Style/CollectionQuerying: Use one? instead.
fragments.size == 1 ? [nil, fragments.first] : fragments
^^^^^^^^^
./apps/gitlabhq/lib/kramdown/converter/commonmark.rb:45:26: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if el.children.size == 1 && @stack.last.children.last == el &&
^^^^^^^^^
./apps/gitlabhq/lib/kramdown/converter/commonmark.rb:46:102: C: [Correctable] Style/CollectionQuerying: Use one? instead.
(@stack.last.children.any? { |c| c.children.first.type != :p } || @stack.last.children.size == 1)
^^^^^^^^^
./apps/gitlabhq/lib/tasks/gitlab/db.rake:103:31: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if databases_with_tasks.size == 1
^^^^^^^^^
./apps/gitlabhq/qa/qa/resource/project.rb:420:49: C: [Correctable] Style/CollectionQuerying: Use one? instead.
next unless result.present? && result.size == 1
^^^^^^^^^
./apps/gitlabhq/qa/qa/resource/user.rb:236:22: C: [Correctable] Style/CollectionQuerying: Use one? instead.
unless users.size == 1 && users.first[:username] == username
^^^^^^^^^
./apps/gitlabhq/qa/qa/specs/features/api/1_manage/migration/gitlab_migration_large_project_spec.rb:39:31: C: [Correctable] Style/CollectionQuerying: Use one? instead.
next sandbox if paths.size == 1
^^^^^^^^^
./apps/gitlabhq/qa/qa/specs/features/api/4_verify/api_variable_inheritance_with_forward_pipeline_variables_spec.rb:34:38: C: [Correctable] Style/CollectionQuerying: Use one? instead.
upstream_project.pipelines.size == 1 && upstream_pipeline.status == 'success'
^^^^^^^^^
./apps/gitlabhq/qa/qa/specs/features/browser_ui/4_verify/ci_variable/prefill_variables_spec.rb:43:95: C: [Correctable] Style/CollectionQuerying: Use one? instead.
Support::Waiter.wait_until(message: 'Wait for pipeline creation') { project.pipelines.length == 1 }
^^^^^^^^^^^
./apps/gitlabhq/qa/qa/specs/features/browser_ui/4_verify/pipeline/update_ci_file_with_pipeline_editor_spec.rb:30:106: C: [Correctable] Style/CollectionQuerying: Use one? instead.
Support::Waiter.wait_until(message: 'Wait for first pipeline to be created') { project.pipelines.size == 1 }
^^^^^^^^^
./apps/gitlabhq/qa/qa/support/json_formatter.rb:83:18: C: [Correctable] Style/CollectionQuerying: Use one? instead.
modified.size == 1 ? modified[0] : modified
^^^^^^^^^
./apps/gitlabhq/qa/qa/tools/generate_import_test_group.rb:98:42: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return @group = sandbox if paths.size == 1
^^^^^^^^^
./apps/gitlabhq/rubocop/cop/migration/complex_indexes_require_name.rb:56:24: C: [Correctable] Style/CollectionQuerying: Use one? instead.
option_nodes.size == 1 && unique_option?(option_nodes.first)
^^^^^^^^^
./apps/gitlabhq/scripts/internal_events/cli/helpers/metric_options.rb:56:46: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return events.first.action if events.length == 1
^^^^^^^^^^^
./apps/gitlabhq/scripts/internal_events/cli/metric_definer.rb:215:41: C: [Correctable] Style/CollectionQuerying: Use one? instead.
next unless values.compact.uniq.length == 1
^^^^^^^^^^^
./apps/gitlabhq/scripts/lib/glfm/parse_examples.rb:110:22: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if headers.length == 1 && line =~ h3_regex
^^^^^^^^^^^
./apps/gitlabhq/spec/lib/banzai/filter/escaped_char_filter_spec.rb:12:42: C: [Correctable] Style/CollectionQuerying: Use one? instead.
next unless klass.reference_prefix.length == 1
^^^^^^^^^^^
./apps/gitlabhq/spec/lib/banzai/pipeline/plain_markdown_pipeline_spec.rb:47:44: C: [Correctable] Style/CollectionQuerying: Use one? instead.
next unless klass.reference_prefix.length == 1
^^^^^^^^^^^
./apps/gitlabhq/spec/requests/api/graphql/mutations/admin/sidekiq_queues/delete_jobs_spec.rb:49:62: C: [Correctable] Style/CollectionQuerying: Use none? instead.
raise 'Not enqueued!' if Sidekiq::Queue.new(queue).size.zero? # rubocop:disable Style/ZeroLengthPredicate -- Sidekiq::Queue doesn't implement #blank? or #empty?
^^^^^^^^^^
./apps/gitlabhq/spec/support/formatters/json_formatter.rb:105:18: C: [Correctable] Style/CollectionQuerying: Use one? instead.
modified.size == 1 ? modified[0] : modified
^^^^^^^^^
./apps/gitlabhq/spec/support/helpers/javascript_fixtures_helpers.rb:53:16: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if queries.length == 1
^^^^^^^^^^^
./apps/gitlabhq/spec/support/matchers/background_migrations_matchers.rb:33:26: C: [Correctable] Style/CollectionQuerying: Use one? instead.
args = job['args'].size == 1 ? [BackgroundMigrationWorker.jobs[0]['args'][0], []] : job['args']
^^^^^^^^^
./apps/gitlabhq/spec/support/matchers/background_migrations_matchers.rb:48:26: C: [Correctable] Style/CollectionQuerying: Use one? instead.
args = job['args'].size == 1 ? [BackgroundMigrationWorker.jobs[0]['args'][0], []] : job['args']
^^^^^^^^^
./apps/gitlabhq/tooling/danger/stable_branch.rb:142:48: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return false unless categories_changed.size == 1
^^^^^^^^^
./apps/gitlabhq/vendor/gems/diff_match_patch/lib/diff_match_patch.rb:116:18: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if shorttext.length == 1
^^^^^^^^^^^
./apps/gitlabhq/vendor/gems/diff_match_patch/lib/diff_match_patch.rb:1318:16: C: [Correctable] Style/CollectionQuerying: Use one? instead.
elsif args.length == 1 && args[0].is_a?(Array)
^^^^^^^^^^^
./apps/gitlabhq/vendor/gems/diff_match_patch/lib/diff_match_patch.rb:1576:53: C: [Correctable] Style/CollectionQuerying: Use one? instead.
elsif diff[0] == :delete && patch.diffs.length == 1 &&
^^^^^^^^^^^
./apps/gitlabhq/vendor/gems/sidekiq-7.1.6/bin/sidekiqmon:9:27: C: [Correctable] Style/CollectionQuerying: Use one? instead.
section = ARGV[0] if ARGV.size == 1
^^^^^^^^^
./apps/gitlabhq/vendor/gems/sidekiq-7.1.6/lib/sidekiq/api.rb:490:12: C: [Correctable] Style/CollectionQuerying: Use one? instead.
hash.size == 1 && hash.include?(GLOBALID_KEY)
^^^^^^^^^
./apps/gitlabhq/vendor/gems/sidekiq-7.1.6/lib/sidekiq/api.rb:578:20: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if results.size == 1
^^^^^^^^^
./apps/gitlabhq/vendor/gems/sidekiq-7.1.6/lib/sidekiq/client.rb:46:15: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if args.size == 1 && kwargs.size == 0
^^^^^^^^^
./apps/gitlabhq/vendor/gems/sidekiq-7.1.6/lib/sidekiq/client.rb:46:35: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if args.size == 1 && kwargs.size == 0
^^^^^^^^^
./apps/gitlabhq/vendor/gems/sidekiq-7.1.6/lib/sidekiq/config.rb:268:36: C: [Correctable] Style/CollectionQuerying: Use none? instead.
if @options[:error_handlers].size == 0
^^^^^^^^^
./apps/gitlabhq/vendor/gems/sidekiq-7.1.6/lib/sidekiq/manager.rb:95:18: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if cleanup.size > 0
^^^^^^^^
./apps/gitlabhq/vendor/gems/sidekiq-7.1.6/lib/sidekiq/metrics/tracking.rb:71:20: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if grams.size > 0
^^^^^^^^
./apps/gitlabhq/vendor/gems/sidekiq-7.1.6/lib/sidekiq/web/helpers.rb:209:16: C: [Correctable] Style/CollectionQuerying: Use none? instead.
(workset.size == 0) ? "idle" : "active"
^^^^^^^^^
./apps/gitlabhq/vendor/gems/sidekiq-7.1.6/test/sidekiq_test.rb:85:114: C: [Correctable] Style/CollectionQuerying: Use one? instead.
raise Sidekiq::RedisClientAdapter::CommandError, "READONLY You can't write against a replica." if counts.size == 1
^^^^^^^^^
./apps/gitlabhq/vendor/gems/sidekiq-7.1.6/test/sidekiq_test.rb:95:163: C: [Correctable] Style/CollectionQuerying: Use one? instead.
raise Sidekiq::RedisClientAdapter::CommandError, "UNBLOCKED force unblock from blocking operation, instance state changed (master -> replica?)" if counts.size == 1
^^^^^^^^^
./apps/openproject/app/components/application_component.rb:55:16: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if names.size == 1 && names.first.is_a?(Hash)
^^^^^^^^^
./apps/openproject/app/contracts/user_preferences/base_contract.rb:81:23: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if time_zones.length == 1
^^^^^^^^^^^
./apps/openproject/app/controllers/activities_controller.rb:120:27: C: [Correctable] Style/CollectionQuerying: Use one? instead.
elsif @activity.scope.size == 1
^^^^^^^^^
./apps/openproject/app/controllers/application_controller.rb:344:45: C: [Correctable] Style/CollectionQuerying: Use one? instead.
@project = @projects.first if @projects.size == 1
^^^^^^^^^
./apps/openproject/app/controllers/members_controller.rb:210:16: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if members.size == 1
^^^^^^^^^
./apps/openproject/app/helpers/members_helper.rb:36:21: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if member.roles.length == 1
^^^^^^^^^^^
./apps/openproject/app/helpers/repositories_helper.rb:111:10: C: [Correctable] Style/CollectionQuerying: Use one? instead.
seen.size == 1 ? seen.first : :open
^^^^^^^^^
./apps/openproject/app/models/custom_actions/actions/strategies/validate_in_range.rb:46:34: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return unless values.compact.length == 1
^^^^^^^^^^^
./apps/openproject/app/models/queries/work_packages/filter/shared_with_user_filter.rb:108:21: C: [Correctable] Style/CollectionQuerying: Use one? instead.
values_replaced.size == 1 && values_replaced.first == User.current.id.to_s
^^^^^^^^^
./apps/openproject/app/models/work_package/pdf_export/gantt/gantt_builder.rb:69:31: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if page_groups[0].pages.length == 1
^^^^^^^^^^^
./apps/openproject/app/models/work_package/pdf_export/overview_table.rb:114:16: C: [Correctable] Style/CollectionQuerying: Use one? instead.
elsif list.length == 1
^^^^^^^^^^^
./apps/openproject/app/models/work_package/pdf_export/work_package_list_to_pdf.rb:139:42: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return batch_files[0] if batch_files.length == 1
^^^^^^^^^^^
./apps/openproject/app/validators/json_validator.rb:100:13: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if path.length == 1
^^^^^^^^^^^
./apps/openproject/app/validators/json_validator.rb:108:13: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if path.length == 1
^^^^^^^^^^^
./apps/openproject/app/validators/json_validator.rb:116:13: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if path.length == 1
^^^^^^^^^^^
./apps/openproject/app/validators/json_validator.rb:124:13: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if path.length == 1
^^^^^^^^^^^
./apps/openproject/app/workers/work_packages/bulk_job.rb:87:43: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if call.success? && work_packages.size == 1
^^^^^^^^^
./apps/openproject/lib/api/open_api.rb:58:15: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if spec.size == 1 && spec.keys.first == "$ref"
^^^^^^^^^
./apps/openproject/lib/api/open_api.rb:82:15: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if spec.size == 1 && spec.keys.first == "$ref"
^^^^^^^^^
./apps/openproject/lib/open_project/text_formatting/filters/table_of_contents_filter.rb:93:24: C: [Correctable] Style/CollectionQuerying: Use any? instead.
while headings.length > 0
^^^^^^^^^^
./apps/openproject/lib/redmine/menu_manager/menu_helper.rb:447:27: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if @hidden_menu_items.length.positive?
^^^^^^^^^^^^^^^^
./apps/openproject/lib/redmine/plugin.rb:250:104: C: [Correctable] Style/CollectionQuerying: Use one? instead.
raise ArgumentError.new("wrong number of versions (#{versions.size} for 1)") unless versions.size == 1
^^^^^^^^^
./apps/openproject/lib/redmine/unified_diff.rb:52:44: C: [Correctable] Style/CollectionQuerying: Use any? instead.
self << diff_table if diff_table.length > 0
^^^^^^^^^^
./apps/openproject/lib/tasks/parallel_testing.rake:107:64: C: [Correctable] Style/CollectionQuerying: Use any? instead.
group_options += " -o '#{rspec_options}'" if rspec_options.length.positive?
^^^^^^^^^^^^^^^^
./apps/openproject/modules/backlogs/app/models/story.rb:43:59: C: [Correctable] Style/CollectionQuerying: Use any? instead.
last_rank = if stories_by_version[story.version_id].size > 0
^^^^^^^^
./apps/openproject/modules/backlogs/app/models/story.rb:154:15: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if extras.size > 0
^^^^^^^^
./apps/openproject/modules/bim/lib/open_project/bim/bcf_json/faster_converter.rb:78:15: C: [Correctable] Style/CollectionQuerying: Use one? instead.
array.size == 1 && array[0].is_a?(Hash)
^^^^^^^^^
./apps/openproject/modules/bim/spec/lib/open_project/bcf/bcf_xml/viewpoint_writer_spec.rb:49:18: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if results.length > 0
^^^^^^^^^^
./apps/openproject/modules/budgets/app/controllers/budgets_controller.rb:213:17: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if projects.size == 1
^^^^^^^^^
./apps/openproject/modules/costs/app/models/rate.rb:121:13: C: [Correctable] Style/CollectionQuerying: Use one? instead.
dates.size == 1 ? dates.first : dates.sort
^^^^^^^^^
./apps/openproject/modules/reporting/lib/report/filter/base.rb:190:51: C: [Correctable] Style/CollectionQuerying: Use one? instead.
query_values.unshift nil if Array(values).size == 1 && Array(values).first.nil?
^^^^^^^^^
./apps/openproject/modules/reporting/lib/report/operator.rb:118:19: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if values.size == 1 && values.first.nil?
^^^^^^^^^
./apps/openproject/modules/reporting/lib/report/result.rb:246:51: C: [Correctable] Style/CollectionQuerying: Use any? instead.
to_evaluate_soon.concat r.values if r.size > 0
^^^^^^^^
./apps/openproject/modules/xls_export/app/models/xls_export/work_package/exporter/xls.rb:87:20: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if relatives.size > 0
^^^^^^^^
./apps/openproject/script/i18n/generate_languages_translations:96:37: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return variations if variations.length == 1
^^^^^^^^^^^
./apps/openproject/spec/models/type/attribute_groups_spec.rb:153:45: C: [Correctable] Style/CollectionQuerying: Use none? instead.
group_members.nil? || group_members.size.zero?
^^^^^^^^^^
./apps/openproject/spec/models/work_package/work_package_custom_fields_spec.rb:339:68: C: [Correctable] Style/CollectionQuerying: Use any? instead.
work_package.journals.find { |j| j.customizable_journals.size > 0 }
^^^^^^^^
./apps/openproject/spec/support/components/work_packages/destroy_modal.rb:42:18: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if wps.length == 1
^^^^^^^^^^^
./apps/openproject/spec/support/pages/projects/index.rb:251:21: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if values.size == 1
^^^^^^^^^
./apps/openproject/spec/support/shared/cuprite_helpers.rb:57:37: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return unless input_element.value.length.positive?
^^^^^^^^^^^^^^^^
./apps/canvas-lms/app/controllers/appointment_groups_controller.rb:373:52: C: [Correctable] Style/CollectionQuerying: Use one? instead.
shard = context_shards.first if context_shards.size == 1
^^^^^^^^^
./apps/canvas-lms/app/controllers/calendar_events_api_controller.rb:1665:38: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return last_scope if collections.length == 1
^^^^^^^^^^^
./apps/canvas-lms/app/controllers/collaborations_controller.rb:154:56: C: [Correctable] Style/CollectionQuerying: Use one? instead.
@etherpad_only = Collaboration.collaboration_types.length == 1 &&
^^^^^^^^^^^
./apps/canvas-lms/app/controllers/conferences_controller.rb:352:20: C: [Correctable] Style/CollectionQuerying: Use one? instead.
elsif urls.size == 1
^^^^^^^^^
./apps/canvas-lms/app/controllers/courses_controller.rb:3051:56: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if params[:course][:event] && params[:course].keys.size == 1
^^^^^^^^^
./apps/canvas-lms/app/controllers/courses_controller.rb:3199:40: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if color.strip.empty? || color.length == 1
^^^^^^^^^^^
./apps/canvas-lms/app/controllers/discussion_topics_controller.rb:782:27: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if topics && topics.length == 1 && [email protected]_right?(@current_user, session, :update)
^^^^^^^^^^^
./apps/canvas-lms/app/controllers/discussion_topics_controller.rb:898:29: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if topics && topics.length == 1 && [email protected]_right?(@current_user, session, :update)
^^^^^^^^^^^
./apps/canvas-lms/app/controllers/lti/ims/deep_linking_controller.rb:43:68: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if for_placement?(:link_selection) && lti_resource_links.length == 1 && !add_assignment?
^^^^^^^^^^^
./apps/canvas-lms/app/controllers/quizzes/quiz_reports_controller.rb:263:21: C: [Correctable] Style/CollectionQuerying: Use one? instead.
(serialized_set.length == 1) ? serialized_set[0] : serialized_set
^^^^^^^^^^^
./apps/canvas-lms/app/controllers/sub_accounts_controller.rb:72:52: C: [Correctable] Style/CollectionQuerying: Use one? instead.
redirect_to @accounts.first if @accounts.length == 1
^^^^^^^^^^^
./apps/canvas-lms/app/graphql/mutations/import_outcomes.rb:203:39: C: [Correctable] Style/CollectionQuerying: Use one? instead.
common_ancestors = if group_ids.size == 1
^^^^^^^^^
./apps/canvas-lms/app/graphql/types/conversation_message_type.rb:40:21: C: [Correctable] Style/CollectionQuerying: Use one? instead.
unless cmps.size == 1
^^^^^^^^^
./apps/canvas-lms/app/helpers/application_helper.rb:1014:24: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if courses.length == 1
^^^^^^^^^^^
./apps/canvas-lms/app/helpers/conversations_helper.rb:109:17: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if audience.size == 1 && include_private_conversation_enrollments
^^^^^^^^^
./apps/canvas-lms/app/helpers/cyoe_helper.rb:93:58: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if !data[:awaiting_choice] && data[:assignment_sets].length == 1
^^^^^^^^^^^
./apps/canvas-lms/app/helpers/rrule_helper.rb:137:128: C: [Correctable] Style/CollectionQuerying: Use one? instead.
raise RruleValidationError, I18n.t("Unsupported BYMONTHDAY, only a single day is permitted.") unless bymonthday.split(",").length == 1
^^^^^^^^^^^
./apps/canvas-lms/app/helpers/rrule_helper.rb:318:24: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if days_of_month.length == 1
^^^^^^^^^^^
./apps/canvas-lms/app/helpers/rrule_helper.rb:340:24: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if days_of_month.length == 1
^^^^^^^^^^^
./apps/canvas-lms/app/models/account.rb:1164:48: C: [Correctable] Style/CollectionQuerying: Use one? instead.
new_row = new_row.first if new_row.length == 1
^^^^^^^^^^^
./apps/canvas-lms/app/models/account.rb:2427:58: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return super unless where_clause.send(:predicates).length == 1
^^^^^^^^^^^
./apps/canvas-lms/app/models/account.rb:2430:38: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return super unless predicates.length == 1
^^^^^^^^^^^
./apps/canvas-lms/app/models/account/settings_wrapper.rb:31:10: C: [Correctable] Style/CollectionQuerying: Use any? instead.
keys.length.positive? ? self[base]&.dig(*keys) : self[base]
^^^^^^^^^^^^^^^^
./apps/canvas-lms/app/models/appointment_group.rb:132:24: C: [Correctable] Style/CollectionQuerying: Use one? instead.
@new_contexts.size == 1 &&
^^^^^^^^^
./apps/canvas-lms/app/models/appointment_group.rb:133:33: C: [Correctable] Style/CollectionQuerying: Use one? instead.
@new_sub_context_codes.size == 1 &&
^^^^^^^^^
./apps/canvas-lms/app/models/appointment_group.rb:174:88: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if @new_contexts.present? && !((appointment_group_sub_contexts + new_sub_contexts).size == 1 &&
^^^^^^^^^
./apps/canvas-lms/app/models/asset_user_access.rb:263:69: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return (view_delta[0] - 1.0).abs < Float::EPSILON if view_delta.size == 1
^^^^^^^^^
./apps/canvas-lms/app/models/authentication_provider/google.rb:87:37: C: [Correctable] Style/CollectionQuerying: Use one? instead.
result[:hd] = (hosted_domains.length == 1) ? hosted_domain : "*"
^^^^^^^^^^^
./apps/canvas-lms/app/models/authentication_provider/saml.rb:266:89: C: [Correctable] Style/CollectionQuerying: Use one? instead.
raise "Must provide exactly one IDPSSODescriptor; found #{idps.length}" unless idps.length == 1
^^^^^^^^^^^
./apps/canvas-lms/app/models/authentication_provider/saml.rb:275:27: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if recognized_formats.length == 1
^^^^^^^^^^^
./apps/canvas-lms/app/models/calendar_event.rb:204:48: C: [Correctable] Style/CollectionQuerying: Use one? instead.
next merge(or_clauses.first) if or_clauses.length == 1
^^^^^^^^^^^
./apps/canvas-lms/app/models/conditional_release/override_handler.rb:66:23: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if new_sets.length == 1 # otherwise they have to choose between sets
^^^^^^^^^^^
./apps/canvas-lms/app/models/conditional_release/service.rb:158:38: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if assignment_sets.length == 1
^^^^^^^^^^^
./apps/canvas-lms/app/models/content_tag.rb:144:12: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if ids.length == 1
^^^^^^^^^^^
./apps/canvas-lms/app/models/context.rb:430:42: C: [Correctable] Style/CollectionQuerying: Use one? instead.
final_scope = scopes.first if scopes.length == 1
^^^^^^^^^^^
./apps/canvas-lms/app/models/conversation.rb:743:35: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if private? && participants.size == 1
^^^^^^^^^
./apps/canvas-lms/app/models/conversation_participant.rb:128:63: C: [Correctable] Style/CollectionQuerying: Use one? instead.
shard_conditions = if options[:mode] == :or || user_ids.size == 1
^^^^^^^^^
./apps/canvas-lms/app/models/course_pace.rb:204:69: C: [Correctable] Style/CollectionQuerying: Use one? instead.
elsif current_override&.assignment_override_students&.size == 1
^^^^^^^^^
./apps/canvas-lms/app/models/lti/line_item.rb:125:24: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return if ids.uniq.size == 1 && ids.first == assignment_id
^^^^^^^^^
./apps/canvas-lms/app/models/master_courses/master_template.rb:143:23: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return if courses.length == 1 # not worth preloading for 1; let the cache be used
^^^^^^^^^^^
./apps/canvas-lms/app/models/pseudonym.rb:709:36: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if pseudonyms.map(&:user).uniq.length == 1 || site_admin
^^^^^^^^^^^
./apps/canvas-lms/app/models/release_note.rb:264:33: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return nil unless res.items.length.positive?
^^^^^^^^^^^^^^^^
./apps/canvas-lms/app/models/report_snapshot.rb:53:13: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if args.length == 1
^^^^^^^^^^^
./apps/canvas-lms/app/models/rollup_score.rb:165:19: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if tmp_scores.size == 1
^^^^^^^^^
./apps/canvas-lms/app/models/sharded_bookmarked_collection.rb:60:88: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return always_use_bookmarks ? collections.last.last : last_relation if collections.size == 1
^^^^^^^^^
./apps/canvas-lms/app/models/user.rb:1335:66: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if accounts_to_search.shard(shard).empty? && common_shards.length == 1 && !unavailable?
^^^^^^^^^^^
./apps/canvas-lms/app/models/wimba_conference.rb:52:66: C: [Correctable] Style/CollectionQuerying: Use one? instead.
urls.first[:url] = join_url(user, urls.first[:id]) if urls.size == 1 && touch_user(user)
^^^^^^^^^
./apps/canvas-lms/app/services/checkpoints/submission_aggregator_service.rb:125:18: C: [Correctable] Style/CollectionQuerying: Use one? instead.
(values.uniq.length == 1) ? values.first : default
^^^^^^^^^^^
./apps/canvas-lms/config/initializers/active_record.rb:1358:35: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return scopes.first if scopes.length == 1
^^^^^^^^^^^
./apps/canvas-lms/config/initializers/active_record.rb:1662:155: C: [Correctable] Style/CollectionQuerying: Use one? instead.
raise "#{name} (#{version}) is not tagged as exactly one of predeploy or postdeploy!" unless (@migration.tags & ActiveRecord::Migration::DEPLOY_TAGS).length == 1
^^^^^^^^^^^
./apps/canvas-lms/config/initializers/folio.rb:45:78: C: [Correctable] Style/CollectionQuerying: Use one? instead.
options[:total_entries] = if having_clause_empty && group_values.length == 1 # multi-column distinct counts are broken right now (as of rails 4.2.5) :(
^^^^^^^^^^^
./apps/canvas-lms/config/initializers/postgresql_adapter.rb:229:138: C: [Correctable] Style/CollectionQuerying: Use one? instead.
raise ArgumentError, "if you're identifying an index by name only, you should use index_name_exists?" if column_name.nil? && options.size == 1 && options.key?(:name)
^^^^^^^^^
./apps/canvas-lms/doc/api/fulldoc/html/swagger/method_view.rb:126:15: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if routes.size == 1
^^^^^^^^^
./apps/canvas-lms/doc/api/fulldoc/html/swagger/method_view.rb:188:17: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if segments.size == 1
^^^^^^^^^
./apps/canvas-lms/doc/api/fulldoc/html/swagger/method_view.rb:198:17: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if urls.length == 1
^^^^^^^^^^^
./apps/canvas-lms/gems/attachment_fu/lib/attachment_fu/processors/mini_magick_processor.rb:65:56: C: [Correctable] Style/CollectionQuerying: Use one? instead.
size = size.first if size.is_a?(Array) && size.length == 1
^^^^^^^^^^^
./apps/canvas-lms/gems/canvas_color/lib/canvas_color.rb:414:27: C: [Correctable] Style/CollectionQuerying: Use one? instead.
val += val if val.size == 1
^^^^^^^^^
./apps/canvas-lms/gems/i18n_extraction/lib/i18n_extraction/i18nliner_extensions.rb:142:22: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return if args.size == 1 && method == :before_label
^^^^^^^^^
./apps/canvas-lms/gems/json_token/lib/json_token.rb:38:41: C: [Correctable] Style/CollectionQuerying: Use one? instead.
raise JSON::ParserError unless json.size == 1
^^^^^^^^^
./apps/canvas-lms/gems/live_events/lib/live_events/async_worker.rb:98:45: C: [Correctable] Style/CollectionQuerying: Use one? instead.
break if r == :stop || (records.size == 1 && records.first == :stop)
^^^^^^^^^
./apps/canvas-lms/gems/plugins/account_reports/lib/account_reports/outcome_reports.rb:523:30: C: [Correctable] Style/CollectionQuerying: Use one? instead.
select.first if select.length == 1
^^^^^^^^^^^
./apps/canvas-lms/gems/plugins/qti_exporter/lib/qti/html_helper.rb:86:38: C: [Correctable] Style/CollectionQuerying: Use one? instead.
break unless node.children.size == 1 && %w[p div span].include?(node.child.name)
^^^^^^^^^
./apps/canvas-lms/gems/plugins/qti_exporter/lib/qti/html_helper.rb:119:127: C: [Correctable] Style/CollectionQuerying: Use one? instead.
sanitized = sanitize_html!(html_node ? Nokogiri::HTML5.fragment(node.text) : node, true) { |s| is_html ||= !(s.children.size == 1 && s.children.first.is_a?(Nokogiri::XML::Text)) }
^^^^^^^^^
./apps/canvas-lms/gems/plugins/respondus_soap_endpoint/lib/respondus_soap_endpoint/urn_RespondusAPIServant.rb:522:95: C: [Correctable] Style/CollectionQuerying: Use one? instead.
raise(OtherError, "Item type incompatible with selection state") unless selection_state.size == 1
^^^^^^^^^
./apps/canvas-lms/lib/api.rb:81:43: C: [Correctable] Style/CollectionQuerying: Use one? instead.
current_term = (current_terms.length == 1) ? current_terms.first : :nil
^^^^^^^^^^^
./apps/canvas-lms/lib/api.rb:301:29: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if columns.keys.flatten.length == 1 && not_scoped_to_account?(columns.keys.first, sis_mapping)
^^^^^^^^^^^
./apps/canvas-lms/lib/api/v1/assignment.rb:107:17: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if contexts.length == 1
^^^^^^^^^^^
./apps/canvas-lms/lib/api/v1/calendar_event.rb:323:55: C: [Correctable] Style/CollectionQuerying: Use one? instead.
return child_events.first.user if unique_user_ids.length == 1
^^^^^^^^^^^
./apps/canvas-lms/lib/canvas/migration/helpers/selective_content_formatter.rb:200:17: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if atts.length == 1 && atts[0]["file_name"] == folder_name
^^^^^^^^^^^
./apps/canvas-lms/lib/data_fixup/backfill_nulls.rb:46:17: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if fields.length == 1
^^^^^^^^^^^
./apps/canvas-lms/lib/data_fixup/backfill_nulls.rb:48:73: C: [Correctable] Style/CollectionQuerying: Use one? instead.
updates = { fields.first.first => fields.first.last } if fields.length == 1
^^^^^^^^^^^
./apps/canvas-lms/lib/effective_due_dates.rb:323:32: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if assignment_collection.length == 1 &&
^^^^^^^^^^^
./apps/canvas-lms/lib/gradebook_importer.rb:706:85: C: [Correctable] Style/CollectionQuerying: Use one? instead.
field_counts[separator] = field_count_by_row.first if field_count_by_row.uniq.size == 1
^^^^^^^^^
./apps/canvas-lms/lib/inst_fs.rb:260:34: C: [Correctable] Style/CollectionQuerying: Use one? instead.
json_response["success"].length == 1 &&
^^^^^^^^^^^
./apps/canvas-lms/lib/lti/content_item_response.rb:137:51: C: [Correctable] Style/CollectionQuerying: Use one? instead.
@canvas_media_type ||= if @media_types.keys.size == 1
^^^^^^^^^
./apps/canvas-lms/lib/message_dispatcher.rb:48:17: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if messages.size == 1
^^^^^^^^^
./apps/canvas-lms/lib/microsoft_sync/debug_info_tracker.rb:166:35: C: [Correctable] Style/CollectionQuerying: Use one? instead.
elsif users_without_uluvs.length == 1
^^^^^^^^^^^
./apps/canvas-lms/lib/microsoft_sync/debug_info_tracker.rb:194:34: C: [Correctable] Style/CollectionQuerying: Use one? instead.
elsif users_without_aads.length == 1
^^^^^^^^^^^
./apps/canvas-lms/lib/microsoft_sync/settings_validator.rb:120:33: C: [Correctable] Style/CollectionQuerying: Use one? instead.
elsif enabled && settings.length == 1
^^^^^^^^^^^
./apps/canvas-lms/lib/outcomes/import.rb:234:61: C: [Correctable] Style/CollectionQuerying: Use one? instead.
model.has_changes_to_save? && !(model.changes_to_save.length == 1 &&
^^^^^^^^^^^
./apps/canvas-lms/lib/planner_api_helper.rb:95:20: C: [Correctable] Style/CollectionQuerying: Use one? instead.
(doneable_tags.length == 1) ? doneable_tags.first : nil
^^^^^^^^^^^
./apps/canvas-lms/lib/quiz_math_data_fixup.rb:89:22: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if html.children.length == 1 && html.children[0].node_type == Nokogiri::XML::Node::TEXT_NODE
^^^^^^^^^^^
./apps/canvas-lms/lib/sis/csv/diff_generator.rb:68:21: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if csvs.size == 1
^^^^^^^^^
./apps/canvas-lms/lib/sis/csv/import_refactored.rb:185:35: C: [Correctable] Style/CollectionQuerying: Use none? instead.
return if File.stat(path).size == 0
^^^^^^^^^
./apps/canvas-lms/lib/sis/csv/import_refactored.rb:280:57: C: [Correctable] Style/CollectionQuerying: Use none? instead.
raise "Empty file" if File.stat(csv[:fullpath]).size == 0
^^^^^^^^^
./apps/canvas-lms/lib/submission_lifecycle_manager.rb:311:24: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if @assignment_ids.size == 1 && !@skip_late_policy_applicator
^^^^^^^^^
./apps/canvas-lms/lib/tasks/db.rake:46:23: C: [Correctable] Style/CollectionQuerying: Use any? instead.
if real_columns.size.positive?
^^^^^^^^^^^^^^
./apps/canvas-lms/lib/user_search.rb:229:29: C: [Correctable] Style/CollectionQuerying: Use any? instead.
return nil unless ids.length.positive?
^^^^^^^^^^^^^^^^
./apps/canvas-lms/spec/apis/v1/assignments_api_spec.rb:235:23: C: [Correctable] Style/CollectionQuerying: Use one? instead.
break if json.length == 1
^^^^^^^^^^^
./apps/canvas-lms/spec/apis/v1/conversations_api_spec.rb:190:55: C: [Correctable] Style/CollectionQuerying: Use one? instead.
expect(links.all? { |l| l.scan("scope=default").size == 1 }).to be_truthy
^^^^^^^^^
./apps/canvas-lms/spec/apis/v1/conversations_api_spec.rb:202:55: C: [Correctable] Style/CollectionQuerying: Use one? instead.
expect(links.all? { |l| l.scan("scope=default").size == 1 }).to be_truthy
^^^^^^^^^
./apps/canvas-lms/spec/apis/v1/submissions_api_spec.rb:37:21: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if sub.versions.size == 1
^^^^^^^^^
./apps/canvas-lms/spec/models/lti/tool_proxy_service_spec.rb:213:33: C: [Correctable] Style/CollectionQuerying: Use one? instead.
resource_placements.size == 1 && resource_placements[0].placement == placement
^^^^^^^^^
./apps/canvas-lms/spec/models/sis_batch_spec.rb:34:15: C: [Correctable] Style/CollectionQuerying: Use one? instead.
if data.length == 1
^^^^^^^^^^^
./apps/canvas-lms/spec/selenium/grades/pages/gradebook_history_page.rb:167:23: C: [Correctable] Style/CollectionQuerying: Use one? instead.
unless arr.uniq.size == 1
^^^^^^^^^
49358 files inspected, 431 offenses detected, 431 offenses autocorrectable
Yeah, I'm fine with a follow-up PR. This one is good to go as far as I'm concerned. Thanks!
Hey folks - just trying out the new rubocop release in a (non-Rails) project, and finding this cop is reporting false positives. i.e. objects that respond to count but don't inherit/mimic Enumerable.
I'm not sure about presuming anything that responds to count is an enumerable - but I'm also not sure what's the preferred approach in Rubocop generally here. Should cops be this aggressive in their presumptions, and it's up to users to disable the rule around the offending lines?
It's been a while since I looked into Rubocop internals - I'm presuming there's no way to reliably detect that the count method is truly being invoked on an enumerable?
I'm also seeing some issues after upgrading. In a Rails application that uses Mongoid, it is changing Company.count > 0 into Company.any?, except Mongoid does not define .any? on the top level model, so we're getting a ton of NoMethodError.
Is this something I should create an issue for, or is it not likely to be fixed? I guess Rubocop is a static analyzer, so without checking what the class is, you'll have no way to know if any? is supported?
Edit: This also has performance implications in Mongoid. It changed model.where(...).count == 1 into model.where(...).any?, which unfortunately turns it from a count query into a find/fetch query then calls any? on the resulting records array, which is much slower. This is an issue with Mongoid not being smarter for these method calls, but thought I'd point it out.
As per both my previous comment and @KieranP's, I've created a PR to disable this cop by default: https://github.com/rubocop/rubocop/pull/14349
Not a question of whether this cop is valuable - just that I think it should be opt-in rather than opt-out.
I'm presuming there's no way to reliably detect that the count method is truly being invoked on an enumerable?
That's right, RuboCop is a static analyzer, so it can't actually know whether your receiver includes Enumerable.
In a Rails application that uses Mongoid, it is changing Company.count > 0 into Company.any?, except Mongoid does not define .any? on the top level model, so we're getting a ton of NoMethodError.
Uhh that's unfortunate. I was thinking of following up on this PR with some additional configurations:
AllowedReceivers- user-set array of receivers which would not register an offense (e.g. if you configured it to['Company'],Company.count > 0wouldn't be an offense anymore). This approach is used e.g. inStyle/CollectionCompact: https://github.com/rubocop/rubocop/blob/c16c8cb93788fd967d8d298508229412db2c3b84/lib/rubocop/cop/style/collection_compact.rb#L40-L42EnforcedStyle- you'd be able to choose if the cop only registerscountwith a block, without a block, or both. For example,foo.count > 0wouldn't be an offense, butfoo.count(&:bar) > 0would (since the latter is more likely an Enumerable).
With these two config options, I think you'll be able to reliably reduce the number of false positives. Probably not eliminate, but that's the case for any cop.
@bbatsov what do you think about the new config options?