Commit 40c8a21c authored by Shubham Kumar's avatar Shubham Kumar Committed by Rémy Coutable

Resolves rubocop offense Style/RedundantAssignment

parent 6853eeb8
......@@ -864,11 +864,6 @@ Style/RaiseArgs:
Enabled: false
EnforcedStyle: exploded
# Offense count: 73
# Cop supports --auto-correct.
Style/RedundantAssignment:
Enabled: false
# Offense count: 2
# Cop supports --auto-correct.
Style/RedundantBegin:
......
......@@ -13,8 +13,7 @@ class AwardEmojisFinder
def execute
awards = awardable.award_emoji
awards = by_name(awards)
awards = by_awarded_by(awards)
awards
by_awarded_by(awards)
end
private
......
......@@ -11,8 +11,7 @@ class BranchesFinder < GitRefsFinder
else
branches = repository.branches_sorted_by(sort)
branches = by_search(branches)
branches = by_names(branches)
branches
by_names(branches)
end
end
......
......@@ -35,8 +35,7 @@ module Ci
return Ci::DailyBuildGroupReportResult.none unless query_allowed?
collection = Ci::DailyBuildGroupReportResult.by_projects(params[:project])
collection = filter_report_results(collection)
collection
filter_report_results(collection)
end
private
......@@ -51,8 +50,7 @@ module Ci
collection = by_dates(collection)
collection = sort(collection)
collection = limit_by(collection)
collection
limit_by(collection)
end
def by_coverage(items)
......
......@@ -11,8 +11,7 @@ module Ci
def execute
variables = resource.variables
variables = by_key(variables)
variables = by_environment_scope(variables)
variables
by_environment_scope(variables)
end
private
......
......@@ -11,9 +11,7 @@ class ContextCommitsFinder
def execute
commits = init_collection
commits = filter_existing_commits(commits)
commits
filter_existing_commits(commits)
end
private
......@@ -21,19 +19,15 @@ class ContextCommitsFinder
attr_reader :project, :merge_request, :search, :limit, :offset
def init_collection
commits =
if search.present?
search_commits
else
project.repository.commits(merge_request.target_branch, { limit: limit, offset: offset })
end
commits
end
def filter_existing_commits(commits)
commits.select! { |commit| already_included_ids.exclude?(commit.id) }
commits
end
......
......@@ -33,9 +33,7 @@ class DeploymentsFinder
items = by_environment(items)
items = by_status(items)
items = preload_associations(items)
items = sort(items)
items
sort(items)
end
private
......
......@@ -15,9 +15,7 @@ class EnvironmentsFinder
environments = by_search(environments)
# Raises InvalidStatesError if params[:states] contains invalid states.
environments = by_states(environments)
environments
by_states(environments)
end
private
......
......@@ -48,8 +48,7 @@ class GroupProjectsFinder < ProjectsFinder
def filter_projects(collection)
projects = super
projects = by_feature_availability(projects)
projects
by_feature_availability(projects)
end
def limit(collection)
......
......@@ -119,9 +119,7 @@ class IssuableFinder
# https://www.postgresql.org/docs/current/static/queries-with.html
items = by_search(items)
items = sort(items)
items
sort(items)
end
def filter_items(items)
......
......@@ -81,8 +81,7 @@ class IssuesFinder < IssuableFinder
issues = super
issues = by_due_date(issues)
issues = by_confidential(issues)
issues = by_issue_types(issues)
issues
by_issue_types(issues)
end
def by_confidential(items)
......
......@@ -14,9 +14,7 @@ class MergeRequest::MetricsFinder
items = init_collection
items = by_target_project(items)
items = by_merged_after(items)
items = by_merged_before(items)
items
by_merged_before(items)
end
private
......
......@@ -39,8 +39,7 @@ module Namespaces
def filter_projects(collection)
collection = by_ids(collection)
collection = by_similarity(collection)
collection
by_similarity(collection)
end
def by_ids(items)
......
......@@ -8,8 +8,7 @@ module Packages
def package_files
files = super
files = by_conan_file_type(files)
files = by_conan_package_reference(files)
files
by_conan_package_reference(files)
end
def by_conan_file_type(files)
......
......@@ -11,8 +11,7 @@ module Packages
collection = relation.with_container(container)
collection = by_codename(collection)
collection = by_suite(collection)
collection = by_codename_or_suite(collection)
collection
by_codename_or_suite(collection)
end
private
......
......@@ -32,8 +32,7 @@ module Packages
packages = filter_with_version(packages)
packages = filter_by_package_type(packages)
packages = filter_by_package_name(packages)
packages = filter_by_status(packages)
packages
filter_by_status(packages)
end
def group_projects_visible_to_current_user
......
......@@ -21,9 +21,7 @@ class Packages::PackageFileFinder
def package_files
files = package.package_files
files = by_file_name(files)
files
by_file_name(files)
end
def by_file_name(files)
......
......@@ -22,8 +22,7 @@ module Packages
packages = filter_by_package_type(packages)
packages = filter_by_package_name(packages)
packages = filter_by_status(packages)
packages = order_packages(packages)
packages
order_packages(packages)
end
private
......
......@@ -26,9 +26,7 @@ class PendingTodosFinder
todos = by_project(todos)
todos = by_target_id(todos)
todos = by_target_type(todos)
todos = by_commit_id(todos)
todos
by_commit_id(todos)
end
def by_project(todos)
......
......@@ -12,9 +12,7 @@ module Projects
def execute
export_jobs = project.export_jobs
export_jobs = by_status(export_jobs)
export_jobs
by_status(export_jobs)
end
private
......
......@@ -30,9 +30,7 @@ module Projects
relation = by_environment(relation)
relation = by_metric(relation)
relation = by_id(relation)
relation = ordered(relation)
relation
ordered(relation)
end
private
......
......@@ -83,8 +83,7 @@ class ProjectsFinder < UnionFinder
collection = by_deleted_status(collection)
collection = by_last_activity_after(collection)
collection = by_last_activity_before(collection)
collection = by_repository_storage(collection)
collection
by_repository_storage(collection)
end
def collection_with_user
......
......@@ -36,9 +36,7 @@ class PrometheusMetricsFinder
metrics = by_common(metrics)
metrics = by_ordered(metrics)
metrics = by_identifier(metrics)
metrics = by_id(metrics)
metrics
by_id(metrics)
end
private
......
......@@ -20,9 +20,7 @@ class ProtectedBranchesFinder
def execute
protected_branches = project.limited_protected_branches(LIMIT)
protected_branches = by_name(protected_branches)
protected_branches
by_name(protected_branches)
end
private
......
......@@ -20,8 +20,7 @@ class ReleasesFinder
releases = get_releases
releases = by_tag(releases)
releases = releases.preloaded if preload
releases = order_releases(releases)
releases
order_releases(releases)
end
private
......
......@@ -7,7 +7,6 @@ class TagsFinder < GitRefsFinder
def execute
tags = repository.tags_sorted_by(sort)
tags = by_search(tags)
tags
by_search(tags)
end
end
......@@ -15,9 +15,7 @@ class UsersStarProjectsFinder
stars = UsersStarProject.all
stars = by_project(stars)
stars = by_search(stars)
stars = filter_visible_profiles(stars)
stars
filter_visible_profiles(stars)
end
private
......
......@@ -165,7 +165,7 @@ module ApplicationHelper
css_classes = [short_format ? 'js-short-timeago' : 'js-timeago']
css_classes << html_class unless html_class.blank?
element = content_tag :time, l(time, format: "%b %d, %Y"),
content_tag :time, l(time, format: "%b %d, %Y"),
class: css_classes.join(' '),
title: l(time.to_time.in_time_zone, format: :timeago_tooltip),
datetime: time.to_time.getutc.iso8601,
......@@ -174,8 +174,6 @@ module ApplicationHelper
placement: placement,
container: 'body'
}
element
end
def edited_time_ago_with_tooltip(object, placement: 'top', html_class: 'time_ago', exclude_author: false)
......
......@@ -4,8 +4,7 @@ module GitHelper
def strip_signature(text)
text = text.gsub(/-----BEGIN PGP SIGNATURE-----(.*)-----END PGP SIGNATURE-----/m, "")
text = text.gsub(/-----BEGIN PGP MESSAGE-----(.*)-----END PGP MESSAGE-----/m, "")
text = text.gsub(/-----BEGIN SIGNED MESSAGE-----(.*)-----END SIGNED MESSAGE-----/m, "")
text
text.gsub(/-----BEGIN SIGNED MESSAGE-----(.*)-----END SIGNED MESSAGE-----/m, "")
end
def short_sha(text)
......
......@@ -21,8 +21,7 @@ module Ci
deps = model_class.where(pipeline_id: processable.pipeline_id).latest
deps = from_previous_stages(deps)
deps = from_needs(deps)
deps = from_dependencies(deps)
deps
from_dependencies(deps)
end
# Dependencies from the same parent-pipeline hierarchy excluding
......
......@@ -49,11 +49,9 @@ module MergeRequests
def duplicates
existing_oids = merge_request.merge_request_context_commits.map { |commit| commit.sha.to_s }
duplicate_oids = existing_oids.select do |existing_oid|
existing_oids.select do |existing_oid|
commit_ids.select { |commit_id| existing_oid.start_with?(commit_id) }.count > 0
end
duplicate_oids
end
def build_context_commit_rows(merge_request_id, commits)
......
......@@ -25,9 +25,7 @@ module ResourceEvents
def apply_common_filters(events)
events = apply_last_fetched_at(events)
events = apply_fetch_until(events)
events
apply_fetch_until(events)
end
def apply_last_fetched_at(events)
......
......@@ -147,8 +147,7 @@ class IrkerWorker # rubocop:disable Scalability/IdempotentWorker
def files_count(commit)
diff_size = commit.raw_deltas.size
files = "#{diff_size} file".pluralize(diff_size)
files
"#{diff_size} file".pluralize(diff_size)
end
def colorize_sha(sha)
......
---
title: Resolves offenses Style/RedundantAssignment
merge_request: 58013
author: Shubham Kumar (@imskr)
type: fixed
......@@ -17,9 +17,8 @@ module HangoutsChat
headers: { 'Content-Type' => 'application/json' },
parse: nil # disables automatic response parsing
)
net_http_response = httparty_response.response
httparty_response.response
# The rest of the integration expects a Net::HTTP response
net_http_response
end
end
......
......@@ -22,7 +22,7 @@ module EE
end
def merge_request_params_attributes
attrs = super.push(
super.push(
{ blocking_merge_request_references: [] },
:update_blocking_merge_request_refs,
:remove_hidden_blocking_merge_requests,
......@@ -32,8 +32,6 @@ module EE
:approver_ids,
:reset_approval_rules_to_defaults
)
attrs
end
def approval_rule_attributes
......
......@@ -54,7 +54,7 @@ module Registrations
end
def create_learn_gitlab_project
learn_gitlab_project = File.open(learn_gitlab_template_path) do |archive|
File.open(learn_gitlab_template_path) do |archive|
::Projects::GitlabProjectsImportService.new(
current_user,
namespace_id: @project.namespace_id,
......@@ -62,8 +62,6 @@ module Registrations
name: learn_gitlab_project_name
).execute
end
learn_gitlab_project
end
def authorize_create_project!
......
......@@ -9,8 +9,7 @@ class DastScannerProfilesFinder
relation = DastScannerProfile.all
relation = by_id(relation)
relation = by_project(relation)
relation = by_name(relation)
relation
by_name(relation)
end
private
......
......@@ -9,8 +9,7 @@ class DastSiteProfilesFinder
relation = DastSiteProfile.with_dast_site_and_validation
relation = by_id(relation)
relation = by_project(relation)
relation = by_name(relation)
relation
by_name(relation)
end
private
......
......@@ -20,8 +20,7 @@ module EE
return ::Ci::DailyBuildGroupReportResult.none unless query_allowed?
collection = ::Ci::DailyBuildGroupReportResult.by_group(params[:group])
collection = filter_report_results(collection)
collection
filter_report_results(collection)
end
private
......@@ -29,8 +28,7 @@ module EE
override :filter_report_results
def filter_report_results(collection)
collection = super(collection)
collection = by_activity_per_group(collection)
collection
by_activity_per_group(collection)
end
def by_activity_per_group(items)
......
......@@ -14,8 +14,7 @@ module EE
override :filter_projects
def filter_projects(collection)
collection = super(collection)
collection = by_security_reports_presence(collection)
collection
by_security_reports_presence(collection)
end
def by_security_reports_presence(collection)
......
......@@ -9,9 +9,7 @@ module EE
def filter_items(items)
items = super(items)
items = by_approvers(items)
items = by_merge_commit_sha(items)
items
by_merge_commit_sha(items)
end
# Filter by merge requests approval list that contains specified user directly or as part of group membership
......
......@@ -21,8 +21,7 @@ module EE
collection = super(collection)
collection = with_vulnerabilities(collection)
collection = with_code_coverage(collection)
collection = by_storage(collection)
collection
by_storage(collection)
end
def by_storage(items)
......
......@@ -17,8 +17,7 @@ module EE
def filter_projects(collection)
collection = super(collection)
collection = by_plans(collection)
collection = by_aimed_for_deletion(collection)
collection
by_aimed_for_deletion(collection)
end
def by_plans(collection)
......
......@@ -13,9 +13,7 @@ module IncidentManagement
return IncidentManagement::OncallRotation.none unless schedule && allowed?
collection = schedule.rotations
collection = by_id(collection)
collection
by_id(collection)
end
private
......
......@@ -12,9 +12,7 @@ module IncidentManagement
return IncidentManagement::OncallSchedule.none unless allowed?
collection = project.incident_management_oncall_schedules
collection = by_iid(collection)
collection
by_iid(collection)
end
private
......
......@@ -37,8 +37,7 @@ module StatusPage
notes = init_collection
notes = only_user(notes)
notes = to_publish(notes)
notes = chronological(notes)
notes
chronological(notes)
end
def init_collection
......
......@@ -20,14 +20,12 @@ module EE
end
def maintenance_mode_message
html = tag.div do
tag.div do
tag.p(class: 'gl-mb-3') do
concat(sprite_icon('information-o', css_class: 'gl-icon gl-mr-3'))
concat(custom_maintenance_mode_message)
end
end
html
end
def geo_secondary_read_only_message
......
......@@ -30,9 +30,7 @@ module EE
border_width = small ? '1px' : '2px'
html = %(<span class="#{wrapper_classes.join(' ')}" style="--label-inset-border: inset 0 0 0 #{border_width} #{label.color}; color: #{label.color}">#{label_html}</span>).html_safe
html
%(<span class="#{wrapper_classes.join(' ')}" style="--label-inset-border: inset 0 0 0 #{border_width} #{label.color}; color: #{label.color}">#{label_html}</span>).html_safe
end
def label_tooltip_title(label)
......
......@@ -14,9 +14,7 @@ module Dashboard
return Project.none unless License.feature_available?(feature)
project_ids = available_project_ids(project_ids) unless include_unavailable
projects = find_projects(project_ids)
projects
find_projects(project_ids)
end
private
......
......@@ -23,8 +23,7 @@ module Security
collection = init_collection
collection = filter_by_package_manager(collection)
collection = filter_by_vulnerable(collection)
collection = sort(collection)
collection
sort(collection)
end
private
......
......@@ -106,7 +106,7 @@ module Gitlab
raise WriteInsideReadOnlyTransactionError, 'A write query is performed inside a read-only transaction'
end
result = @load_balancer.read_write do |connection|
@load_balancer.read_write do |connection|
# Sticking has to be enabled before calling the method. Not doing so
# could lead to methods called in a block still being performed on a
# secondary instead of on a primary (when necessary).
......@@ -114,8 +114,6 @@ module Gitlab
connection.send(name, *args, &block)
end
result
end
private
......
......@@ -13,9 +13,7 @@ RSpec.describe BackfillOperationsFeatureFlagsIid do
def setup
namespace = namespaces.create!(name: 'foo', path: 'foo')
project = projects.create!(namespace_id: namespace.id)
project
projects.create!(namespace_id: namespace.id)
end
it 'backfills the iid for a flag' do
......
......@@ -19,9 +19,7 @@ RSpec.describe FeatureFlagIssues::DestroyService do
def setup
feature_flag = create(:operations_feature_flag, project: project)
issue = create(:issue, project: project)
feature_flag_issue = create(:feature_flag_issue, feature_flag: feature_flag, issue: issue)
feature_flag_issue
create(:feature_flag_issue, feature_flag: feature_flag, issue: issue)
end
describe '#execute' do
......
......@@ -52,9 +52,7 @@ module API
groups = groups.where.not(id: params[:skip_groups]) if params[:skip_groups].present?
order_options = { params[:order_by] => params[:sort] }
order_options["id"] ||= "asc"
groups = groups.reorder(order_options)
groups
groups.reorder(order_options)
end
# rubocop: enable CodeReuse/ActiveRecord
......
......@@ -209,10 +209,8 @@ module API
end
def find_personal_access_token
personal_access_token = find_personal_access_token_from_conan_jwt ||
find_personal_access_token_from_conan_jwt ||
find_personal_access_token_from_http_basic_auth
personal_access_token
end
def find_user_from_job_token
......
......@@ -113,9 +113,7 @@ module ErrorTracking
uri = URI(url)
uri.path.squeeze!('/')
# Remove trailing slash
uri = uri.to_s.delete_suffix('/')
uri
uri.to_s.delete_suffix('/')
end
def map_to_errors(issues)
......
......@@ -96,9 +96,7 @@ module Gitlab
initial_config = Config::External::Processor.new(initial_config, @context).perform
initial_config = Config::Extendable.new(initial_config).to_hash
initial_config = Config::Yaml::Tags::Resolver.new(initial_config).to_hash
initial_config = Config::EdgeStagesInjector.new(initial_config).to_hash
initial_config
Config::EdgeStagesInjector.new(initial_config).to_hash
end
def find_sha(project)
......
......@@ -25,8 +25,7 @@ module Gitlab
return unless value
encrypted_token = Base64.decode64(value)
decrypted_token = Encryptor.decrypt(AES256_GCM_OPTIONS.merge(value: encrypted_token, iv: nonce))
decrypted_token
Encryptor.decrypt(AES256_GCM_OPTIONS.merge(value: encrypted_token, iv: nonce))
end
end
end
......@@ -12,7 +12,7 @@ module Gitlab
author_url = build_author_url(build.commit, commit)
data = {
{
object_kind: 'build',
ref: build.ref,
......@@ -67,8 +67,6 @@ module Gitlab
environment: build_environment(build)
}
data
end
private
......
......@@ -199,8 +199,7 @@ module Gitlab
def linkify_issues(str)
str = str.gsub(/([Ii]ssue) ([0-9]+)/, '\1 #\2')
str = str.gsub(/([Cc]ase) ([0-9]+)/, '\1 #\2')
str
str.gsub(/([Cc]ase) ([0-9]+)/, '\1 #\2')
end
def escape_for_markdown(str)
......@@ -208,8 +207,7 @@ module Gitlab
str = str.gsub(/^-/, "\\-")
str = str.gsub("`", "\\~")
str = str.delete("\r")
str = str.gsub("\n", " \n")
str
str.gsub("\n", " \n")
end
def format_content(raw_content)
......
......@@ -127,10 +127,9 @@ module Gitlab
end
def decorate!
collection = each_with_index do |element, i|
each_with_index do |element, i|
@array[i] = yield(element)
end
collection
end
alias_method :to_ary, :to_a
......
......@@ -30,15 +30,13 @@ module Gitlab
# ex: " OR (relative_position = 23 AND id > 500)"
def second_attribute_condition
condition = <<~SQL
<<~SQL
OR (
#{table_condition(order_list.first, values.first, '=').to_sql}
AND
#{table_condition(order_list[1], values[1], operators[1]).to_sql}
)
SQL
condition
end
# ex: " OR (relative_position IS NULL)"
......
......@@ -14,15 +14,13 @@ module Gitlab
# ex: "(relative_position IS NULL AND id > 500)"
def first_attribute_condition
condition = <<~SQL
<<~SQL
(
#{table_condition(order_list.first, nil, 'is_null').to_sql}
AND
#{table_condition(order_list[1], values[1], operators[1]).to_sql}
)
SQL
condition
end
# ex: " OR (relative_position IS NOT NULL)"
......
......@@ -224,11 +224,9 @@ module Gitlab
frag_path = frag_path.gsub(DOTS_RE) do |dots|
rel_dir(dots.split('/').count)
end
frag_path = frag_path.gsub(IMPLICIT_ROOT) do
frag_path.gsub(IMPLICIT_ROOT) do
(Rails.root / 'app').to_s + '/'
end
frag_path
end
def rel_dir(n_steps_up)
......
......@@ -104,9 +104,7 @@ module Gitlab
def format_query(metric)
expression = remove_new_lines(metric[:expr])
expression = replace_variables(expression)
expression = replace_global_variables(expression, metric)
expression
replace_global_variables(expression, metric)
end
# Accomodates instance-defined Grafana variables.
......@@ -135,9 +133,7 @@ module Gitlab
def replace_global_variables(expression, metric)
expression = expression.gsub('$__interval', metric[:interval]) if metric[:interval]
expression = expression.gsub('$__from', query_params[:from])
expression = expression.gsub('$__to', query_params[:to])
expression
expression.gsub('$__to', query_params[:to])
end
# Removes new lines from expression.
......
......@@ -26,7 +26,6 @@ module Gitlab
# Repeated dashes are invalid (OpenShift limitation)
slugified.squeeze!('-')
slugified =
if slugified.size > 24 || slugified != name
# Maximum length: 24 characters (OpenShift limitation)
shorten_and_add_suffix(slugified)
......@@ -34,8 +33,6 @@ module Gitlab
# Cannot end with a dash (Kubernetes label limitation)
slugified.chomp('-')
end
slugified
end
private
......
......@@ -53,12 +53,10 @@ module QA
end
def run_saml_idp_service(group_name)
service = Service::DockerRun::SamlIdp.new(Runtime::Scenario.gitlab_address, group_name).tap do |runner|
Service::DockerRun::SamlIdp.new(Runtime::Scenario.gitlab_address, group_name).tap do |runner|
runner.pull
runner.register!
end
service
end
def remove_saml_idp_service(saml_idp_service)
......
......@@ -43,7 +43,7 @@ module GitalyTest
end
def env
env_hash = {
{
'HOME' => File.expand_path('tmp/tests'),
'GEM_PATH' => Gem.path.join(':'),
'BUNDLE_APP_CONFIG' => File.join(gemfile_dir, '.bundle'),
......@@ -54,8 +54,6 @@ module GitalyTest
# Git hooks can't run during tests as the internal API is not running.
'GITALY_TESTING_NO_GIT_HOOKS' => "1"
}
env_hash
end
# rubocop:disable GitlabSecurity/SystemCommandInjection
......
......@@ -2016,9 +2016,7 @@ RSpec.describe Gitlab::Database::MigrationHelpers do
def setup
namespace = namespaces.create!(name: 'foo', path: 'foo')
project = projects.create!(namespace_id: namespace.id)
project
projects.create!(namespace_id: namespace.id)
end
it 'generates iids properly for models created after the migration' do
......
......@@ -10,9 +10,7 @@ RSpec.describe BackfillOperationsFeatureFlagsActive do
def setup
namespace = namespaces.create!(name: 'foo', path: 'foo')
project = projects.create!(namespace_id: namespace.id)
project
projects.create!(namespace_id: namespace.id)
end
it 'executes successfully when there are no flags in the table' do
......
......@@ -10,9 +10,7 @@ RSpec.describe BackfillOperationsFeatureFlagsIid do
def setup
namespace = namespaces.create!(name: 'foo', path: 'foo')
project = projects.create!(namespace_id: namespace.id)
project
projects.create!(namespace_id: namespace.id)
end
it 'migrates successfully when there are no flags in the database' do
......
......@@ -10,9 +10,7 @@ RSpec.describe DeleteInternalIdsWhereFeatureFlagsUsage do
def setup
namespace = namespaces.create!(name: 'foo', path: 'foo')
project = projects.create!(namespace_id: namespace.id)
project
projects.create!(namespace_id: namespace.id)
end
it 'deletes feature flag rows from the internal_ids table' do
......
......@@ -12,9 +12,7 @@ RSpec.describe MigrateOpsFeatureFlagsScopesTargetUserIds do
def setup
namespace = namespaces.create!(name: 'foo', path: 'foo')
project = projects.create!(namespace_id: namespace.id)
flag = flags.create!(project_id: project.id, active: true, name: 'test_flag')
flag
flags.create!(project_id: project.id, active: true, name: 'test_flag')
end
it 'migrates successfully when there are no scopes in the database' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment