diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2018-08-27 17:31:01 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2018-09-11 17:32:00 +0200 |
commit | 2039c8280db1646845c33d6c5a74e5f23ca6f4de (patch) | |
tree | e2b3cd3012d9711cda7c6afb962ae4228d59521a /app/helpers | |
parent | 91c40973dc620430b173ea2df968587d2a708dff (diff) | |
download | gitlab-ce-2039c8280db1646845c33d6c5a74e5f23ca6f4de.tar.gz |
Disable existing offenses for the CodeReuse cops
This whitelists all existing offenses for the various CodeReuse cops, of
which most are triggered by the CodeReuse/ActiveRecord cop.
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/application_helper.rb | 4 | ||||
-rw-r--r-- | app/helpers/auth_helper.rb | 2 | ||||
-rw-r--r-- | app/helpers/auto_devops_helper.rb | 2 | ||||
-rw-r--r-- | app/helpers/diff_helper.rb | 2 | ||||
-rw-r--r-- | app/helpers/environment_helper.rb | 2 | ||||
-rw-r--r-- | app/helpers/issuables_helper.rb | 8 | ||||
-rw-r--r-- | app/helpers/milestones_helper.rb | 2 | ||||
-rw-r--r-- | app/helpers/namespaces_helper.rb | 4 | ||||
-rw-r--r-- | app/helpers/numbers_helper.rb | 2 | ||||
-rw-r--r-- | app/helpers/projects_helper.rb | 2 | ||||
-rw-r--r-- | app/helpers/safe_params_helper.rb | 2 | ||||
-rw-r--r-- | app/helpers/search_helper.rb | 4 | ||||
-rw-r--r-- | app/helpers/tree_helper.rb | 4 |
13 files changed, 40 insertions, 0 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index bb7ae03313c..bb401b03709 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -5,9 +5,11 @@ require 'uri' module ApplicationHelper # See https://docs.gitlab.com/ee/development/ee_features.html#code-in-app-views + # rubocop: disable CodeReuse/ActiveRecord def render_if_exists(partial, locals = {}) render(partial, locals) if lookup_context.exists?(partial, [], true) end + # rubocop: enable CodeReuse/ActiveRecord # Check if a particular controller is the current one # @@ -51,6 +53,7 @@ module ApplicationHelper # Define whenever show last push event # with suggestion to create MR + # rubocop: disable CodeReuse/ActiveRecord def show_last_push_widget?(event) # Skip if event is not about added or modified non-master branch return false unless event && event.last_push_to_non_root? && !event.rm_ref? @@ -68,6 +71,7 @@ module ApplicationHelper true end + # rubocop: enable CodeReuse/ActiveRecord def hexdigest(string) Digest::SHA1.hexdigest string diff --git a/app/helpers/auth_helper.rb b/app/helpers/auth_helper.rb index c17a54a6dff..c158cf20dd6 100644 --- a/app/helpers/auth_helper.rb +++ b/app/helpers/auth_helper.rb @@ -66,9 +66,11 @@ module AuthHelper end end + # rubocop: disable CodeReuse/ActiveRecord def auth_active?(provider) current_user.identities.exists?(provider: provider.to_s) end + # rubocop: enable CodeReuse/ActiveRecord def unlink_allowed?(provider) %w(saml cas3).exclude?(provider.to_s) diff --git a/app/helpers/auto_devops_helper.rb b/app/helpers/auto_devops_helper.rb index 62fc6fb279f..516c8a353ea 100644 --- a/app/helpers/auto_devops_helper.rb +++ b/app/helpers/auto_devops_helper.rb @@ -26,6 +26,7 @@ module AutoDevopsHelper end end + # rubocop: disable CodeReuse/ActiveRecord def cluster_ingress_ip(project) project .cluster_ingresses @@ -34,6 +35,7 @@ module AutoDevopsHelper .pluck(:external_ip) .first end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb index 7684734c014..b6844d36052 100644 --- a/app/helpers/diff_helper.rb +++ b/app/helpers/diff_helper.rb @@ -213,9 +213,11 @@ module DiffHelper params[:w] == '1' end + # rubocop: disable CodeReuse/ActiveRecord def params_with_whitespace hide_whitespace? ? request.query_parameters.except(:w) : request.query_parameters.merge(w: 1) end + # rubocop: enable CodeReuse/ActiveRecord def toggle_whitespace_link(url, options) options[:class] = [*options[:class], 'btn btn-default'].join(' ') diff --git a/app/helpers/environment_helper.rb b/app/helpers/environment_helper.rb index 4b3ef2de701..2b7320817ed 100644 --- a/app/helpers/environment_helper.rb +++ b/app/helpers/environment_helper.rb @@ -1,11 +1,13 @@ # frozen_string_literal: true module EnvironmentHelper + # rubocop: disable CodeReuse/ActiveRecord def environment_for_build(project, build) return unless build.environment project.environments.find_by(name: build.expanded_environment_name) end + # rubocop: enable CodeReuse/ActiveRecord def environment_link_for_build(project, build) environment = environment_for_build(project, build) diff --git a/app/helpers/issuables_helper.rb b/app/helpers/issuables_helper.rb index 8396cfe0ac8..1f67c045d1c 100644 --- a/app/helpers/issuables_helper.rb +++ b/app/helpers/issuables_helper.rb @@ -107,6 +107,7 @@ module IssuablesHelper end end + # rubocop: disable CodeReuse/ActiveRecord def user_dropdown_label(user_id, default_label) return default_label if user_id.nil? return "Unassigned" if user_id == "0" @@ -119,7 +120,9 @@ module IssuablesHelper default_label end end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def project_dropdown_label(project_id, default_label) return default_label if project_id.nil? return "Any project" if project_id == "0" @@ -132,7 +135,9 @@ module IssuablesHelper default_label end end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def group_dropdown_label(group_id, default_label) return default_label if group_id.nil? return "Any group" if group_id == "0" @@ -145,6 +150,7 @@ module IssuablesHelper default_label end end + # rubocop: enable CodeReuse/ActiveRecord def milestone_dropdown_label(milestone_title, default_label = "Milestone") title = @@ -191,11 +197,13 @@ module IssuablesHelper output.join.html_safe end + # rubocop: disable CodeReuse/ActiveRecord def issuable_todo(issuable) if current_user current_user.todos.find_by(target: issuable, state: :pending) end end + # rubocop: enable CodeReuse/ActiveRecord def issuable_labels_tooltip(labels, limit: 5) first, last = labels.partition.with_index { |_, i| i < limit } diff --git a/app/helpers/milestones_helper.rb b/app/helpers/milestones_helper.rb index 999143002bb..94a030d9d57 100644 --- a/app/helpers/milestones_helper.rb +++ b/app/helpers/milestones_helper.rb @@ -53,6 +53,7 @@ module MilestonesHelper # Returns count of milestones for different states # Uses explicit hash keys as the 'opened' state URL params differs from the db value # and we need to add the total + # rubocop: disable CodeReuse/ActiveRecord def milestone_counts(milestones) counts = milestones.reorder(nil).group(:state).count @@ -62,6 +63,7 @@ module MilestonesHelper all: counts.values.sum || 0 } end + # rubocop: enable CodeReuse/ActiveRecord # Show 'active' class if provided GET param matches check # `or_blank` allows the function to return 'active' when given an empty param diff --git a/app/helpers/namespaces_helper.rb b/app/helpers/namespaces_helper.rb index e7537ca5733..6c65e573307 100644 --- a/app/helpers/namespaces_helper.rb +++ b/app/helpers/namespaces_helper.rb @@ -5,6 +5,7 @@ module NamespacesHelper params.dig(:project, :namespace_id) || params[:namespace_id] end + # rubocop: disable CodeReuse/ActiveRecord def namespaces_options(selected = :current_user, display_path: false, groups: nil, extra_group: nil, groups_only: false) groups ||= current_user.manageable_groups .eager_load(:route) @@ -42,6 +43,7 @@ module NamespacesHelper grouped_options_for_select(options, selected_id) end + # rubocop: enable CodeReuse/ActiveRecord def namespace_icon(namespace, size = 40) if namespace.is_a?(Group) @@ -55,6 +57,7 @@ module NamespacesHelper # Many importers create a temporary Group, so use the real # group if one exists by that name to prevent duplicates. + # rubocop: disable CodeReuse/ActiveRecord def dedup_extra_group(extra_group) unless extra_group.persisted? existing_group = Group.find_by(path: extra_group.path) @@ -63,6 +66,7 @@ module NamespacesHelper extra_group end + # rubocop: enable CodeReuse/ActiveRecord def options_for_group(namespaces, display_path:, type:) group_label = type.pluralize diff --git a/app/helpers/numbers_helper.rb b/app/helpers/numbers_helper.rb index f609b6c0cec..3c0b11c4d32 100644 --- a/app/helpers/numbers_helper.rb +++ b/app/helpers/numbers_helper.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true module NumbersHelper + # rubocop: disable CodeReuse/ActiveRecord def limited_counter_with_delimiter(resource, **options) limit = options.fetch(:limit, 1000).to_i count = resource.limit(limit + 1).count(:all) @@ -10,4 +11,5 @@ module NumbersHelper number_with_delimiter(count, options) end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 89fee06ee77..8b17e6ef75d 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -222,6 +222,7 @@ module ProjectsHelper # # If no limit is applied we'll just issue a COUNT since the result set could # be too large to load into memory. + # rubocop: disable CodeReuse/ActiveRecord def any_projects?(projects) return projects.any? if projects.is_a?(Array) @@ -231,6 +232,7 @@ module ProjectsHelper projects.except(:offset).any? end end + # rubocop: enable CodeReuse/ActiveRecord def show_projects?(projects, params) !!(params[:personal] || params[:name] || any_projects?(projects)) diff --git a/app/helpers/safe_params_helper.rb b/app/helpers/safe_params_helper.rb index 72bf1377b02..18bbf3347a8 100644 --- a/app/helpers/safe_params_helper.rb +++ b/app/helpers/safe_params_helper.rb @@ -3,6 +3,7 @@ module SafeParamsHelper # Rails 5.0 requires to permit `params` if they're used in url helpers. # Use this helper when generating links with `params.merge(...)` + # rubocop: disable CodeReuse/ActiveRecord def safe_params if params.respond_to?(:permit!) params.except(:host, :port, :protocol).permit! @@ -10,4 +11,5 @@ module SafeParamsHelper params end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index c509cd592c4..4f9e1322b56 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -101,6 +101,7 @@ module SearchHelper end # Autocomplete results for the current user's groups + # rubocop: disable CodeReuse/ActiveRecord def groups_autocomplete(term, limit = 5) current_user.authorized_groups.order_id_desc.search(term).limit(limit).map do |group| { @@ -112,8 +113,10 @@ module SearchHelper } end end + # rubocop: enable CodeReuse/ActiveRecord # Autocomplete results for the current user's projects + # rubocop: disable CodeReuse/ActiveRecord def projects_autocomplete(term, limit = 5) current_user.authorized_projects.order_id_desc.search_by_title(term) .sorted_by_stars.non_archived.limit(limit).map do |p| @@ -127,6 +130,7 @@ module SearchHelper } end end + # rubocop: enable CodeReuse/ActiveRecord def search_result_sanitize(str) Sanitize.clean(str) diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb index 80f61a371fd..6d2da5699fb 100644 --- a/app/helpers/tree_helper.rb +++ b/app/helpers/tree_helper.rb @@ -7,6 +7,7 @@ module TreeHelper # their corresponding partials # # tree - A `Tree` object for the current tree + # rubocop: disable CodeReuse/ActiveRecord def render_tree(tree) # Sort submodules and folders together by name ahead of files folders, files, submodules = tree.trees, tree.blobs, tree.submodules @@ -22,6 +23,7 @@ module TreeHelper tree << render(partial: 'projects/tree/tree_row', collection: items) if items.present? tree.join.html_safe end + # rubocop: enable CodeReuse/ActiveRecord # Return an image icon depending on the file type and mode # @@ -124,6 +126,7 @@ module TreeHelper end # returns the relative path of the first subdir that doesn't have only one directory descendant + # rubocop: disable CodeReuse/ActiveRecord def flatten_tree(root_path, tree) return tree.flat_path.sub(%r{\A#{Regexp.escape(root_path)}/}, '') if tree.flat_path.present? @@ -134,6 +137,7 @@ module TreeHelper return tree.name end end + # rubocop: enable CodeReuse/ActiveRecord def selected_branch @branch_name || tree_edit_branch |