Commit 07d3d447 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Move ModuleWithInstanceVariables to Gitlab namespace

And use .rubocop.yml to exclude paths we don't care,
rather than using the cop itself to exclude.
parent 15edf741
...@@ -1185,7 +1185,20 @@ RSpec/SubjectStub: ...@@ -1185,7 +1185,20 @@ RSpec/SubjectStub:
RSpec/VerifiedDoubles: RSpec/VerifiedDoubles:
Enabled: false Enabled: false
# GitlabSecurity ############################################################## # Gitlab ###################################################################
Gitlab/ModuleWithInstanceVariables:
Enable: true
Exclude:
# We ignore Rails helpers right now because it's hard to workaround it
- app/helpers/*_helper.rb
# We ignore Rails mailers right now because it's hard to workaround it
- app/mailers/emails/*.rb
# We ignore spec helpers because it usually doesn't matter
- spec/support/**/*.rb
- features/steps/**/*.rb
# GitlabSecurity ###########################################################
GitlabSecurity/DeepMunge: GitlabSecurity/DeepMunge:
Enabled: true Enabled: true
......
...@@ -24,11 +24,11 @@ module BoardsResponses ...@@ -24,11 +24,11 @@ module BoardsResponses
end end
def respond_with_boards def respond_with_boards
respond_with(@boards) # rubocop:disable Cop/ModuleWithInstanceVariables respond_with(@boards) # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
def respond_with_board def respond_with_board
respond_with(@board) # rubocop:disable Cop/ModuleWithInstanceVariables respond_with(@board) # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
def respond_with(resource) def respond_with(resource)
......
...@@ -2,7 +2,7 @@ module CreatesCommit ...@@ -2,7 +2,7 @@ module CreatesCommit
extend ActiveSupport::Concern extend ActiveSupport::Concern
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def create_commit(service, success_path:, failure_path:, failure_view: nil, success_notice: nil) def create_commit(service, success_path:, failure_path:, failure_view: nil, success_notice: nil)
if can?(current_user, :push_code, @project) if can?(current_user, :push_code, @project)
@project_to_commit_into = @project @project_to_commit_into = @project
...@@ -47,7 +47,7 @@ module CreatesCommit ...@@ -47,7 +47,7 @@ module CreatesCommit
end end
end end
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
def authorize_edit_tree! def authorize_edit_tree!
return if can_collaborate_with_project? return if can_collaborate_with_project?
...@@ -80,7 +80,7 @@ module CreatesCommit ...@@ -80,7 +80,7 @@ module CreatesCommit
end end
end end
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def new_merge_request_path def new_merge_request_path
project_new_merge_request_path( project_new_merge_request_path(
@project_to_commit_into, @project_to_commit_into,
...@@ -92,13 +92,13 @@ module CreatesCommit ...@@ -92,13 +92,13 @@ module CreatesCommit
} }
) )
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
def existing_merge_request_path def existing_merge_request_path
project_merge_request_path(@project, @merge_request) # rubocop:disable Cop/ModuleWithInstanceVariables project_merge_request_path(@project, @merge_request) # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def merge_request_exists? def merge_request_exists?
strong_memoize(:merge_request) do strong_memoize(:merge_request) do
MergeRequestsFinder.new(current_user, project_id: @project.id) MergeRequestsFinder.new(current_user, project_id: @project.id)
...@@ -110,10 +110,10 @@ module CreatesCommit ...@@ -110,10 +110,10 @@ module CreatesCommit
target_branch: @start_branch) target_branch: @start_branch)
end end
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
def different_project? def different_project?
@project_to_commit_into != @project # rubocop:disable Cop/ModuleWithInstanceVariables @project_to_commit_into != @project # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
def create_merge_request? def create_merge_request?
...@@ -121,6 +121,6 @@ module CreatesCommit ...@@ -121,6 +121,6 @@ module CreatesCommit
# as the target branch in the same project, # as the target branch in the same project,
# we don't want to create a merge request. # we don't want to create a merge request.
params[:create_merge_request].present? && params[:create_merge_request].present? &&
(different_project? || @start_branch != @branch_name) # rubocop:disable Cop/ModuleWithInstanceVariables (different_project? || @start_branch != @branch_name) # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
end end
module GroupTree module GroupTree
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def render_group_tree(groups) def render_group_tree(groups)
@groups = if params[:filter].present? @groups = if params[:filter].present?
Gitlab::GroupHierarchy.new(groups.search(params[:filter])) Gitlab::GroupHierarchy.new(groups.search(params[:filter]))
...@@ -21,6 +21,6 @@ module GroupTree ...@@ -21,6 +21,6 @@ module GroupTree
render json: serializer.represent(@groups) render json: serializer.represent(@groups)
end end
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
end end
end end
...@@ -17,7 +17,7 @@ module IssuableActions ...@@ -17,7 +17,7 @@ module IssuableActions
end end
def update def update
@issuable = update_service.execute(issuable) # rubocop:disable Cop/ModuleWithInstanceVariables @issuable = update_service.execute(issuable) # rubocop:disable Gitlab/ModuleWithInstanceVariables
respond_to do |format| respond_to do |format|
format.html do format.html do
...@@ -83,7 +83,7 @@ module IssuableActions ...@@ -83,7 +83,7 @@ module IssuableActions
def render_conflict_response def render_conflict_response
respond_to do |format| respond_to do |format|
format.html do format.html do
@conflict = true # rubocop:disable Cop/ModuleWithInstanceVariables @conflict = true # rubocop:disable Gitlab/ModuleWithInstanceVariables
render :edit render :edit
end end
...@@ -98,7 +98,7 @@ module IssuableActions ...@@ -98,7 +98,7 @@ module IssuableActions
end end
def labels def labels
@labels ||= LabelsFinder.new(current_user, project_id: @project.id).execute # rubocop:disable Cop/ModuleWithInstanceVariables @labels ||= LabelsFinder.new(current_user, project_id: @project.id).execute # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
def authorize_destroy_issuable! def authorize_destroy_issuable!
...@@ -108,7 +108,7 @@ module IssuableActions ...@@ -108,7 +108,7 @@ module IssuableActions
end end
def authorize_admin_issuable! def authorize_admin_issuable!
unless can?(current_user, :"admin_#{resource_name}", @project) # rubocop:disable Cop/ModuleWithInstanceVariables unless can?(current_user, :"admin_#{resource_name}", @project) # rubocop:disable Gitlab/ModuleWithInstanceVariables
return access_denied! return access_denied!
end end
end end
...@@ -142,7 +142,7 @@ module IssuableActions ...@@ -142,7 +142,7 @@ module IssuableActions
@resource_name ||= controller_name.singularize @resource_name ||= controller_name.singularize
end end
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def render_entity_json def render_entity_json
if @issuable.valid? if @issuable.valid?
render json: serializer.represent(@issuable) render json: serializer.represent(@issuable)
...@@ -150,7 +150,7 @@ module IssuableActions ...@@ -150,7 +150,7 @@ module IssuableActions
render json: { errors: @issuable.errors.full_messages }, status: :unprocessable_entity render json: { errors: @issuable.errors.full_messages }, status: :unprocessable_entity
end end
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
def serializer def serializer
raise NotImplementedError raise NotImplementedError
...@@ -161,6 +161,6 @@ module IssuableActions ...@@ -161,6 +161,6 @@ module IssuableActions
end end
def parent def parent
@project || @group # rubocop:disable Cop/ModuleWithInstanceVariables @project || @group # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
end end
...@@ -10,7 +10,7 @@ module IssuableCollections ...@@ -10,7 +10,7 @@ module IssuableCollections
private private
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def set_issuables_index def set_issuables_index
@issuables = issuables_collection @issuables = issuables_collection
@issuables = @issuables.page(params[:page]) @issuables = @issuables.page(params[:page])
...@@ -35,7 +35,7 @@ module IssuableCollections ...@@ -35,7 +35,7 @@ module IssuableCollections
@users.push(author) if author @users.push(author) if author
end end
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
def issuables_collection def issuables_collection
finder.execute.preload(preload_for_collection) finder.execute.preload(preload_for_collection)
...@@ -44,7 +44,7 @@ module IssuableCollections ...@@ -44,7 +44,7 @@ module IssuableCollections
def redirect_out_of_range(total_pages) def redirect_out_of_range(total_pages)
return false if total_pages.zero? return false if total_pages.zero?
out_of_range = @issuables.current_page > total_pages # rubocop:disable Cop/ModuleWithInstanceVariables out_of_range = @issuables.current_page > total_pages # rubocop:disable Gitlab/ModuleWithInstanceVariables
if out_of_range if out_of_range
redirect_to(url_for(params.merge(page: total_pages, only_path: true))) redirect_to(url_for(params.merge(page: total_pages, only_path: true)))
...@@ -54,7 +54,7 @@ module IssuableCollections ...@@ -54,7 +54,7 @@ module IssuableCollections
end end
def issuable_page_count def issuable_page_count
page_count_for_relation(@issuables, finder.row_count) # rubocop:disable Cop/ModuleWithInstanceVariables page_count_for_relation(@issuables, finder.row_count) # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
def page_count_for_relation(relation, row_count) def page_count_for_relation(relation, row_count)
...@@ -69,7 +69,7 @@ module IssuableCollections ...@@ -69,7 +69,7 @@ module IssuableCollections
finder_class.new(current_user, filter_params) finder_class.new(current_user, filter_params)
end end
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def filter_params def filter_params
set_sort_order_from_cookie set_sort_order_from_cookie
set_default_state set_default_state
...@@ -94,7 +94,7 @@ module IssuableCollections ...@@ -94,7 +94,7 @@ module IssuableCollections
@filter_params.permit(IssuableFinder::VALID_PARAMS) @filter_params.permit(IssuableFinder::VALID_PARAMS)
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
def set_default_state def set_default_state
params[:state] = 'opened' if params[:state].blank? params[:state] = 'opened' if params[:state].blank?
...@@ -135,7 +135,7 @@ module IssuableCollections ...@@ -135,7 +135,7 @@ module IssuableCollections
def finder def finder
strong_memoize(:finder) do strong_memoize(:finder) do
issuable_finder_for(@finder_type) # rubocop:disable Cop/ModuleWithInstanceVariables issuable_finder_for(@finder_type) # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
end end
......
...@@ -2,7 +2,7 @@ module IssuesAction ...@@ -2,7 +2,7 @@ module IssuesAction
extend ActiveSupport::Concern extend ActiveSupport::Concern
include IssuableCollections include IssuableCollections
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def issues def issues
@finder_type = IssuesFinder @finder_type = IssuesFinder
@label = finder.labels.first @label = finder.labels.first
...@@ -18,5 +18,5 @@ module IssuesAction ...@@ -18,5 +18,5 @@ module IssuesAction
format.atom { render layout: 'xml.atom' } format.atom { render layout: 'xml.atom' }
end end
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
end end
...@@ -2,7 +2,7 @@ module MergeRequestsAction ...@@ -2,7 +2,7 @@ module MergeRequestsAction
extend ActiveSupport::Concern extend ActiveSupport::Concern
include IssuableCollections include IssuableCollections
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def merge_requests def merge_requests
@finder_type = MergeRequestsFinder @finder_type = MergeRequestsFinder
@label = finder.labels.first @label = finder.labels.first
...@@ -11,7 +11,7 @@ module MergeRequestsAction ...@@ -11,7 +11,7 @@ module MergeRequestsAction
@issuable_meta_data = issuable_meta_data(@merge_requests, collection_type) @issuable_meta_data = issuable_meta_data(@merge_requests, collection_type)
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
private private
......
...@@ -6,7 +6,7 @@ module MilestoneActions ...@@ -6,7 +6,7 @@ module MilestoneActions
format.html { redirect_to milestone_redirect_path } format.html { redirect_to milestone_redirect_path }
format.json do format.json do
render json: tabs_json("shared/milestones/_merge_requests_tab", { render json: tabs_json("shared/milestones/_merge_requests_tab", {
merge_requests: @milestone.sorted_merge_requests, # rubocop:disable Cop/ModuleWithInstanceVariables merge_requests: @milestone.sorted_merge_requests, # rubocop:disable Gitlab/ModuleWithInstanceVariables
show_project_name: true show_project_name: true
}) })
end end
...@@ -18,7 +18,7 @@ module MilestoneActions ...@@ -18,7 +18,7 @@ module MilestoneActions
format.html { redirect_to milestone_redirect_path } format.html { redirect_to milestone_redirect_path }
format.json do format.json do
render json: tabs_json("shared/milestones/_participants_tab", { render json: tabs_json("shared/milestones/_participants_tab", {
users: @milestone.participants # rubocop:disable Cop/ModuleWithInstanceVariables users: @milestone.participants # rubocop:disable Gitlab/ModuleWithInstanceVariables
}) })
end end
end end
...@@ -29,7 +29,7 @@ module MilestoneActions ...@@ -29,7 +29,7 @@ module MilestoneActions
format.html { redirect_to milestone_redirect_path } format.html { redirect_to milestone_redirect_path }
format.json do format.json do
render json: tabs_json("shared/milestones/_labels_tab", { render json: tabs_json("shared/milestones/_labels_tab", {
labels: @milestone.labels # rubocop:disable Cop/ModuleWithInstanceVariables labels: @milestone.labels # rubocop:disable Gitlab/ModuleWithInstanceVariables
}) })
end end
...@@ -44,7 +44,7 @@ module MilestoneActions ...@@ -44,7 +44,7 @@ module MilestoneActions
} }
end end
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def milestone_redirect_path def milestone_redirect_path
if @project if @project
project_milestone_path(@project, @milestone) project_milestone_path(@project, @milestone)
...@@ -54,5 +54,5 @@ module MilestoneActions ...@@ -54,5 +54,5 @@ module MilestoneActions
dashboard_milestone_path(@milestone.safe_title, title: @milestone.title) dashboard_milestone_path(@milestone.safe_title, title: @milestone.title)
end end
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
end end
...@@ -31,7 +31,7 @@ module NotesActions ...@@ -31,7 +31,7 @@ module NotesActions
render json: notes_json render json: notes_json
end end
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def create def create
create_params = note_params.merge( create_params = note_params.merge(
merge_request_diff_head_sha: params[:merge_request_diff_head_sha], merge_request_diff_head_sha: params[:merge_request_diff_head_sha],
...@@ -49,9 +49,9 @@ module NotesActions ...@@ -49,9 +49,9 @@ module NotesActions
format.html { redirect_back_or_default } format.html { redirect_back_or_default }
end end
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def update def update
@note = Notes::UpdateService.new(project, current_user, note_params).execute(note) @note = Notes::UpdateService.new(project, current_user, note_params).execute(note)
...@@ -64,7 +64,7 @@ module NotesActions ...@@ -64,7 +64,7 @@ module NotesActions
format.html { redirect_back_or_default } format.html { redirect_back_or_default }
end end
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
def destroy def destroy
if note.editable? if note.editable?
...@@ -143,7 +143,7 @@ module NotesActions ...@@ -143,7 +143,7 @@ module NotesActions
end end
else else
template = "discussions/_diff_discussion" template = "discussions/_diff_discussion"
@fresh_discussion = true # rubocop:disable Cop/ModuleWithInstanceVariables @fresh_discussion = true # rubocop:disable Gitlab/ModuleWithInstanceVariables
locals = { discussions: [discussion], on_image: on_image } locals = { discussions: [discussion], on_image: on_image }
end end
...@@ -196,7 +196,7 @@ module NotesActions ...@@ -196,7 +196,7 @@ module NotesActions
end end
def noteable def noteable
@noteable ||= notes_finder.target || @note&.noteable # rubocop:disable Cop/ModuleWithInstanceVariables @noteable ||= notes_finder.target || @note&.noteable # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
def require_noteable! def require_noteable!
......
module PreviewMarkdown module PreviewMarkdown
extend ActiveSupport::Concern extend ActiveSupport::Concern
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def preview_markdown def preview_markdown
result = PreviewMarkdownService.new(@project, current_user, params).execute result = PreviewMarkdownService.new(@project, current_user, params).execute
...@@ -20,5 +20,5 @@ module PreviewMarkdown ...@@ -20,5 +20,5 @@ module PreviewMarkdown
} }
} }
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
end end
module RendersCommits module RendersCommits
def prepare_commits_for_rendering(commits) def prepare_commits_for_rendering(commits)
Banzai::CommitRenderer.render(commits, @project, current_user) # rubocop:disable Cop/ModuleWithInstanceVariables Banzai::CommitRenderer.render(commits, @project, current_user) # rubocop:disable Gitlab/ModuleWithInstanceVariables
commits commits
end end
......
module RendersNotes module RendersNotes
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def prepare_notes_for_rendering(notes, noteable = nil) def prepare_notes_for_rendering(notes, noteable = nil)
preload_noteable_for_regular_notes(notes) preload_noteable_for_regular_notes(notes)
preload_max_access_for_authors(notes, @project) preload_max_access_for_authors(notes, @project)
...@@ -8,7 +8,7 @@ module RendersNotes ...@@ -8,7 +8,7 @@ module RendersNotes
notes notes
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
private private
......
...@@ -66,7 +66,7 @@ module ServiceParams ...@@ -66,7 +66,7 @@ module ServiceParams
FILTER_BLANK_PARAMS = [:password].freeze FILTER_BLANK_PARAMS = [:password].freeze
def service_params def service_params
dynamic_params = @service.event_channel_names + @service.event_names # rubocop:disable Cop/ModuleWithInstanceVariables dynamic_params = @service.event_channel_names + @service.event_names # rubocop:disable Gitlab/ModuleWithInstanceVariables
service_params = params.permit(:id, service: ALLOWED_PARAMS_CE + dynamic_params) service_params = params.permit(:id, service: ALLOWED_PARAMS_CE + dynamic_params)
if service_params[:service].is_a?(Hash) if service_params[:service].is_a?(Hash)
......
...@@ -4,7 +4,7 @@ module SnippetsActions ...@@ -4,7 +4,7 @@ module SnippetsActions
def edit def edit
end end
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def raw def raw
disposition = params[:inline] == 'false' ? 'attachment' : 'inline' disposition = params[:inline] == 'false' ? 'attachment' : 'inline'
...@@ -15,7 +15,7 @@ module SnippetsActions ...@@ -15,7 +15,7 @@ module SnippetsActions
filename: @snippet.sanitized_file_name filename: @snippet.sanitized_file_name
) )
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
private private
......
...@@ -46,7 +46,7 @@ module Noteable ...@@ -46,7 +46,7 @@ module Noteable
notes.inc_relations_for_view.grouped_diff_discussions(*args) notes.inc_relations_for_view.grouped_diff_discussions(*args)
end end
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def resolvable_discussions def resolvable_discussions
@resolvable_discussions ||= @resolvable_discussions ||=
if defined?(@discussions) if defined?(@discussions)
...@@ -55,7 +55,7 @@ module Noteable ...@@ -55,7 +55,7 @@ module Noteable
discussion_notes.resolvable.discussions(self) discussion_notes.resolvable.discussions(self)
end end
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
def discussions_resolvable? def discussions_resolvable?
resolvable_discussions.any?(&:resolvable?) resolvable_discussions.any?(&:resolvable?)
......
...@@ -52,7 +52,7 @@ module RelativePositioning ...@@ -52,7 +52,7 @@ module RelativePositioning
# to its predecessor. This process will recursively move all the predecessors until we have a place # to its predecessor. This process will recursively move all the predecessors until we have a place
if (after.relative_position - before.relative_position) < 2 if (after.relative_position - before.relative_position) < 2
before.move_before before.move_before
@positionable_neighbours = [before] # rubocop:disable Cop/ModuleWithInstanceVariables @positionable_neighbours = [before] # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
self.relative_position = position_between(before.relative_position, after.relative_position) self.relative_position = position_between(before.relative_position, after.relative_position)
...@@ -65,7 +65,7 @@ module RelativePositioning ...@@ -65,7 +65,7 @@ module RelativePositioning
if before.shift_after? if before.shift_after?
issue_to_move = self.class.in_projects(project_ids).find_by!(relative_position: pos_after) issue_to_move = self.class.in_projects(project_ids).find_by!(relative_position: pos_after)
issue_to_move.move_after issue_to_move.move_after
@positionable_neighbours = [issue_to_move] # rubocop:disable Cop/ModuleWithInstanceVariables @positionable_neighbours = [issue_to_move] # rubocop:disable Gitlab/ModuleWithInstanceVariables
pos_after = issue_to_move.relative_position pos_after = issue_to_move.relative_position
end end
...@@ -80,7 +80,7 @@ module RelativePositioning ...@@ -80,7 +80,7 @@ module RelativePositioning
if after.shift_before? if after.shift_before?
issue_to_move = self.class.in_projects(project_ids).find_by!(relative_position: pos_before) issue_to_move = self.class.in_projects(project_ids).find_by!(relative_position: pos_before)
issue_to_move.move_before issue_to_move.move_before
@positionable_neighbours = [issue_to_move] # rubocop:disable Cop/ModuleWithInstanceVariables @positionable_neighbours = [issue_to_move] # rubocop:disable Gitlab/ModuleWithInstanceVariables
pos_before = issue_to_move.relative_position pos_before = issue_to_move.relative_position
end end
...@@ -132,7 +132,7 @@ module RelativePositioning ...@@ -132,7 +132,7 @@ module RelativePositioning
end end
end end
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def save_positionable_neighbours def save_positionable_neighbours
return unless @positionable_neighbours return unless @positionable_neighbours
...@@ -141,5 +141,5 @@ module RelativePositioning ...@@ -141,5 +141,5 @@ module RelativePositioning
status status
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
end end
...@@ -45,13 +45,13 @@ module ResolvableDiscussion ...@@ -45,13 +45,13 @@ module ResolvableDiscussion
def first_note_to_resolve def first_note_to_resolve
return unless resolvable? return unless resolvable?
@first_note_to_resolve ||= notes.find(&:to_be_resolved?) # rubocop:disable Cop/ModuleWithInstanceVariables @first_note_to_resolve ||= notes.find(&:to_be_resolved?) # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
def last_resolved_note def last_resolved_note
return unless resolved? return unless resolved?
@last_resolved_note ||= resolved_notes.sort_by(&:resolved_at).last # rubocop:disable Cop/ModuleWithInstanceVariables @last_resolved_note ||= resolved_notes.sort_by(&:resolved_at).last # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
def resolved_notes def resolved_notes
...@@ -91,7 +91,7 @@ module ResolvableDiscussion ...@@ -91,7 +91,7 @@ module ResolvableDiscussion
yield(notes_relation) yield(notes_relation)
# Set the notes array to the updated notes # Set the notes array to the updated notes
@notes = notes_relation.fresh.to_a # rubocop:disable Cop/ModuleWithInstanceVariables @notes = notes_relation.fresh.to_a # rubocop:disable Gitlab/ModuleWithInstanceVariables
self.class.memoized_values.each do |var| self.class.memoized_values.each do |var|
instance_variable_set(:"@#{var}", nil) instance_variable_set(:"@#{var}", nil)
......
...@@ -88,7 +88,7 @@ module Routable ...@@ -88,7 +88,7 @@ module Routable
def full_name def full_name
if route && route.name.present? if route && route.name.present?
@full_name ||= route.name # rubocop:disable Cop/ModuleWithInstanceVariables @full_name ||= route.name # rubocop:disable Gitlab/ModuleWithInstanceVariables
else else
update_route if persisted? update_route if persisted?
...@@ -112,7 +112,7 @@ module Routable ...@@ -112,7 +112,7 @@ module Routable
def expires_full_path_cache def expires_full_path_cache
RequestStore.delete(full_path_key) if RequestStore.active? RequestStore.delete(full_path_key) if RequestStore.active?
@full_path = nil # rubocop:disable Cop/ModuleWithInstanceVariables @full_path = nil # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
def build_full_path def build_full_path
...@@ -127,7 +127,7 @@ module Routable ...@@ -127,7 +127,7 @@ module Routable
def uncached_full_path def uncached_full_path
if route && route.path.present? if route && route.path.present?
@full_path ||= route.path # rubocop:disable Cop/ModuleWithInstanceVariables @full_path ||= route.path # rubocop:disable Gitlab/ModuleWithInstanceVariables
else else
update_route if persisted? update_route if persisted?
...@@ -166,7 +166,7 @@ module Routable ...@@ -166,7 +166,7 @@ module Routable
route || build_route(source: self) route || build_route(source: self)
route.path = build_full_path route.path = build_full_path
route.name = build_full_name route.name = build_full_name
@full_path = nil # rubocop:disable Cop/ModuleWithInstanceVariables @full_path = nil # rubocop:disable Gitlab/ModuleWithInstanceVariables
@full_name = nil # rubocop:disable Cop/ModuleWithInstanceVariables @full_name = nil # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
end end
...@@ -39,7 +39,7 @@ module Taskable ...@@ -39,7 +39,7 @@ module Taskable
def task_list_items def task_list_items
return [] if description.blank? return [] if description.blank?
@task_list_items ||= Taskable.get_tasks(description) # rubocop:disable Cop/ModuleWithInstanceVariables @task_list_items ||= Taskable.get_tasks(description) # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
def tasks def tasks
......
...@@ -20,7 +20,7 @@ module TimeTrackable ...@@ -20,7 +20,7 @@ module TimeTrackable
has_many :timelogs, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_many :timelogs, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
end end
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def spend_time(options) def spend_time(options)
@time_spent = options[:duration] @time_spent = options[:duration]
@time_spent_user = options[:user] @time_spent_user = options[:user]
...@@ -36,7 +36,7 @@ module TimeTrackable ...@@ -36,7 +36,7 @@ module TimeTrackable
end end
end end
alias_method :spend_time=, :spend_time alias_method :spend_time=, :spend_time
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
def total_time_spent def total_time_spent
timelogs.sum(:time_spent) timelogs.sum(:time_spent)
...@@ -53,10 +53,10 @@ module TimeTrackable ...@@ -53,10 +53,10 @@ module TimeTrackable
private private
def reset_spent_time def reset_spent_time
timelogs.new(time_spent: total_time_spent * -1, user: @time_spent_user) # rubocop:disable Cop/ModuleWithInstanceVariables timelogs.new(time_spent: total_time_spent * -1, user: @time_spent_user) # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def add_or_subtract_spent_time def add_or_subtract_spent_time
timelogs.new( timelogs.new(
time_spent: time_spent, time_spent: time_spent,
...@@ -64,7 +64,7 @@ module TimeTrackable ...@@ -64,7 +64,7 @@ module TimeTrackable
spent_at: @spent_at spent_at: @spent_at
) )
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
def check_negative_time_spent def check_negative_time_spent
return if time_spent.nil? || time_spent == :reset return if time_spent.nil? || time_spent == :reset
......
...@@ -4,12 +4,12 @@ module Issues ...@@ -4,12 +4,12 @@ module Issues
attr_reader :merge_request_to_resolve_discussions_of_iid, :discussion_to_resolve_id attr_reader :merge_request_to_resolve_discussions_of_iid, :discussion_to_resolve_id
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def filter_resolve_discussion_params def filter_resolve_discussion_params
@merge_request_to_resolve_discussions_of_iid ||= params.delete(:merge_request_to_resolve_discussions_of) @merge_request_to_resolve_discussions_of_iid ||= params.delete(:merge_request_to_resolve_discussions_of)
@discussion_to_resolve_id ||= params.delete(:discussion_to_resolve) @discussion_to_resolve_id ||= params.delete(:discussion_to_resolve)
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
def merge_request_to_resolve_discussions_of def merge_request_to_resolve_discussions_of
strong_memoize(:merge_request_to_resolve_discussions_of) do strong_memoize(:merge_request_to_resolve_discussions_of) do
...@@ -22,7 +22,7 @@ module Issues ...@@ -22,7 +22,7 @@ module Issues
def discussions_to_resolve def discussions_to_resolve
return [] unless merge_request_to_resolve_discussions_of return [] unless merge_request_to_resolve_discussions_of
@discussions_to_resolve ||= # rubocop:disable Cop/ModuleWithInstanceVariables @discussions_to_resolve ||= # rubocop:disable Gitlab/ModuleWithInstanceVariables
if discussion_to_resolve_id if discussion_to_resolve_id
discussion_or_nil = merge_request_to_resolve_discussions_of discussion_or_nil = merge_request_to_resolve_discussions_of
.find_discussion(discussion_to_resolve_id) .find_discussion(discussion_to_resolve_id)
......
...@@ -7,19 +7,19 @@ ...@@ -7,19 +7,19 @@
# - params with :request # - params with :request
# #
module SpamCheckService module SpamCheckService
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def filter_spam_check_params def filter_spam_check_params
@request = params.delete(:request) @request = params.delete(:request)
@api = params.delete(:api) @api = params.delete(:api)
@recaptcha_verified = params.delete(:recaptcha_verified) @recaptcha_verified = params.delete(:recaptcha_verified)
@spam_log_id = params.delete(:spam_log_id) @spam_log_id = params.delete(:spam_log_id)
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
# In order to be proceed to the spam check process, @spammable has to be # In order to be proceed to the spam check process, @spammable has to be
# a dirty instance, which means it should be already assigned with the new # a dirty instance, which means it should be already assigned with the new
# attribute values. # attribute values.
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def spam_check(spammable, user) def spam_check(spammable, user)
spam_service = SpamService.new(spammable, @request) spam_service = SpamService.new(spammable, @request)
...@@ -27,5 +27,5 @@ module SpamCheckService ...@@ -27,5 +27,5 @@ module SpamCheckService
user.spam_logs.find_by(id: @spam_log_id)&.update!(recaptcha_verified: true) user.spam_logs.find_by(id: @spam_log_id)&.update!(recaptcha_verified: true)
end end
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
end end
...@@ -9,15 +9,15 @@ module NewIssuable ...@@ -9,15 +9,15 @@ module NewIssuable
end end
def set_user(user_id) def set_user(user_id)
@user = User.find_by(id: user_id) # rubocop:disable Cop/ModuleWithInstanceVariables @user = User.find_by(id: user_id) # rubocop:disable Gitlab/ModuleWithInstanceVariables
log_error(User, user_id) unless @user # rubocop:disable Cop/ModuleWithInstanceVariables log_error(User, user_id) unless @user # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
def set_issuable(issuable_id) def set_issuable(issuable_id)
@issuable = issuable_class.find_by(id: issuable_id) # rubocop:disable Cop/ModuleWithInstanceVariables @issuable = issuable_class.find_by(id: issuable_id) # rubocop:disable Gitlab/ModuleWithInstanceVariables
log_error(issuable_class, issuable_id) unless @issuable # rubocop:disable Cop/ModuleWithInstanceVariables log_error(issuable_class, issuable_id) unless @issuable # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
def log_error(record_class, record_id) def log_error(record_class, record_id)
......
...@@ -6,7 +6,7 @@ module LocalCacheRegistryCleanupWithEnsure ...@@ -6,7 +6,7 @@ module LocalCacheRegistryCleanupWithEnsure
def call(env) def call(env)
LocalCacheRegistry.set_cache_for(local_cache_key, LocalStore.new) LocalCacheRegistry.set_cache_for(local_cache_key, LocalStore.new)
response = @app.call(env) # rubocop:disable Cop/ModuleWithInstanceVariables response = @app.call(env) # rubocop:disable Gitlab/ModuleWithInstanceVariables
response[2] = ::Rack::BodyProxy.new(response[2]) do response[2] = ::Rack::BodyProxy.new(response[2]) do
LocalCacheRegistry.set_cache_for(local_cache_key, nil) LocalCacheRegistry.set_cache_for(local_cache_key, nil)
end end
......
...@@ -19,10 +19,10 @@ module RspecProfilingExt ...@@ -19,10 +19,10 @@ module RspecProfilingExt
def example_finished(*args) def example_finished(*args)
super super
rescue => err rescue => err
return if @already_logged_example_finished_error # rubocop:disable Cop/ModuleWithInstanceVariables return if @already_logged_example_finished_error # rubocop:disable Gitlab/ModuleWithInstanceVariables
$stderr.puts "rspec_profiling couldn't collect an example: #{err}. Further warnings suppressed." $stderr.puts "rspec_profiling couldn't collect an example: #{err}. Further warnings suppressed."
@already_logged_example_finished_error = true # rubocop:disable Cop/ModuleWithInstanceVariables @already_logged_example_finished_error = true # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
alias_method :example_passed, :example_finished alias_method :example_passed, :example_finished
......
...@@ -185,7 +185,7 @@ Put the disabling comment right after your code in the same line: ...@@ -185,7 +185,7 @@ Put the disabling comment right after your code in the same line:
``` ruby ``` ruby
module M module M
def violating_method def violating_method
@f + @g # rubocop:disable Cop/ModuleWithInstanceVariables @f + @g # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
end end
``` ```
...@@ -194,13 +194,13 @@ If there are multiple lines, you could also enable and disable for a section: ...@@ -194,13 +194,13 @@ If there are multiple lines, you could also enable and disable for a section:
``` ruby ``` ruby
module M module M
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def violating_method def violating_method
@f = 0 @f = 0
@g = 1 @g = 1
@h = 2 @h = 2
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
end end
``` ```
......
...@@ -42,11 +42,11 @@ module StdoutReporterWithScenarioLocation ...@@ -42,11 +42,11 @@ module StdoutReporterWithScenarioLocation
# Override the standard reporter to show filename and line number next to each # Override the standard reporter to show filename and line number next to each
# scenario for easy, focused re-runs # scenario for easy, focused re-runs
def before_scenario_run(scenario, step_definitions = nil) def before_scenario_run(scenario, step_definitions = nil)
@max_step_name_length = scenario.steps.map(&:name).map(&:length).max if scenario.steps.any? # rubocop:disable Cop/ModuleWithInstanceVariables @max_step_name_length = scenario.steps.map(&:name).map(&:length).max if scenario.steps.any? # rubocop:disable Gitlab/ModuleWithInstanceVariables
name = scenario.name name = scenario.name
# This number has no significance, it's just to line things up # This number has no significance, it's just to line things up
max_length = @max_step_name_length + 19 # rubocop:disable Cop/ModuleWithInstanceVariables max_length = @max_step_name_length + 19 # rubocop:disable Gitlab/ModuleWithInstanceVariables
out.puts "\n #{'Scenario:'.green} #{name.light_green.ljust(max_length)}" \ out.puts "\n #{'Scenario:'.green} #{name.light_green.ljust(max_length)}" \
" # #{scenario.feature.filename}:#{scenario.line}" " # #{scenario.feature.filename}:#{scenario.line}"
end end
......
...@@ -32,7 +32,7 @@ module API ...@@ -32,7 +32,7 @@ module API
end end
end end
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
# We can't rewrite this with StrongMemoize because `sudo!` would # We can't rewrite this with StrongMemoize because `sudo!` would
# actually write to `@current_user`, and `sudo?` would immediately # actually write to `@current_user`, and `sudo?` would immediately
# call `current_user` again which reads from `@current_user`. # call `current_user` again which reads from `@current_user`.
...@@ -50,7 +50,7 @@ module API ...@@ -50,7 +50,7 @@ module API
@current_user @current_user
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
def sudo? def sudo?
initial_current_user != current_user initial_current_user != current_user
...@@ -399,7 +399,7 @@ module API ...@@ -399,7 +399,7 @@ module API
private private
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def initial_current_user def initial_current_user
return @initial_current_user if defined?(@initial_current_user) return @initial_current_user if defined?(@initial_current_user)
...@@ -409,7 +409,7 @@ module API ...@@ -409,7 +409,7 @@ module API
unauthorized! unauthorized!
end end
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
def sudo! def sudo!
return unless sudo_identifier return unless sudo_identifier
...@@ -429,7 +429,7 @@ module API ...@@ -429,7 +429,7 @@ module API
sudoed_user = find_user(sudo_identifier) sudoed_user = find_user(sudo_identifier)
not_found!("User with ID or username '#{sudo_identifier}'") unless sudoed_user not_found!("User with ID or username '#{sudo_identifier}'") unless sudoed_user
@current_user = sudoed_user # rubocop:disable Cop/ModuleWithInstanceVariables @current_user = sudoed_user # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
def sudo_identifier def sudo_identifier
......
...@@ -9,13 +9,13 @@ module API ...@@ -9,13 +9,13 @@ module API
attr_reader :redirected_path attr_reader :redirected_path
def wiki? def wiki?
set_project unless defined?(@wiki) # rubocop:disable Cop/ModuleWithInstanceVariables set_project unless defined?(@wiki) # rubocop:disable Gitlab/ModuleWithInstanceVariables
@wiki # rubocop:disable Cop/ModuleWithInstanceVariables @wiki # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
def project def project
set_project unless defined?(@project) # rubocop:disable Cop/ModuleWithInstanceVariables set_project unless defined?(@project) # rubocop:disable Gitlab/ModuleWithInstanceVariables
@project # rubocop:disable Cop/ModuleWithInstanceVariables @project # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
def ssh_authentication_abilities def ssh_authentication_abilities
...@@ -67,7 +67,7 @@ module API ...@@ -67,7 +67,7 @@ module API
private private
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def set_project def set_project
if params[:gl_repository] if params[:gl_repository]
@project, @wiki = Gitlab::GlRepository.parse(params[:gl_repository]) @project, @wiki = Gitlab::GlRepository.parse(params[:gl_repository])
...@@ -76,7 +76,7 @@ module API ...@@ -76,7 +76,7 @@ module API
@project, @wiki, @redirected_path = Gitlab::RepoPath.parse(params[:project]) @project, @wiki, @redirected_path = Gitlab::RepoPath.parse(params[:project])
end end
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
# Project id to pass between components that don't share/don't have # Project id to pass between components that don't share/don't have
# access to the same filesystem mounts # access to the same filesystem mounts
......
...@@ -40,7 +40,7 @@ module ExtractsPath ...@@ -40,7 +40,7 @@ module ExtractsPath
def extract_ref(id) def extract_ref(id)
pair = ['', ''] pair = ['', '']
return pair unless @project # rubocop:disable Cop/ModuleWithInstanceVariables return pair unless @project # rubocop:disable Gitlab/ModuleWithInstanceVariables
if id =~ /^(\h{40})(.+)/ if id =~ /^(\h{40})(.+)/
# If the ref appears to be a SHA, we're done, just split the string # If the ref appears to be a SHA, we're done, just split the string
...@@ -104,7 +104,7 @@ module ExtractsPath ...@@ -104,7 +104,7 @@ module ExtractsPath
# #
# Automatically renders `not_found!` if a valid tree path could not be # Automatically renders `not_found!` if a valid tree path could not be
# resolved (e.g., when a user inserts an invalid path or ref). # resolved (e.g., when a user inserts an invalid path or ref).
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def assign_ref_vars def assign_ref_vars
# assign allowed options # assign allowed options
allowed_options = ["filter_ref"] allowed_options = ["filter_ref"]
...@@ -132,10 +132,10 @@ module ExtractsPath ...@@ -132,10 +132,10 @@ module ExtractsPath
rescue RuntimeError, NoMethodError, InvalidPathError rescue RuntimeError, NoMethodError, InvalidPathError
render_404 render_404
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
def tree def tree
@tree ||= @repo.tree(@commit.id, @path) # rubocop:disable Cop/ModuleWithInstanceVariables @tree ||= @repo.tree(@commit.id, @path) # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
private private
...@@ -148,8 +148,8 @@ module ExtractsPath ...@@ -148,8 +148,8 @@ module ExtractsPath
end end
def ref_names def ref_names
return [] unless @project # rubocop:disable Cop/ModuleWithInstanceVariables return [] unless @project # rubocop:disable Gitlab/ModuleWithInstanceVariables
@ref_names ||= @project.repository.ref_names # rubocop:disable Cop/ModuleWithInstanceVariables @ref_names ||= @project.repository.ref_names # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
end end
...@@ -6,7 +6,7 @@ module Gitlab ...@@ -6,7 +6,7 @@ module Gitlab
query query
.group("DATE(#{::Ci::Pipeline.table_name}.created_at)") .group("DATE(#{::Ci::Pipeline.table_name}.created_at)")
.count(:created_at) .count(:created_at)
.transform_keys { |date| date.strftime(@format) } # rubocop:disable Cop/ModuleWithInstanceVariables .transform_keys { |date| date.strftime(@format) } # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
def interval_step def interval_step
......
...@@ -13,7 +13,7 @@ module Gitlab ...@@ -13,7 +13,7 @@ module Gitlab
end end
def errors def errors
@validator.messages + descendants.flat_map(&:errors) # rubocop:disable Cop/ModuleWithInstanceVariables @validator.messages + descendants.flat_map(&:errors) # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
class_methods do class_methods do
......
...@@ -53,7 +53,7 @@ module Gitlab ...@@ -53,7 +53,7 @@ module Gitlab
end end
def in_memory_application_settings def in_memory_application_settings
@in_memory_application_settings ||= ::ApplicationSetting.new(::ApplicationSetting.defaults) # rubocop:disable Cop/ModuleWithInstanceVariables @in_memory_application_settings ||= ::ApplicationSetting.new(::ApplicationSetting.defaults) # rubocop:disable Gitlab/ModuleWithInstanceVariables
rescue ActiveRecord::StatementInvalid, ActiveRecord::UnknownAttributeError rescue ActiveRecord::StatementInvalid, ActiveRecord::UnknownAttributeError
# In case migrations the application_settings table is not created yet, # In case migrations the application_settings table is not created yet,
# we fallback to a simple OpenStruct # we fallback to a simple OpenStruct
......
...@@ -14,9 +14,9 @@ module Gitlab ...@@ -14,9 +14,9 @@ module Gitlab
def stage_query def stage_query
query = mr_closing_issues_table.join(issue_table).on(issue_table[:id].eq(mr_closing_issues_table[:issue_id])) query = mr_closing_issues_table.join(issue_table).on(issue_table[:id].eq(mr_closing_issues_table[:issue_id]))
.join(issue_metrics_table).on(issue_table[:id].eq(issue_metrics_table[:issue_id])) .join(issue_metrics_table).on(issue_table[:id].eq(issue_metrics_table[:issue_id]))
.where(issue_table[:project_id].eq(@project.id)) # rubocop:disable Cop/ModuleWithInstanceVariables .where(issue_table[:project_id].eq(@project.id)) # rubocop:disable Gitlab/ModuleWithInstanceVariables
.where(issue_table[:deleted_at].eq(nil)) .where(issue_table[:deleted_at].eq(nil))
.where(issue_table[:created_at].gteq(@options[:from])) # rubocop:disable Cop/ModuleWithInstanceVariables .where(issue_table[:created_at].gteq(@options[:from])) # rubocop:disable Gitlab/ModuleWithInstanceVariables
# Load merge_requests # Load merge_requests
query = query.join(mr_table, Arel::Nodes::OuterJoin) query = query.join(mr_table, Arel::Nodes::OuterJoin)
......
...@@ -4,7 +4,7 @@ module Gitlab ...@@ -4,7 +4,7 @@ module Gitlab
def stage_query def stage_query
super super
.where(mr_metrics_table[:first_deployed_to_production_at] .where(mr_metrics_table[:first_deployed_to_production_at]
.gteq(@options[:from])) # rubocop:disable Cop/ModuleWithInstanceVariables .gteq(@options[:from])) # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
end end
end end
......
...@@ -6,7 +6,7 @@ module Gitlab ...@@ -6,7 +6,7 @@ module Gitlab
module Routable module Routable
def full_path def full_path
if route && route.path.present? if route && route.path.present?
@full_path ||= route.path # rubocop:disable Cop/ModuleWithInstanceVariables @full_path ||= route.path # rubocop:disable Gitlab/ModuleWithInstanceVariables
else else
update_route if persisted? update_route if persisted?
...@@ -30,7 +30,7 @@ module Gitlab ...@@ -30,7 +30,7 @@ module Gitlab
def prepare_route def prepare_route
route || build_route(source: self) route || build_route(source: self)
route.path = build_full_path route.path = build_full_path
@full_path = nil # rubocop:disable Cop/ModuleWithInstanceVariables @full_path = nil # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
end end
......
...@@ -32,7 +32,7 @@ module Gitlab ...@@ -32,7 +32,7 @@ module Gitlab
def execute(cmd) def execute(cmd)
output, status = Gitlab::Popen.popen(cmd) output, status = Gitlab::Popen.popen(cmd)
@shared.error(Gitlab::ImportExport::Error.new(output.to_s)) unless status.zero? # rubocop:disable Cop/ModuleWithInstanceVariables @shared.error(Gitlab::ImportExport::Error.new(output.to_s)) unless status.zero? # rubocop:disable Gitlab/ModuleWithInstanceVariables
status.zero? status.zero?
end end
......
...@@ -154,7 +154,7 @@ module Gitlab ...@@ -154,7 +154,7 @@ module Gitlab
# When enabled this should be set before being used as the usual pattern # When enabled this should be set before being used as the usual pattern
# "@foo ||= bar" is _not_ thread-safe. # "@foo ||= bar" is _not_ thread-safe.
# rubocop:disable Cop/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def pool def pool
if influx_metrics_enabled? if influx_metrics_enabled?
if @pool.nil? if @pool.nil?
...@@ -171,7 +171,7 @@ module Gitlab ...@@ -171,7 +171,7 @@ module Gitlab
@pool @pool
end end
end end
# rubocop:enable Cop/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
end end
end end
end end
module RuboCop
module Cop
module Gitlab
class ModuleWithInstanceVariables < RuboCop::Cop::Cop
MSG = <<~EOL.freeze
Do not use instance variables in a module. Please read this
for the rationale behind it:
https://docs.gitlab.com/ee/development/module_with_instance_variables.html
EOL
def on_module(node)
check_method_definition(node)
# Not sure why some module would have an extra begin wrapping around
node.each_child_node(:begin) do |begin_node|
check_method_definition(begin_node)
end
end
private
def check_method_definition(node)
node.each_child_node(:def) do |definition|
# We allow this pattern:
#
# def f
# @f ||= true
# end
if only_ivar_or_assignment?(definition)
# We don't allow if any other ivar is used
definition.each_descendant(:ivar) do |offense|
add_offense(offense, :expression)
end
# We allow initialize method and single ivar
elsif !initialize_method?(definition) && !single_ivar?(definition)
definition.each_descendant(:ivar, :ivasgn) do |offense|
add_offense(offense, :expression)
end
end
end
end
def only_ivar_or_assignment?(definition)
node = definition.child_nodes.last
definition.child_nodes.size == 2 &&
node.or_asgn_type? && node.child_nodes.first.ivasgn_type?
end
def single_ivar?(definition)
node = definition.child_nodes.last
definition.child_nodes.size == 2 && node.ivar_type?
end
def initialize_method?(definition)
definition.children.first == :initialize
end
end
end
end
end
module RuboCop
module Cop
class ModuleWithInstanceVariables < RuboCop::Cop::Cop
MSG = <<~EOL.freeze
Do not use instance variables in a module. Please read this
for the rationale behind it:
https://docs.gitlab.com/ee/development/module_with_instance_variables.html
EOL
def on_module(node)
return if
rails_helper?(node) || rails_mailer?(node) || spec_helper?(node)
check_method_definition(node)
# Not sure why some module would have an extra begin wrapping around
node.each_child_node(:begin) do |begin_node|
check_method_definition(begin_node)
end
end
private
# We ignore Rails helpers right now because it's hard to workaround it
def rails_helper?(node)
node.source_range.source_buffer.name =~
%r{app/helpers/\w+_helper.rb\z}
end
# We ignore Rails mailers right now because it's hard to workaround it
def rails_mailer?(node)
node.source_range.source_buffer.name =~
%r{app/mailers/emails/}
end
# We ignore spec helpers because it usually doesn't matter
def spec_helper?(node)
node.source_range.source_buffer.name =~
%r{spec/support/|features/steps/}
end
def check_method_definition(node)
node.each_child_node(:def) do |definition|
# We allow this pattern:
#
# def f
# @f ||= true
# end
if only_ivar_or_assignment?(definition)
# We don't allow if any other ivar is used
definition.each_descendant(:ivar) do |offense|
add_offense(offense, :expression)
end
# We allow initialize method and single ivar
elsif !initialize_method?(definition) && !single_ivar?(definition)
definition.each_descendant(:ivar, :ivasgn) do |offense|
add_offense(offense, :expression)
end
end
end
end
def only_ivar_or_assignment?(definition)
node = definition.child_nodes.last
definition.child_nodes.size == 2 &&
node.or_asgn_type? && node.child_nodes.first.ivasgn_type?
end
def single_ivar?(definition)
node = definition.child_nodes.last
definition.child_nodes.size == 2 && node.ivar_type?
end
def initialize_method?(definition)
definition.children.first == :initialize
end
end
end
end
...@@ -5,8 +5,8 @@ require_relative 'cop/gem_fetcher' ...@@ -5,8 +5,8 @@ require_relative 'cop/gem_fetcher'
require_relative 'cop/in_batches' require_relative 'cop/in_batches'
require_relative 'cop/polymorphic_associations' require_relative 'cop/polymorphic_associations'
require_relative 'cop/project_path_helper' require_relative 'cop/project_path_helper'
require_relative 'cop/module_with_instance_variables'
require_relative 'cop/redirect_with_status' require_relative 'cop/redirect_with_status'
require_relative 'cop/gitlab/module_with_instance_variables'
require_relative 'cop/migration/add_column' require_relative 'cop/migration/add_column'
require_relative 'cop/migration/add_column_with_default_to_large_table' require_relative 'cop/migration/add_column_with_default_to_large_table'
require_relative 'cop/migration/add_concurrent_foreign_key' require_relative 'cop/migration/add_concurrent_foreign_key'
......
require 'spec_helper' require 'spec_helper'
require 'rubocop' require 'rubocop'
require 'rubocop/rspec/support' require 'rubocop/rspec/support'
require_relative '../../../rubocop/cop/module_with_instance_variables' require_relative '../../../../rubocop/cop/gitlab/module_with_instance_variables'
describe RuboCop::Cop::ModuleWithInstanceVariables do describe RuboCop::Cop::Gitlab::ModuleWithInstanceVariables do
include CopHelper include CopHelper
subject(:cop) { described_class.new } subject(:cop) { described_class.new }
...@@ -83,42 +83,6 @@ describe RuboCop::Cop::ModuleWithInstanceVariables do ...@@ -83,42 +83,6 @@ describe RuboCop::Cop::ModuleWithInstanceVariables do
end end
end end
context 'with regular ivar assignment' do
let(:source) do
<<~RUBY
module M
def f
@f = true
end
end
RUBY
end
context 'when source is offending but it is a rails helper' do
before do
allow(cop).to receive(:rails_helper?).and_return(true)
end
it_behaves_like 'not registering offense'
end
context 'when source is offending but it is a rails mailer' do
before do
allow(cop).to receive(:rails_mailer?).and_return(true)
end
it_behaves_like 'not registering offense'
end
context 'when source is offending but it is a spec helper' do
before do
allow(cop).to receive(:spec_helper?).and_return(true)
end
it_behaves_like 'not registering offense'
end
end
context 'when source is using simple or ivar assignment' do context 'when source is using simple or ivar assignment' do
it_behaves_like 'not registering offense' do it_behaves_like 'not registering offense' do
let(:source) do let(:source) 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