Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
6a4ee9aa
Commit
6a4ee9aa
authored
Sep 19, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow simple ivar ||= form. Update accordingly
parent
9ae92b8c
Changes
53
Hide whitespace changes
Inline
Side-by-side
Showing
53 changed files
with
220 additions
and
109 deletions
+220
-109
app/controllers/concerns/boards_responses.rb
app/controllers/concerns/boards_responses.rb
+2
-1
app/controllers/concerns/creates_commit.rb
app/controllers/concerns/creates_commit.rb
+5
-1
app/controllers/concerns/cycle_analytics_params.rb
app/controllers/concerns/cycle_analytics_params.rb
+0
-1
app/controllers/concerns/issuable_actions.rb
app/controllers/concerns/issuable_actions.rb
+4
-1
app/controllers/concerns/issuable_collections.rb
app/controllers/concerns/issuable_collections.rb
+2
-1
app/controllers/concerns/issues_action.rb
app/controllers/concerns/issues_action.rb
+1
-1
app/controllers/concerns/lfs_request.rb
app/controllers/concerns/lfs_request.rb
+0
-2
app/controllers/concerns/membership_actions.rb
app/controllers/concerns/membership_actions.rb
+0
-1
app/controllers/concerns/merge_requests_action.rb
app/controllers/concerns/merge_requests_action.rb
+1
-1
app/controllers/concerns/oauth_applications.rb
app/controllers/concerns/oauth_applications.rb
+1
-2
app/controllers/concerns/requires_whitelisted_monitoring_client.rb
...ollers/concerns/requires_whitelisted_monitoring_client.rb
+0
-1
app/models/concerns/ignorable_column.rb
app/models/concerns/ignorable_column.rb
+0
-1
app/models/concerns/mentionable.rb
app/models/concerns/mentionable.rb
+1
-1
app/models/concerns/noteable.rb
app/models/concerns/noteable.rb
+0
-3
app/models/concerns/participable.rb
app/models/concerns/participable.rb
+7
-6
app/models/concerns/protected_ref.rb
app/models/concerns/protected_ref.rb
+0
-1
app/models/concerns/relative_positioning.rb
app/models/concerns/relative_positioning.rb
+4
-1
app/models/concerns/resolvable_discussion.rb
app/models/concerns/resolvable_discussion.rb
+5
-1
app/models/concerns/routable.rb
app/models/concerns/routable.rb
+4
-1
app/models/concerns/storage/legacy_namespace.rb
app/models/concerns/storage/legacy_namespace.rb
+0
-1
app/models/concerns/strip_attribute.rb
app/models/concerns/strip_attribute.rb
+0
-1
app/models/concerns/taskable.rb
app/models/concerns/taskable.rb
+1
-1
app/models/concerns/time_trackable.rb
app/models/concerns/time_trackable.rb
+3
-1
app/services/spam_check_service.rb
app/services/spam_check_service.rb
+2
-1
app/services/system_note_service.rb
app/services/system_note_service.rb
+0
-1
config/initializers/rugged_use_gitlab_git_attributes.rb
config/initializers/rugged_use_gitlab_git_attributes.rb
+1
-1
doc/development/module_with_instance_variables.md
doc/development/module_with_instance_variables.md
+51
-20
lib/after_commit_queue.rb
lib/after_commit_queue.rb
+0
-1
lib/api/api_guard.rb
lib/api/api_guard.rb
+3
-5
lib/api/helpers.rb
lib/api/helpers.rb
+3
-1
lib/api/helpers/internal_helpers.rb
lib/api/helpers/internal_helpers.rb
+4
-5
lib/api/helpers/runner.rb
lib/api/helpers/runner.rb
+0
-1
lib/extracts_path.rb
lib/extracts_path.rb
+4
-1
lib/gitlab/ci/charts.rb
lib/gitlab/ci/charts.rb
+0
-2
lib/gitlab/ci/config/entry/configurable.rb
lib/gitlab/ci/config/entry/configurable.rb
+1
-1
lib/gitlab/ci/config/entry/validatable.rb
lib/gitlab/ci/config/entry/validatable.rb
+1
-1
lib/gitlab/ci/model.rb
lib/gitlab/ci/model.rb
+0
-1
lib/gitlab/cycle_analytics/base_query.rb
lib/gitlab/cycle_analytics/base_query.rb
+1
-1
lib/gitlab/cycle_analytics/production_helper.rb
lib/gitlab/cycle_analytics/production_helper.rb
+1
-1
lib/gitlab/email/handler/reply_processing.rb
lib/gitlab/email/handler/reply_processing.rb
+0
-1
lib/gitlab/emoji.rb
lib/gitlab/emoji.rb
+8
-3
lib/gitlab/identifier.rb
lib/gitlab/identifier.rb
+0
-1
lib/gitlab/metrics/influx_db.rb
lib/gitlab/metrics/influx_db.rb
+1
-1
lib/gitlab/metrics/prometheus.rb
lib/gitlab/metrics/prometheus.rb
+1
-1
lib/gitlab/prometheus/additional_metrics_parser.rb
lib/gitlab/prometheus/additional_metrics_parser.rb
+0
-1
lib/gitlab/prometheus/queries/query_additional_metrics.rb
lib/gitlab/prometheus/queries/query_additional_metrics.rb
+0
-1
lib/gitlab/regex.rb
lib/gitlab/regex.rb
+0
-1
lib/gitlab/slash_commands/presenters/issue_base.rb
lib/gitlab/slash_commands/presenters/issue_base.rb
+3
-1
lib/gitlab/themes.rb
lib/gitlab/themes.rb
+0
-1
lib/tasks/gitlab/task_helpers.rb
lib/tasks/gitlab/task_helpers.rb
+2
-1
qa/qa/runtime/namespace.rb
qa/qa/runtime/namespace.rb
+0
-1
rubocop/cop/module_with_instance_variables.rb
rubocop/cop/module_with_instance_variables.rb
+20
-2
spec/rubocop/cop/module_with_instance_variables_spec.rb
spec/rubocop/cop/module_with_instance_variables_spec.rb
+72
-17
No files found.
app/controllers/concerns/boards_responses.rb
View file @
6a4ee9aa
# rubocop:disable Cop/ModuleWithInstanceVariables
module
BoardsResponses
def
authorize_read_list
authorize_action_for!
(
board
.
parent
,
:read_list
)
...
...
@@ -24,10 +23,12 @@ module BoardsResponses
return
render_403
unless
can?
(
current_user
,
ability
,
resource
)
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
respond_with_boards
respond_with
(
@boards
)
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
respond_with_board
respond_with
(
@board
)
end
...
...
app/controllers/concerns/creates_commit.rb
View file @
6a4ee9aa
# rubocop:disable Cop/ModuleWithInstanceVariables
module
CreatesCommit
extend
ActiveSupport
::
Concern
# rubocop:disable Cop/ModuleWithInstanceVariables
def
create_commit
(
service
,
success_path
:,
failure_path
:,
failure_view:
nil
,
success_notice:
nil
)
if
can?
(
current_user
,
:push_code
,
@project
)
@project_to_commit_into
=
@project
...
...
@@ -78,6 +78,7 @@ module CreatesCommit
end
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
new_merge_request_path
project_new_merge_request_path
(
@project_to_commit_into
,
...
...
@@ -94,6 +95,7 @@ module CreatesCommit
project_merge_request_path
(
@project
,
@merge_request
)
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
merge_request_exists?
return
@merge_request
if
defined?
(
@merge_request
)
...
...
@@ -101,10 +103,12 @@ module CreatesCommit
.
find_by
(
source_project_id:
@project_to_commit_into
,
source_branch:
@branch_name
,
target_branch:
@start_branch
)
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
different_project?
@project_to_commit_into
!=
@project
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
create_merge_request?
# Even if the field is set, if we're checking the same branch
# as the target branch in the same project,
...
...
app/controllers/concerns/cycle_analytics_params.rb
View file @
6a4ee9aa
module
CycleAnalyticsParams
extend
ActiveSupport
::
Concern
# rubocop:disable Cop/ModuleWithInstanceVariables
def
options
(
params
)
@options
||=
{
from:
start_date
(
params
),
current_user:
current_user
}
end
...
...
app/controllers/concerns/issuable_actions.rb
View file @
6a4ee9aa
# rubocop:disable Cop/ModuleWithInstanceVariables
module
IssuableActions
extend
ActiveSupport
::
Concern
...
...
@@ -8,6 +7,7 @@ module IssuableActions
before_action
:authorize_admin_issuable!
,
only: :bulk_update
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
destroy
issuable
.
destroy
destroy_method
=
"destroy_
#{
issuable
.
class
.
name
.
underscore
}
"
.
to_sym
...
...
@@ -36,6 +36,7 @@ module IssuableActions
private
# rubocop:disable Cop/ModuleWithInstanceVariables
def
render_conflict_response
respond_to
do
|
format
|
format
.
html
do
...
...
@@ -53,6 +54,7 @@ module IssuableActions
end
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
labels
@labels
||=
LabelsFinder
.
new
(
current_user
,
project_id:
@project
.
id
).
execute
end
...
...
@@ -63,6 +65,7 @@ module IssuableActions
end
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
authorize_admin_issuable!
unless
can?
(
current_user
,
:"admin_
#{
resource_name
}
"
,
@project
)
return
access_denied!
...
...
app/controllers/concerns/issuable_collections.rb
View file @
6a4ee9aa
# rubocop:disable Cop/ModuleWithInstanceVariables
module
IssuableCollections
extend
ActiveSupport
::
Concern
include
SortingHelper
...
...
@@ -11,6 +10,7 @@ module IssuableCollections
private
# rubocop:disable Cop/ModuleWithInstanceVariables
def
set_issues_index
@collection_type
=
"Issue"
@issues
=
issues_collection
...
...
@@ -85,6 +85,7 @@ module IssuableCollections
finder_class
.
new
(
current_user
,
filter_params
)
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
filter_params
set_sort_order_from_cookie
set_default_state
...
...
app/controllers/concerns/issues_action.rb
View file @
6a4ee9aa
# rubocop:disable Cop/ModuleWithInstanceVariables
module
IssuesAction
extend
ActiveSupport
::
Concern
include
IssuableCollections
# rubocop:disable Cop/ModuleWithInstanceVariables
def
issues
@label
=
issues_finder
.
labels
.
first
...
...
app/controllers/concerns/lfs_request.rb
View file @
6a4ee9aa
...
...
@@ -90,7 +90,6 @@ module LfsRequest
has_authentication_ability?
(
:build_download_code
)
&&
can?
(
user
,
:build_download_code
,
project
)
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
storage_project
@storage_project
||=
begin
result
=
project
...
...
@@ -104,7 +103,6 @@ module LfsRequest
end
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
objects
@objects
||=
(
params
[
:objects
]
||
[]).
to_a
end
...
...
app/controllers/concerns/membership_actions.rb
View file @
6a4ee9aa
...
...
@@ -76,7 +76,6 @@ module MembershipActions
end
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
source_type
@source_type
||=
membershipable
.
class
.
to_s
.
humanize
(
capitalize:
false
)
end
...
...
app/controllers/concerns/merge_requests_action.rb
View file @
6a4ee9aa
# rubocop:disable Cop/ModuleWithInstanceVariables
module
MergeRequestsAction
extend
ActiveSupport
::
Concern
include
IssuableCollections
# rubocop:disable Cop/ModuleWithInstanceVariables
def
merge_requests
@label
=
merge_requests_finder
.
labels
.
first
...
...
app/controllers/concerns/oauth_applications.rb
View file @
6a4ee9aa
...
...
@@ -13,8 +13,7 @@ module OauthApplications
end
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
load_scopes
@scopes
=
Doorkeeper
.
configuration
.
scopes
@scopes
||
=
Doorkeeper
.
configuration
.
scopes
end
end
app/controllers/concerns/requires_whitelisted_monitoring_client.rb
View file @
6a4ee9aa
...
...
@@ -17,7 +17,6 @@ module RequiresWhitelistedMonitoringClient
ip_whitelist
.
any?
{
|
e
|
e
.
include?
(
Gitlab
::
RequestContext
.
client_ip
)
}
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
ip_whitelist
@ip_whitelist
||=
Settings
.
monitoring
.
ip_whitelist
.
map
(
&
IPAddr
.
method
(
:new
))
end
...
...
app/models/concerns/ignorable_column.rb
View file @
6a4ee9aa
...
...
@@ -17,7 +17,6 @@ module IgnorableColumn
super
.
reject
{
|
column
|
ignored_columns
.
include?
(
column
.
name
)
}
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
ignored_columns
@ignored_columns
||=
Set
.
new
end
...
...
app/models/concerns/mentionable.rb
View file @
6a4ee9aa
...
...
@@ -5,7 +5,6 @@
#
# Used by Issue, Note, MergeRequest, and Commit.
#
# # rubocop:disable Cop/ModuleWithInstanceVariables
module
Mentionable
extend
ActiveSupport
::
Concern
...
...
@@ -44,6 +43,7 @@ module Mentionable
self
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
all_references
(
current_user
=
nil
,
extractor:
nil
)
@extractors
||=
{}
...
...
app/models/concerns/noteable.rb
View file @
6a4ee9aa
...
...
@@ -12,7 +12,6 @@ module Noteable
#
# noteable.class # => MergeRequest
# noteable.human_class_name # => "merge request"
# rubocop:disable Cop/ModuleWithInstanceVariables
def
human_class_name
@human_class_name
||=
base_class_name
.
titleize
.
downcase
end
...
...
@@ -35,7 +34,6 @@ module Noteable
delegate
:find_discussion
,
to: :discussion_notes
# rubocop:disable Cop/ModuleWithInstanceVariables
def
discussions
@discussions
||=
discussion_notes
.
inc_relations_for_view
...
...
@@ -70,7 +68,6 @@ module Noteable
discussions_resolvable?
&&
!
discussions_resolved?
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
discussions_to_be_resolved
@discussions_to_be_resolved
||=
resolvable_discussions
.
select
(
&
:to_be_resolved?
)
end
...
...
app/models/concerns/participable.rb
View file @
6a4ee9aa
...
...
@@ -55,17 +55,18 @@ module Participable
# This method processes attributes of objects in breadth-first order.
#
# Returns an Array of User instances.
# rubocop:disable Cop/ModuleWithInstanceVariables
def
participants
(
current_user
=
nil
)
@participants
||=
Hash
.
new
do
|
hash
,
user
|
hash
[
user
]
=
raw_participants
(
user
)
end
@participants
[
current_user
]
all_participants
[
current_user
]
end
private
def
all_participants
@all_participants
||=
Hash
.
new
do
|
hash
,
user
|
hash
[
user
]
=
raw_participants
(
user
)
end
end
def
raw_participants
(
current_user
=
nil
)
current_user
||=
author
ext
=
Gitlab
::
ReferenceExtractor
.
new
(
project
,
current_user
)
...
...
app/models/concerns/protected_ref.rb
View file @
6a4ee9aa
...
...
@@ -55,7 +55,6 @@ module ProtectedRef
private
# rubocop:disable Cop/ModuleWithInstanceVariables
def
ref_matcher
@ref_matcher
||=
ProtectedRefMatcher
.
new
(
self
)
end
...
...
app/models/concerns/relative_positioning.rb
View file @
6a4ee9aa
# rubocop:disable Cop/ModuleWithInstanceVariables
module
RelativePositioning
extend
ActiveSupport
::
Concern
...
...
@@ -45,6 +44,7 @@ module RelativePositioning
next_pos
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
move_between
(
before
,
after
)
return
move_after
(
before
)
unless
after
return
move_before
(
after
)
unless
before
...
...
@@ -59,6 +59,7 @@ module RelativePositioning
self
.
relative_position
=
position_between
(
before
.
relative_position
,
after
.
relative_position
)
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
move_after
(
before
=
self
)
pos_before
=
before
.
relative_position
pos_after
=
before
.
next_relative_position
...
...
@@ -74,6 +75,7 @@ module RelativePositioning
self
.
relative_position
=
position_between
(
pos_before
,
pos_after
)
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
move_before
(
after
=
self
)
pos_after
=
after
.
relative_position
pos_before
=
after
.
prev_relative_position
...
...
@@ -133,6 +135,7 @@ module RelativePositioning
end
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
save_positionable_neighbours
return
unless
@positionable_neighbours
...
...
app/models/concerns/resolvable_discussion.rb
View file @
6a4ee9aa
# rubocop:disable Cop/ModuleWithInstanceVariables
module
ResolvableDiscussion
extend
ActiveSupport
::
Concern
...
...
@@ -31,12 +30,14 @@ module ResolvableDiscussion
allow_nil:
true
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
resolvable?
return
@resolvable
if
@resolvable
.
present?
@resolvable
=
potentially_resolvable?
&&
notes
.
any?
(
&
:resolvable?
)
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
resolved?
return
@resolved
if
@resolved
.
present?
...
...
@@ -47,12 +48,14 @@ module ResolvableDiscussion
@first_note
||=
notes
.
first
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
first_note_to_resolve
return
unless
resolvable?
@first_note_to_resolve
||=
notes
.
find
(
&
:to_be_resolved?
)
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
last_resolved_note
return
unless
resolved?
...
...
@@ -89,6 +92,7 @@ module ResolvableDiscussion
private
# rubocop:disable Cop/ModuleWithInstanceVariables
def
update
# Do not select `Note.resolvable`, so that system notes remain in the collection
notes_relation
=
Note
.
where
(
id:
notes
.
map
(
&
:id
))
...
...
app/models/concerns/routable.rb
View file @
6a4ee9aa
# Store object full path in separate table for easy lookup and uniq validation
# Object must have name and path db fields and respond to parent and parent_changed? methods.
# rubocop:disable Cop/ModuleWithInstanceVariables
module
Routable
extend
ActiveSupport
::
Concern
...
...
@@ -87,6 +86,7 @@ module Routable
end
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
full_name
if
route
&&
route
.
name
.
present?
@full_name
||=
route
.
name
...
...
@@ -107,6 +107,7 @@ module Routable
RequestStore
[
full_path_key
]
||=
uncached_full_path
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
expires_full_path_cache
RequestStore
.
delete
(
full_path_key
)
if
RequestStore
.
active?
@full_path
=
nil
...
...
@@ -122,6 +123,7 @@ module Routable
private
# rubocop:disable Cop/ModuleWithInstanceVariables
def
uncached_full_path
if
route
&&
route
.
path
.
present?
@full_path
||=
route
.
path
...
...
@@ -157,6 +159,7 @@ module Routable
route
.
save
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
prepare_route
route
||
build_route
(
source:
self
)
route
.
path
=
build_full_path
...
...
app/models/concerns/storage/legacy_namespace.rb
View file @
6a4ee9aa
...
...
@@ -49,7 +49,6 @@ module Storage
private
# rubocop:disable Cop/ModuleWithInstanceVariables
def
old_repository_storage_paths
@old_repository_storage_paths
||=
repository_storage_paths
end
...
...
app/models/concerns/strip_attribute.rb
View file @
6a4ee9aa
...
...
@@ -17,7 +17,6 @@ module StripAttribute
strip_attrs
.
concat
(
attrs
)
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
strip_attrs
@strip_attrs
||=
[]
end
...
...
app/models/concerns/taskable.rb
View file @
6a4ee9aa
...
...
@@ -6,7 +6,6 @@ require 'task_list/filter'
# bugs".
#
# Used by MergeRequest and Issue
# rubocop:disable Cop/ModuleWithInstanceVariables
module
Taskable
COMPLETED
=
'completed'
.
freeze
INCOMPLETE
=
'incomplete'
.
freeze
...
...
@@ -37,6 +36,7 @@ module Taskable
end
# Called by `TaskList::Summary`
# rubocop:disable Cop/ModuleWithInstanceVariables
def
task_list_items
return
[]
if
description
.
blank?
...
...
app/models/concerns/time_trackable.rb
View file @
6a4ee9aa
...
...
@@ -4,7 +4,6 @@
#
# Used by Issue and MergeRequest.
#
# rubocop:disable Cop/ModuleWithInstanceVariables
module
TimeTrackable
extend
ActiveSupport
::
Concern
...
...
@@ -21,6 +20,7 @@ module TimeTrackable
has_many
:timelogs
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
spend_time
(
options
)
@time_spent
=
options
[
:duration
]
@time_spent_user
=
options
[
:user
]
...
...
@@ -50,6 +50,7 @@ module TimeTrackable
private
# rubocop:disable Cop/ModuleWithInstanceVariables
def
reset_spent_time
timelogs
.
new
(
time_spent:
total_time_spent
*
-
1
,
user:
@time_spent_user
)
end
...
...
@@ -58,6 +59,7 @@ module TimeTrackable
timelogs
.
new
(
time_spent:
time_spent
,
user:
@time_spent_user
)
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
check_negative_time_spent
return
if
time_spent
.
nil?
||
time_spent
==
:reset
...
...
app/services/spam_check_service.rb
View file @
6a4ee9aa
...
...
@@ -6,8 +6,8 @@
# Dependencies:
# - params with :request
#
# rubocop:disable Cop/ModuleWithInstanceVariables
module
SpamCheckService
# rubocop:disable Cop/ModuleWithInstanceVariables
def
filter_spam_check_params
@request
=
params
.
delete
(
:request
)
@api
=
params
.
delete
(
:api
)
...
...
@@ -18,6 +18,7 @@ module SpamCheckService
# 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
# attribute values.
# rubocop:disable Cop/ModuleWithInstanceVariables
def
spam_check
(
spammable
,
user
)
spam_service
=
SpamService
.
new
(
spammable
,
@request
)
...
...
app/services/system_note_service.rb
View file @
6a4ee9aa
...
...
@@ -662,7 +662,6 @@ module SystemNoteService
Rack
::
Utils
.
escape_html
(
text
)
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
url_helpers
@url_helpers
||=
Gitlab
::
Routing
.
url_helpers
end
...
...
config/initializers/rugged_use_gitlab_git_attributes.rb
View file @
6a4ee9aa
...
...
@@ -11,10 +11,10 @@
# anyway, and there is no great efficiency gain from just fetching the listed
# attributes with our implementation, so we ignore the additional arguments.
#
# rubocop:disable Cop/ModuleWithInstanceVariables
module
Rugged
class
Repository
module
UseGitlabGitAttributes
# rubocop:disable Cop/ModuleWithInstanceVariables
def
fetch_attributes
(
name
,
*
)
@attributes
||=
Gitlab
::
Git
::
Attributes
.
new
(
path
)
@attributes
.
attributes
(
name
)
...
...
doc/development/module_with_instance_variables.md
View file @
6a4ee9aa
##
Usually modules with instance variables
considered harmful
##
Modules with instance variables could be
considered harmful
### Background
...
...
@@ -43,7 +43,7 @@ instance variables in the final giant object, and that's where the problem is.
### Solutions
We should split the giant object into multiple objects, and they communicate
each other with the API, i.e. public methods. In short, composition over
with
each other with the API, i.e. public methods. In short, composition over
inheritance. This way, each smaller objects would have their own respective
limited states, i.e. instance variables. If one instance variable goes wrong,
we would be very clear that it's from that single small object, because
...
...
@@ -53,36 +53,67 @@ With clearly defined API, this would make things less coupled and much easier
to debug and track, and much more extensible for other objects to use, because
they communicate in a clear way, rather than implicit dependencies.
###
Exceptions
###
Acceptable use
However, it's not all that bad when using instance variables in a module,
as long as it's contained in the same module, that is no other modules or
objects are touching them. If that's the case, then it would be an acceptable
use. Unfortunately it's a bit hard to code this principle in the cop, so
for now we rely on people turning off the cops, if they think that the use
conform this rule.
use.
Here's an acceptable case:
We especially allow the case where a single instance variable is used with
`||=`
to setup the value. This would look like:
```
ruby
# This is ok, as long as `@attributes` is never used anywhere else.
# Consider adding some prefix or suffix to avoid name conflicts though.
# rubocop:disable Cop/ModuleWithInstanceVariables
module
Rugged
class
Repository
module
UseGitlabGitAttributes
def
fetch_attributes
(
name
,
*
)
@attributes
||=
Gitlab
::
Git
::
Attributes
.
new
(
path
)
@attributes
.
attributes
(
name
)
end
module
M
def
f
@f
||=
true
end
end
```
Unfortunately it's not easy to code more complex rules into the cop, so
we rely on people's best judge. If we could find another good pattern we
could easily add to the cop, we should do it.
### How to rewrite and avoid disabling this cop
Even if we could just disable the cop, we should avoid doing so. Some code
could be easily rewritten in simple form. Here's an example. Consider this
acceptable method:
```
ruby
module
Gitlab
module
Emoji
def
emoji_unicode_version
(
name
)
@emoji_unicode_versions_by_name
||=
JSON
.
parse
(
File
.
read
(
Rails
.
root
.
join
(
'fixtures'
,
'emojis'
,
'emoji-unicode-version-map.json'
)))
@emoji_unicode_versions_by_name
[
name
]
end
end
end
```
It's still offending because it's not just
`||=`
, but We could split this
method into two:
```
ruby
module
Gitlab
module
Emoji
def
emoji_unicode_version
(
name
)
emoji_unicode_versions_by_name
[
name
]
end
prepend
UseGitlabGitAttributes
private
def
emoji_unicode_versions_by_name
@emoji_unicode_versions_by_name
||=
JSON
.
parse
(
File
.
read
(
Rails
.
root
.
join
(
'fixtures'
,
'emojis'
,
'emoji-unicode-version-map.json'
)))
end
end
end
```
Here's a bad example which we sh
ould rewrite:
Now the cop won't complain. Here's another bad example which we c
ould rewrite:
```
ruby
module
SpamCheckService
...
...
@@ -146,7 +177,7 @@ end
This way, all those instance variables are isolated in
`SpamCheckService`
rather than who ever include the module, and those modules which were also
included, making it much easier to track down the issues if there's any,
and it also reduce the chance of having name conflicts.
and it also reduce
s
the chance of having name conflicts.
### Things we might need to ignore right now
...
...
lib/after_commit_queue.rb
View file @
6a4ee9aa
...
...
@@ -20,7 +20,6 @@ module AfterCommitQueue
end
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
_after_commit_queue
@after_commit_queue
||=
[]
end
...
...
lib/api/api_guard.rb
View file @
6a4ee9aa
...
...
@@ -2,7 +2,6 @@
require
'rack/oauth2'
# rubocop:disable Cop/ModuleWithInstanceVariables
module
API
module
APIGuard
extend
ActiveSupport
::
Concern
...
...
@@ -43,6 +42,8 @@ module API
# Helper Methods for Grape Endpoint
module
HelperMethods
attr_reader
:current_user
# Invokes the doorkeeper guard.
#
# If token is presented and valid, then it sets @current_user.
...
...
@@ -61,6 +62,7 @@ module API
# scopes: (optional) scopes required for this guard.
# Defaults to empty array.
#
# rubocop:disable Cop/ModuleWithInstanceVariables
def
doorkeeper_guard
(
scopes:
[])
access_token
=
find_access_token
return
nil
unless
access_token
...
...
@@ -88,10 +90,6 @@ module API
find_user_by_authentication_token
(
token_string
)
||
find_user_by_personal_access_token
(
token_string
,
scopes
)
end
def
current_user
@current_user
end
private
def
find_user_by_authentication_token
(
token_string
)
...
...
lib/api/helpers.rb
View file @
6a4ee9aa
# rubocop:disable Cop/ModuleWithInstanceVariables
module
API
module
Helpers
include
Gitlab
::
Utils
...
...
@@ -33,6 +32,7 @@ module API
end
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
current_user
return
@current_user
if
defined?
(
@current_user
)
...
...
@@ -396,6 +396,7 @@ module API
warden
.
try
(
:authenticate
)
if
verified_request?
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
initial_current_user
return
@initial_current_user
if
defined?
(
@initial_current_user
)
Gitlab
::
Auth
::
UniqueIpsLimiter
.
limit_user!
do
...
...
@@ -411,6 +412,7 @@ module API
end
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
sudo!
return
unless
sudo_identifier
return
unless
initial_current_user
...
...
lib/api/helpers/internal_helpers.rb
View file @
6a4ee9aa
# rubocop:disable Cop/ModuleWithInstanceVariables
module
API
module
Helpers
module
InternalHelpers
...
...
@@ -7,20 +6,20 @@ module API
'git-upload-pack'
=>
:ssh_upload_pack
}.
freeze
attr_reader
:redirected_path
# rubocop:disable Cop/ModuleWithInstanceVariables
def
wiki?
set_project
unless
defined?
(
@wiki
)
@wiki
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
project
set_project
unless
defined?
(
@project
)
@project
end
def
redirected_path
@redirected_path
end
def
ssh_authentication_abilities
[
:read_project
,
...
...
lib/api/helpers/runner.rb
View file @
6a4ee9aa
...
...
@@ -21,7 +21,6 @@ module API
forbidden!
unless
current_runner
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
current_runner
@runner
||=
::
Ci
::
Runner
.
find_by_token
(
params
[
:token
].
to_s
)
end
...
...
lib/extracts_path.rb
View file @
6a4ee9aa
# Module providing methods for dealing with separating a tree-ish string and a
# file path string when combined in a request parameter
# rubocop:disable Cop/ModuleWithInstanceVariables
module
ExtractsPath
# Raised when given an invalid file path
InvalidPathError
=
Class
.
new
(
StandardError
)
...
...
@@ -38,6 +37,7 @@ module ExtractsPath
#
# Returns an Array where the first value is the tree-ish and the second is the
# path
# rubocop:disable Cop/ModuleWithInstanceVariables
def
extract_ref
(
id
)
pair
=
[
''
,
''
]
...
...
@@ -105,6 +105,7 @@ module ExtractsPath
#
# Automatically renders `not_found!` if a valid tree path could not be
# resolved (e.g., when a user inserts an invalid path or ref).
# rubocop:disable Cop/ModuleWithInstanceVariables
def
assign_ref_vars
# assign allowed options
allowed_options
=
[
"filter_ref"
]
...
...
@@ -133,6 +134,7 @@ module ExtractsPath
render_404
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
tree
@tree
||=
@repo
.
tree
(
@commit
.
id
,
@path
)
end
...
...
@@ -146,6 +148,7 @@ module ExtractsPath
id
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
ref_names
return
[]
unless
@project
...
...
lib/gitlab/ci/charts.rb
View file @
6a4ee9aa
...
...
@@ -10,7 +10,6 @@ module Gitlab
.
transform_keys
{
|
date
|
date
.
strftime
(
@format
)
}
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
interval_step
@interval_step
||=
1
.
day
end
...
...
@@ -30,7 +29,6 @@ module Gitlab
end
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
interval_step
@interval_step
||=
1
.
month
end
...
...
lib/gitlab/ci/config/entry/configurable.rb
View file @
6a4ee9aa
...
...
@@ -13,7 +13,6 @@ module Gitlab
# script: ...
# artifacts: ...
#
# rubocop:disable Cop/ModuleWithInstanceVariables
module
Configurable
extend
ActiveSupport
::
Concern
...
...
@@ -25,6 +24,7 @@ module Gitlab
end
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
compose!
(
deps
=
nil
)
return
unless
valid?
...
...
lib/gitlab/ci/config/entry/validatable.rb
View file @
6a4ee9aa
# rubocop:disable Cop/ModuleWithInstanceVariables
module
Gitlab
module
Ci
class
Config
...
...
@@ -13,6 +12,7 @@ module Gitlab
end
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
errors
@validator
.
messages
+
descendants
.
flat_map
(
&
:errors
)
end
...
...
lib/gitlab/ci/model.rb
View file @
6a4ee9aa
...
...
@@ -5,7 +5,6 @@ module Gitlab
"ci_"
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
model_name
@model_name
||=
ActiveModel
::
Name
.
new
(
self
,
nil
,
self
.
name
.
split
(
"::"
).
last
)
end
...
...
lib/gitlab/cycle_analytics/base_query.rb
View file @
6a4ee9aa
...
...
@@ -7,11 +7,11 @@ module Gitlab
private
# rubocop:disable Cop/ModuleWithInstanceVariables
def
base_query
@base_query
||=
stage_query
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
stage_query
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
]))
...
...
lib/gitlab/cycle_analytics/production_helper.rb
View file @
6a4ee9aa
# rubocop:disable Cop/ModuleWithInstanceVariables
module
Gitlab
module
CycleAnalytics
module
ProductionHelper
# rubocop:disable Cop/ModuleWithInstanceVariables
def
stage_query
super
.
where
(
mr_metrics_table
[
:first_deployed_to_production_at
].
gteq
(
@options
[
:from
]))
end
...
...
lib/gitlab/email/handler/reply_processing.rb
View file @
6a4ee9aa
...
...
@@ -12,7 +12,6 @@ module Gitlab
raise
NotImplementedError
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
message
@message
||=
process_message
end
...
...
lib/gitlab/emoji.rb
View file @
6a4ee9aa
# rubocop:disable Cop/ModuleWithInstanceVariables
module
Gitlab
module
Emoji
extend
self
...
...
@@ -32,8 +31,7 @@ module Gitlab
end
def
emoji_unicode_version
(
name
)
@emoji_unicode_versions_by_name
||=
JSON
.
parse
(
File
.
read
(
Rails
.
root
.
join
(
'fixtures'
,
'emojis'
,
'emoji-unicode-version-map.json'
)))
@emoji_unicode_versions_by_name
[
name
]
emoji_unicode_versions_by_name
[
name
]
end
def
normalize_emoji_name
(
name
)
...
...
@@ -57,5 +55,12 @@ module Gitlab
ActionController
::
Base
.
helpers
.
content_tag
(
'gl-emoji'
,
emoji_info
[
'moji'
],
title:
emoji_info
[
'description'
],
data:
data
)
end
private
def
emoji_unicode_versions_by_name
@emoji_unicode_versions_by_name
||=
JSON
.
parse
(
File
.
read
(
Rails
.
root
.
join
(
'fixtures'
,
'emojis'
,
'emoji-unicode-version-map.json'
)))
end
end
end
lib/gitlab/identifier.rb
View file @
6a4ee9aa
...
...
@@ -52,7 +52,6 @@ module Gitlab
end
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
identification_cache
@identification_cache
||=
{
email:
{},
...
...
lib/gitlab/metrics/influx_db.rb
View file @
6a4ee9aa
# rubocop:disable Cop/ModuleWithInstanceVariables
module
Gitlab
module
Metrics
module
InfluxDb
...
...
@@ -150,6 +149,7 @@ module Gitlab
# When enabled this should be set before being used as the usual pattern
# "@foo ||= bar" is _not_ thread-safe.
# rubocop:disable Cop/ModuleWithInstanceVariables
def
pool
if
influx_metrics_enabled?
if
@pool
.
nil?
...
...
lib/gitlab/metrics/prometheus.rb
View file @
6a4ee9aa
require
'prometheus/client'
# rubocop:disable Cop/ModuleWithInstanceVariables
module
Gitlab
module
Metrics
module
Prometheus
...
...
@@ -14,6 +13,7 @@ module Gitlab
::
File
.
writable?
(
multiprocess_files_dir
)
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
prometheus_metrics_enabled?
return
@prometheus_metrics_enabled
if
defined?
(
@prometheus_metrics_enabled
)
...
...
lib/gitlab/prometheus/additional_metrics_parser.rb
View file @
6a4ee9aa
...
...
@@ -26,7 +26,6 @@ module Gitlab
load_yaml_file
&
.
map
(
&
:deep_symbolize_keys
).
freeze
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
load_yaml_file
@loaded_yaml_file
||=
YAML
.
load_file
(
Rails
.
root
.
join
(
'config/prometheus/additional_metrics.yml'
))
end
...
...
lib/gitlab/prometheus/queries/query_additional_metrics.rb
View file @
6a4ee9aa
...
...
@@ -56,7 +56,6 @@ module Gitlab
query
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
available_metrics
@available_metrics
||=
client_label_values
||
[]
end
...
...
lib/gitlab/regex.rb
View file @
6a4ee9aa
# rubocop:disable Cop/ModuleWithInstanceVariables
module
Gitlab
module
Regex
extend
self
...
...
lib/gitlab/slash_commands/presenters/issue_base.rb
View file @
6a4ee9aa
# rubocop:disable Cop/ModuleWithInstanceVariables
module
Gitlab
module
SlashCommands
module
Presenters
...
...
@@ -11,14 +10,17 @@ module Gitlab
issuable
.
open?
?
'Open'
:
'Closed'
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
project
@resource
.
project
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
author
@resource
.
author
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
fields
[
{
...
...
lib/gitlab/themes.rb
View file @
6a4ee9aa
...
...
@@ -72,7 +72,6 @@ module Gitlab
private
# rubocop:disable Cop/ModuleWithInstanceVariables
def
default_id
@default_id
||=
begin
id
=
Gitlab
.
config
.
gitlab
.
default_theme
.
to_i
...
...
lib/tasks/gitlab/task_helpers.rb
View file @
6a4ee9aa
require
'rainbow/ext/string'
# rubocop:disable Cop/ModuleWithInstanceVariables
module
Gitlab
TaskFailedError
=
Class
.
new
(
StandardError
)
TaskAbortedByUserError
=
Class
.
new
(
StandardError
)
...
...
@@ -105,6 +104,7 @@ module Gitlab
Gitlab
.
config
.
gitlab
.
user
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
gitlab_user?
return
@is_gitlab_user
unless
@is_gitlab_user
.
nil?
...
...
@@ -112,6 +112,7 @@ module Gitlab
@is_gitlab_user
=
current_user
==
gitlab_user
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
warn_user_is_not_gitlab
return
if
@warned_user_not_gitlab
...
...
qa/qa/runtime/namespace.rb
View file @
6a4ee9aa
...
...
@@ -3,7 +3,6 @@ module QA
module
Namespace
extend
self
# rubocop:disable Cop/ModuleWithInstanceVariables
def
time
@time
||=
Time
.
now
end
...
...
rubocop/cop/module_with_instance_variables.rb
View file @
6a4ee9aa
...
...
@@ -45,11 +45,29 @@ module RuboCop
def
check_method_definition
(
node
)
node
.
each_child_node
(
:def
)
do
|
definition
|
definition
.
each_descendant
(
:ivar
,
:ivasgn
)
do
|
offense
|
add_offense
(
offense
,
:expression
)
# 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
else
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
end
end
end
spec/rubocop/cop/module_with_instance_variables_spec.rb
View file @
6a4ee9aa
...
...
@@ -19,12 +19,20 @@ describe RuboCop::Cop::ModuleWithInstanceVariables do
end
end
shared_examples
(
'not registering offense'
)
do
it
'does not register offenses'
do
inspect_source
(
cop
,
source
)
expect
(
cop
.
offenses
).
to
be_empty
end
end
context
'when source is a regular module'
do
let
(
:source
)
do
<<~
RUBY
module M
def f
@f
||
= true
@f = true
end
end
RUBY
...
...
@@ -59,7 +67,7 @@ describe RuboCop::Cop::ModuleWithInstanceVariables do
module N
module M
def f
@f
||
= true
@f = true
end
def g
...
...
@@ -79,39 +87,86 @@ describe RuboCop::Cop::ModuleWithInstanceVariables do
it_behaves_like
'registering offense'
end
context
'when source is offending but it is a rails helper'
do
before
do
allow
(
cop
).
to
receive
(
:rails_helper?
).
and_return
(
true
)
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
it
'does not register offenses'
do
inspect_source
(
cop
,
<<~
RUBY
)
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
let
(
:source
)
do
<<~
RUBY
module M
def f
@f ||= true
end
end
RUBY
expect
(
cop
.
offenses
).
to
be_empty
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
)
context
'when source is using simple or ivar assignment with other ivar'
do
let
(
:source
)
do
<<~
RUBY
module M
def f
@f ||= g(@g)
end
end
RUBY
end
it
'does not register offenses'
do
inspect_source
(
cop
,
<<~
RUBY
)
let
(
:offending_lines
)
{
[
3
]
}
it_behaves_like
'registering offense'
end
context
'when source is using or ivar assignment with something else'
do
let
(
:source
)
do
<<~
RUBY
module M
def f
@f = true
@f ||= true
@f.to_s
end
end
RUBY
expect
(
cop
.
offenses
).
to
be_empty
end
let
(
:offending_lines
)
{
[
3
,
4
]
}
it_behaves_like
'registering offense'
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment