Commit d38cdaa4 authored by Lin Jen-Shin's avatar Lin Jen-Shin 🌙

Update from `rubocop -a`

parent 12bc446e
......@@ -31,12 +31,6 @@ Style/MutableConstant:
- 'ee/db/post_migrate/**/*'
- 'ee/db/geo/migrate/**/*'
Naming/UncommunicativeMethodParamName:
Enabled: false
Naming/MemoizedInstanceVariableName:
Enabled: false
Naming/FileName:
ExpectMatchingDefinition: true
Exclude:
......
......@@ -363,7 +363,7 @@ group :development, :test do
gem 'spring', '~> 2.0.0'
gem 'spring-commands-rspec', '~> 1.0.4'
gem 'gitlab-styles', '~> 2.4', require: false
gem 'gitlab-styles', '~> 2.4', git: 'https://gitlab.com/gitlab-org/gitlab-styles.git', branch: '2.4.1-rc', require: false
# Pin these dependencies, otherwise a new rule could break the CI pipelines
gem 'rubocop', '~> 0.54.0'
gem 'rubocop-rspec', '~> 1.22.1'
......
GIT
remote: https://gitlab.com/gitlab-org/gitlab-styles.git
revision: ea26af1601c6341f15b62a71b337208541cf7c1a
branch: 2.4.1-rc
specs:
gitlab-styles (2.4.1)
rubocop (~> 0.54.0)
rubocop-gitlab-security (~> 0.1.0)
rubocop-rspec (~> 1.19)
GEM
remote: https://rubygems.org/
specs:
......@@ -337,10 +347,6 @@ GEM
posix-spawn (~> 0.3)
gitlab-license (1.0.0)
gitlab-markup (1.6.4)
gitlab-styles (2.4.0)
rubocop (~> 0.54.0)
rubocop-gitlab-security (~> 0.1.0)
rubocop-rspec (~> 1.19)
gitlab_omniauth-ldap (2.0.4)
net-ldap (~> 0.16)
omniauth (~> 1.3)
......@@ -1078,7 +1084,7 @@ DEPENDENCIES
gitlab-gollum-rugged_adapter (~> 0.4.4)
gitlab-license (~> 1.0)
gitlab-markup (~> 1.6.4)
gitlab-styles (~> 2.4)
gitlab-styles (~> 2.4)!
gitlab_omniauth-ldap (~> 2.0.4)
gon (~> 6.2)
google-api-client (~> 0.19.8)
......
GIT
remote: https://gitlab.com/gitlab-org/gitlab-styles.git
revision: ea26af1601c6341f15b62a71b337208541cf7c1a
branch: 2.4.1-rc
specs:
gitlab-styles (2.4.1)
rubocop (~> 0.54.0)
rubocop-gitlab-security (~> 0.1.0)
rubocop-rspec (~> 1.19)
GEM
remote: https://rubygems.org/
specs:
......@@ -340,10 +350,6 @@ GEM
posix-spawn (~> 0.3)
gitlab-license (1.0.0)
gitlab-markup (1.6.4)
gitlab-styles (2.4.0)
rubocop (~> 0.54.0)
rubocop-gitlab-security (~> 0.1.0)
rubocop-rspec (~> 1.19)
gitlab_omniauth-ldap (2.0.4)
net-ldap (~> 0.16)
omniauth (~> 1.3)
......@@ -1088,7 +1094,7 @@ DEPENDENCIES
gitlab-gollum-rugged_adapter (~> 0.4.4)
gitlab-license (~> 1.0)
gitlab-markup (~> 1.6.4)
gitlab-styles (~> 2.4)
gitlab-styles (~> 2.4)!
gitlab_omniauth-ldap (~> 2.0.4)
gon (~> 6.2)
google-api-client (~> 0.19.8)
......
......@@ -12,7 +12,7 @@ class Projects::ImportsController < Projects::ApplicationController
end
def create
if @project.update_attributes(safe_import_params)
if @project.update(safe_import_params)
@project.reload.import_schedule
end
......
......@@ -47,7 +47,7 @@ class Admin::LicensesController < Admin::ApplicationController
flash[:alert] = "The license was removed. GitLab now no longer has a valid license."
end
redirect_to admin_license_path, status: 302
redirect_to admin_license_path, status: :found
end
private
......
......@@ -8,7 +8,7 @@ class Admin::PushRulesController < Admin::ApplicationController
end
def update
@push_rule.update_attributes(push_rule_params)
@push_rule.update(push_rule_params)
if @push_rule.valid?
redirect_to admin_push_rule_path, notice: 'Push Rule updated successfully.'
......
......@@ -48,7 +48,7 @@ module EE
respond_to do |format|
format.json { head :ok }
format.html { redirect_to boards_path, status: 302 }
format.html { redirect_to boards_path, status: :found }
end
end
......
......@@ -44,7 +44,7 @@ module EE
end
def render_bad_geo_auth(message)
render plain: "Geo JWT authentication failed: #{message}", status: 401
render plain: "Geo JWT authentication failed: #{message}", status: :unauthorized
end
end
end
......
......@@ -48,7 +48,6 @@ module EE
.find_by!(iid: params[:id])
super
end
# rubocop:disable Gitlab/ModuleWithInstanceVariables
def define_edit_vars
super
......
......@@ -13,20 +13,20 @@ module EE
if lookup.error.present?
# Failed to read keys
render json: { message: lookup.error }, status: 400
render json: { message: lookup.error }, status: :bad_request
elsif lookup.known_hosts.nil?
# Still working, come back later
render body: nil, status: 204
render body: nil, status: :no_content
else
render json: lookup
end
rescue ArgumentError => err
render json: { message: err.message }, status: 400
render json: { message: err.message }, status: :bad_request
end
override :update
def update
if project.update_attributes(safe_mirror_params)
if project.update(safe_mirror_params)
if project.mirror?
project.force_import_job!
......
......@@ -67,7 +67,7 @@ module EE
respond_to do |format|
format.html do
redirect_to edit_project_service_path(project, ::PrometheusService), status: 303
redirect_to edit_project_service_path(project, ::PrometheusService), status: :see_other
end
format.json do
head :ok
......
......@@ -17,7 +17,7 @@ class Groups::AnalyticsController < Groups::ApplicationController
format.json do
render json: GroupAnalyticsSerializer
.new(events: event_totals)
.represent(users), status: 200
.represent(users), status: :ok
end
end
end
......
......@@ -44,7 +44,7 @@ class Groups::HooksController < Groups::ApplicationController
def destroy
hook.destroy
redirect_to group_hooks_path(@group), status: 302
redirect_to group_hooks_path(@group), status: :found
end
private
......
......@@ -25,7 +25,7 @@ class Projects::PathLocksController < Projects::ApplicationController
head :ok
rescue PathLocks::UnlockService::AccessDenied, PathLocks::LockService::AccessDenied
return access_denied!
access_denied!
end
def destroy
......@@ -39,7 +39,7 @@ class Projects::PathLocksController < Projects::ApplicationController
respond_to do |format|
format.html do
redirect_to project_locks_path(@project), status: 302
redirect_to project_locks_path(@project), status: :found
end
format.js
end
......
......@@ -11,7 +11,7 @@ class Projects::PushRulesController < Projects::ApplicationController
def update
@push_rule = project.push_rule
@push_rule.update_attributes(push_rule_params)
@push_rule.update(push_rule_params)
if @push_rule.valid?
flash[:notice] = 'Push Rules updated successfully.'
......
......@@ -19,7 +19,7 @@ module PushRulesHelper
if push_rule.global?
messages << s_("ProjectSettings|This setting will be applied to all projects unless overridden by an admin.")
else
enabled_globally = PushRule.global&.public_send(rule) # rubocop:disable GitlabSecurity/PublicSend
enabled_globally = PushRule.global&.public_send(rule)
enabled_in_project = push_rule.public_send(rule) # rubocop:disable GitlabSecurity/PublicSend
if enabled_globally
......
......@@ -88,7 +88,7 @@ class Burndown
# reopened.
internal_clause =
::Issue
.joins("LEFT OUTER JOIN events e ON issues.id = e.target_id AND e.target_type = 'Issue' AND e.action = #{Event::CLOSED}") # rubocop:disable GitlabSecurity/SqlInjection
.joins("LEFT OUTER JOIN events e ON issues.id = e.target_id AND e.target_type = 'Issue' AND e.action = #{Event::CLOSED}")
.where(milestone: @milestone)
.where("state = 'closed' OR (state = 'opened' AND e.action = #{Event::CLOSED})") # rubocop:disable GitlabSecurity/SqlInjection
......
......@@ -11,7 +11,7 @@ module EE
# If we don't `protected_branch` or `protected_tag` would be empty and
# `project` cannot be delegated to it, which in turn would cause validations
# to fail.
has_many :"#{type}_access_levels", inverse_of: self.model_name.singular # rubocop:disable Cop/ActiveRecordDependent
has_many :"#{type}_access_levels", inverse_of: self.model_name.singular
accepts_nested_attributes_for :"#{type}_access_levels", allow_destroy: true
......
......@@ -11,7 +11,7 @@ module CiCd
private
def update_project
project.update_attributes(
project.update(
mirror: true,
mirror_trigger_builds: true,
mirror_overwrites_diverged_branches: true,
......@@ -21,7 +21,7 @@ module CiCd
end
def disable_project_features
project.project_feature.update_attributes(
project.project_feature.update(
issues_access_level: ProjectFeature::DISABLED,
merge_requests_access_level: ProjectFeature::DISABLED,
wiki_access_level: ProjectFeature::DISABLED,
......
......@@ -16,7 +16,7 @@ module EE
user_mirrors.find_each do |mirror|
new_mirror_user = first_mirror_owner(user, mirror)
mirror.update_attributes(mirror_user: new_mirror_user)
mirror.update(mirror_user: new_mirror_user)
::NotificationService.new.project_mirror_user_changed(new_mirror_user, user.name, mirror)
end
end
......
......@@ -13,7 +13,7 @@ module EpicIssues
epic_issue.save!
success
rescue ActiveRecord::RecordNotFound
return error('Epic issue not found for given params', 404)
error('Epic issue not found for given params', 404)
end
private
......
......@@ -10,16 +10,16 @@ module Geo
return false
end
return true
true
rescue Gitlab::Geo::GeoNodeNotFoundError => e
log_error(e.to_s)
return false
false
rescue OpenSSL::Cipher::CipherError => e
log_error('Error decrypting the Geo secret from the database. Check that the primary uses the correct db_key_base.', e)
return false
false
rescue Gitlab::HTTP::Error, Timeout::Error, SocketError, SystemCallError, OpenSSL::SSL::SSLError => e
log_error('Failed to post status data to primary', e)
return false
false
end
private
......
......@@ -10,7 +10,7 @@ module Projects
private
def update_project
project.update_attributes(
project.update(
container_registry_enabled: false,
mirror: true,
mirror_trigger_builds: true,
......@@ -21,7 +21,7 @@ module Projects
end
def disable_project_features
project.project_feature.update_attributes(
project.project_feature.update(
issues_access_level: ProjectFeature::DISABLED,
merge_requests_access_level: ProjectFeature::DISABLED,
wiki_access_level: ProjectFeature::DISABLED,
......
......@@ -143,7 +143,7 @@ module API
if geo_node.primary?
forbidden!('Primary node cannot be edited')
elsif geo_node.update_attributes(update_params)
elsif geo_node.update(update_params)
present geo_node, with: EE::API::Entities::GeoNode
else
render_validation_error!(geo_node)
......
......@@ -58,7 +58,7 @@ module API
push_rule = user_project.push_rule
not_found!('Push Rule') unless push_rule
if push_rule.update_attributes(declared_params(include_missing: false))
if push_rule.update(declared_params(include_missing: false))
present push_rule, with: EE::API::Entities::ProjectPushRule
else
render_validation_error!(push_rule)
......
# frozen_string_literal: true
# rubocop:disable Metrics/LineLength
# rubocop:disable Style/Documentation
module Gitlab
module BackgroundMigration
......
......@@ -33,7 +33,7 @@ module Gitlab
def use_primary(&blk)
used_primary = @use_primary
@use_primary = true
return yield
yield
ensure
@use_primary = used_primary || @performed_write
end
......
......@@ -85,7 +85,7 @@ module Gitlab
sha = head_commit.try(:sha)
sha ||= Gitlab::Git::BLANK_SHA
index_status.update_attributes(last_commit: sha, indexed_at: Time.now)
index_status.update(last_commit: sha, indexed_at: Time.now)
project.index_status(true)
end
end
......
......@@ -87,7 +87,6 @@ module Gitlab
end
end
# rubocop: disable Rails/Output
def status
Gitlab::Geo::DatabaseTasks.with_geo_db do
unless ActiveRecord::SchemaMigration.table_exists?
......
......@@ -25,7 +25,7 @@ module Gitlab
end
end
return ''
''
rescue => e
e.message
end
......
......@@ -31,7 +31,7 @@ module Gitlab
encrypted = cipher.update(access_token) + cipher.final
self.state = "#{oauth_salt}:#{Base64.urlsafe_encode64(encrypted)}"
rescue OpenSSL::OpenSSLError
return false
false
end
def extract_logout_token
......@@ -41,7 +41,7 @@ module Gitlab
decipher = logout_token_cipher(salt, :decrypt)
decipher.update(Base64.urlsafe_decode64(encrypted)) + decipher.final
rescue OpenSSL::OpenSSLError
return false
false
end
def get_oauth_state_return_to
......
......@@ -81,7 +81,7 @@ module Gitlab
end
if dryrun
puts "Sidekiq command: #{cmd}" # rubocop:disable Rails/Output
puts "Sidekiq command: #{cmd}"
return
end
......
......@@ -30,7 +30,7 @@ describe Projects::MergeRequests::CreationsController do
let(:created_merge_request) { assigns(:merge_request) }
before do
project.update_attributes(approvals_before_merge: 2)
project.update(approvals_before_merge: 2)
end
context 'when it is less than the one in the target project' do
......@@ -81,8 +81,8 @@ describe Projects::MergeRequests::CreationsController do
context 'when the target project is a fork of a deleted project' do
before do
original_project = create(:project)
project.update_attributes(forked_from_project: original_project, approvals_before_merge: 4)
original_project.update_attributes(pending_delete: true)
project.update(forked_from_project: original_project, approvals_before_merge: 4)
original_project.update(pending_delete: true)
create_merge_request(approvals_before_merge: 3)
end
......
......@@ -99,7 +99,7 @@ describe Projects::MergeRequestsController do
describe 'PUT update' do
before do
project.update_attributes(approvals_before_merge: 2)
project.update(approvals_before_merge: 2)
end
def update_merge_request(params = {})
......@@ -112,7 +112,7 @@ describe Projects::MergeRequestsController do
context 'when the merge request requires approval' do
before do
project.update_attributes(approvals_before_merge: 1)
project.update(approvals_before_merge: 1)
end
it_behaves_like 'update invalid issuable', MergeRequest
......@@ -120,12 +120,12 @@ describe Projects::MergeRequestsController do
context 'overriding approvers per MR' do
before do
project.update_attributes(approvals_before_merge: 1)
project.update(approvals_before_merge: 1)
end
context 'enabled' do
before do
project.update_attributes(disable_overriding_approvers_per_merge_request: false)
project.update(disable_overriding_approvers_per_merge_request: false)
end
it 'updates approvals' do
......@@ -141,7 +141,7 @@ describe Projects::MergeRequestsController do
before do
project.add_developer(new_approver)
project.update_attributes(disable_overriding_approvers_per_merge_request: true)
project.update(disable_overriding_approvers_per_merge_request: true)
end
it 'does not update approvals_before_merge' do
......@@ -166,7 +166,7 @@ describe Projects::MergeRequestsController do
shared_examples 'approvals_before_merge param' do
before do
project.update_attributes(approvals_before_merge: 2)
project.update(approvals_before_merge: 2)
end
context 'approvals_before_merge not set for the existing MR' do
......@@ -296,7 +296,7 @@ describe Projects::MergeRequestsController do
before do
upstream.add_developer(user)
upstream.update_attributes(approvals_before_merge: 2)
upstream.update(approvals_before_merge: 2)
end
it_behaves_like 'approvals_before_merge param'
......@@ -307,7 +307,7 @@ describe Projects::MergeRequestsController do
before do
project.add_developer(user)
project.update_attributes(approvals_before_merge: 0)
project.update(approvals_before_merge: 0)
end
it_behaves_like 'approvals_before_merge param'
......
......@@ -10,7 +10,7 @@ FactoryBot.define do
end
after(:create) do |epic, evaluator|
epic.update_attributes(labels: evaluator.labels)
epic.update(labels: evaluator.labels)
end
end
end
......
......@@ -17,7 +17,7 @@ describe 'Merge request > User selects branches for new MR', :js do
context 'when approvals are zero for the target project' do
before do
project.update_attributes(approvals_before_merge: 0)
project.update(approvals_before_merge: 0)
visit project_new_merge_request_path(project, merge_request: { target_branch: 'master', source_branch: 'feature_conflict' })
end
......
......@@ -17,12 +17,12 @@ describe 'Project mirror', :js do
let(:timestamp) { Time.now }
before do
import_state.update_attributes(next_execution_timestamp: timestamp + 10.minutes)
import_state.update(next_execution_timestamp: timestamp + 10.minutes)
end
context 'when able to force update' do
it 'forces import' do
import_state.update_attributes(last_update_at: timestamp - 8.minutes)
import_state.update(last_update_at: timestamp - 8.minutes)
expect_any_instance_of(EE::Project).to receive(:force_import_job!)
......@@ -36,7 +36,7 @@ describe 'Project mirror', :js do
context 'when unable to force update' do
it 'does not force import' do
import_state.update_attributes(last_update_at: timestamp - 3.minutes)
import_state.update(last_update_at: timestamp - 3.minutes)
expect_any_instance_of(EE::Project).not_to receive(:force_import_job!)
......
......@@ -11,7 +11,7 @@ describe "User manages members" do
shared_examples "when group membership is unlocked" do
before do
group.update_attributes(membership_lock: false)
group.update(membership_lock: false)
visit(project_project_members_path(project))
end
......@@ -21,7 +21,7 @@ describe "User manages members" do
shared_examples "when group membership is locked" do
before do
group.update_attributes(membership_lock: true)
group.update(membership_lock: true)
visit(project_project_members_path(project))
end
......
......@@ -44,7 +44,7 @@ describe MigrateCiJobArtifactsToSeparateRegistry, :geo, :migration do
expect(job_artifact_registry.all.count).to eq(3)
entry = file_registry.find_by(file_id: 1)
entry.update_attributes(success: false, bytes: 10240, sha256: '10' * 64)
entry.update(success: false, bytes: 10240, sha256: '10' * 64)
expect(job_artifact_registry.where(artifact_id: 1, success: false, bytes: 10240, sha256: '10' * 64).count).to eq(1)
# Ensure that *only* the correct job artifact is updated
......
......@@ -71,7 +71,7 @@ describe Project do
Timecop.freeze do
expect do
project.update_attributes(mirror: true, mirror_user_id: project.creator.id, import_url: generate(:url))
project.update(mirror: true, mirror_user_id: project.creator.id, import_url: generate(:url))
end.to change { ProjectImportState.count }.by(1)
expect(project.import_state.next_execution_timestamp).to eq(Time.now)
......@@ -85,7 +85,7 @@ describe Project do
Timecop.freeze do
expect do
project.update_attributes(mirror: true, mirror_user_id: project.creator.id)
project.update(mirror: true, mirror_user_id: project.creator.id)
end.not_to change { ProjectImportState.count }
expect(project.import_state.next_execution_timestamp).to eq(Time.now)
......@@ -123,7 +123,7 @@ describe Project do
end
it 'returns empty if next_execution_timestamp is in the future' do
import_state.update_attributes(next_execution_timestamp: timestamp + 2.minutes)
import_state.update(next_execution_timestamp: timestamp + 2.minutes)
expect(described_class.mirrors_to_sync(timestamp)).to be_empty
end
......@@ -137,7 +137,7 @@ describe Project do
end
it 'returns empty if next_execution_timestamp is in the future' do
project.import_state.update_attributes(next_execution_timestamp: timestamp + 2.minutes)
project.import_state.update(next_execution_timestamp: timestamp + 2.minutes)
expect(described_class.mirrors_to_sync(timestamp)).to be_empty
end
......@@ -167,7 +167,7 @@ describe Project do
describe 'hard failing a mirror' do
it 'sends a notification' do
project = create(:project, :mirror, :import_started)
project.import_state.update_attributes(retry_count: Gitlab::Mirror::MAX_RETRY)
project.import_state.update(retry_count: Gitlab::Mirror::MAX_RETRY)
expect_any_instance_of(EE::NotificationService).to receive(:mirror_was_hard_failed).with(project)
......@@ -407,7 +407,7 @@ describe Project do
expect(RepositoryRemoveRemoteWorker).to receive(:perform_async).with(project.id, ::Repository::MIRROR_REMOTE).and_call_original
project.update_attributes(import_url: "http://test.com")
project.update(import_url: "http://test.com")
end
end
......@@ -416,7 +416,7 @@ describe Project do
project = create(:project, :mirror, :import_scheduled)
import_state = project.import_state
import_state.update_attributes(last_update_started_at: import_state.last_update_scheduled_at + 5.minutes)
import_state.update(last_update_started_at: import_state.last_update_scheduled_at + 5.minutes)
expect(project.mirror_waiting_duration).to eq(300)
end
......@@ -426,7 +426,7 @@ describe Project do
it 'returns in seconds the time spent updating' do
project = create(:project, :mirror, :import_started)
project.update_attributes(mirror_last_update_at: project.import_state.last_update_started_at + 5.minutes)
project.update(mirror_last_update_at: project.import_state.last_update_started_at + 5.minutes)
expect(project.mirror_update_duration).to eq(300)
end
......@@ -734,7 +734,7 @@ describe Project do
context 'when repository_size_limit is configured' do
before do
project.update_attributes(repository_size_limit: 1024)
project.update(repository_size_limit: 1024)
end
context 'with an EES license' do
......
......@@ -139,7 +139,7 @@ describe PushRule do
it 'raises a MatchError when the regex is invalid' do
push_rule[regex_attr] = '+'
expect { push_rule.public_send(method_name, 'foo') } # rubocop:disable GitlabSecurity/PublicSend
expect { push_rule.public_send(method_name, 'foo') }
.to raise_error(PushRule::MatchError, /\ARegular expression '\+' is invalid/)
end
end
......
......@@ -46,7 +46,7 @@ describe API::MergeRequests do
context 'the approvals_before_merge param' do
context 'when the target project has disable_overriding_approvers_per_merge_request set to true' do
before do
project.update_attributes(disable_overriding_approvers_per_merge_request: true)
project.update(disable_overriding_approvers_per_merge_request: true)
create_merge_request(approvals_before_merge: 1)
end
......@@ -57,7 +57,7 @@ describe API::MergeRequests do
context 'when the target project has approvals_before_merge set to zero' do
before do
project.update_attributes(approvals_before_merge: 0)
project.update(approvals_before_merge: 0)
create_merge_request(approvals_before_merge: 1)
end
......@@ -73,7 +73,7 @@ describe API::MergeRequests do
context 'when the target project has a non-zero approvals_before_merge' do
context 'when the approvals_before_merge param is less than or equal to the value in the target project' do
before do
project.update_attributes(approvals_before_merge: 2)
project.update(approvals_before_merge: 2)
create_merge_request(approvals_before_merge: 1)
end