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
1b73e05d
Commit
1b73e05d
authored
Dec 13, 2021
by
Igor Drozdov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Performance/Detect offences
It encourages using `.find` instead of `select {...}.first`
parent
7530be6f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
12 additions
and
23 deletions
+12
-23
.rubocop_todo.yml
.rubocop_todo.yml
+0
-11
ee/spec/controllers/projects/dependencies_controller_spec.rb
ee/spec/controllers/projects/dependencies_controller_spec.rb
+2
-2
ee/spec/requests/api/dependencies_spec.rb
ee/spec/requests/api/dependencies_spec.rb
+1
-1
spec/lib/gitlab/git/tree_spec.rb
spec/lib/gitlab/git/tree_spec.rb
+5
-5
spec/lib/gitlab/import_export/project/tree_restorer_spec.rb
spec/lib/gitlab/import_export/project/tree_restorer_spec.rb
+3
-3
spec/models/event_spec.rb
spec/models/event_spec.rb
+1
-1
No files found.
.rubocop_todo.yml
View file @
1b73e05d
...
...
@@ -289,17 +289,6 @@ Performance/DeleteSuffix:
-
'
ee/app/models/geo/upload_registry.rb'
-
'
ee/app/workers/geo/file_download_dispatch_worker/attachment_job_finder.rb'
# Offense count: 13
# Cop supports --auto-correct.
Performance/Detect
:
Exclude
:
-
'
ee/spec/controllers/projects/dependencies_controller_spec.rb'
-
'
ee/spec/requests/api/dependencies_spec.rb'
-
'
qa/qa/runtime/feature.rb'
-
'
spec/lib/gitlab/git/tree_spec.rb'
-
'
spec/lib/gitlab/import_export/project/tree_restorer_spec.rb'
-
'
spec/models/event_spec.rb'
# Offense count: 121
Performance/MethodObjectAsBlock
:
Enabled
:
false
...
...
ee/spec/controllers/projects/dependencies_controller_spec.rb
View file @
1b73e05d
...
...
@@ -147,7 +147,7 @@ RSpec.describe Projects::DependenciesController do
end
it
'returns vulnerability params'
do
dependency
=
json_response
[
'dependencies'
].
select
{
|
dep
|
dep
[
'name'
]
==
'nokogiri'
}.
first
dependency
=
json_response
[
'dependencies'
].
find
{
|
dep
|
dep
[
'name'
]
==
'nokogiri'
}
vulnerability
=
dependency
[
'vulnerabilities'
].
first
path
=
"/security/vulnerabilities/
#{
finding
.
vulnerability_id
}
"
...
...
@@ -182,7 +182,7 @@ RSpec.describe Projects::DependenciesController do
end
it
'include license information to response'
do
nokogiri
=
json_response
[
'dependencies'
].
select
{
|
dep
|
dep
[
'name'
]
==
'nokogiri'
}.
first
nokogiri
=
json_response
[
'dependencies'
].
find
{
|
dep
|
dep
[
'name'
]
==
'nokogiri'
}
expect
(
nokogiri
[
'licenses'
]).
not_to
be_empty
end
...
...
ee/spec/requests/api/dependencies_spec.rb
View file @
1b73e05d
...
...
@@ -37,7 +37,7 @@ RSpec.describe API::Dependencies do
end
it
'returns vulnerabilities info'
do
vulnerability
=
json_response
.
select
{
|
dep
|
dep
[
'name'
]
==
'nokogiri'
}[
0
]
[
'vulnerabilities'
][
0
]
vulnerability
=
json_response
.
find
{
|
dep
|
dep
[
'name'
]
==
'nokogiri'
}
[
'vulnerabilities'
][
0
]
path
=
"/security/vulnerabilities/
#{
finding
.
vulnerability_id
}
"
expect
(
vulnerability
[
'name'
]).
to
eq
(
'Vulnerabilities in libxml2 in nokogiri'
)
...
...
spec/lib/gitlab/git/tree_spec.rb
View file @
1b73e05d
...
...
@@ -43,7 +43,7 @@ RSpec.describe Gitlab::Git::Tree, :seed_helper do
end
describe
'#dir?'
do
let
(
:dir
)
{
entries
.
select
(
&
:dir?
).
first
}
let
(
:dir
)
{
entries
.
find
(
&
:dir?
)
}
it
{
expect
(
dir
).
to
be_kind_of
Gitlab
::
Git
::
Tree
}
it
{
expect
(
dir
.
id
).
to
eq
(
'3c122d2b7830eca25235131070602575cf8b41a1'
)
}
...
...
@@ -134,7 +134,7 @@ RSpec.describe Gitlab::Git::Tree, :seed_helper do
end
describe
'#file?'
do
let
(
:file
)
{
entries
.
select
(
&
:file?
).
first
}
let
(
:file
)
{
entries
.
find
(
&
:file?
)
}
it
{
expect
(
file
).
to
be_kind_of
Gitlab
::
Git
::
Tree
}
it
{
expect
(
file
.
id
).
to
eq
(
'dfaa3f97ca337e20154a98ac9d0be76ddd1fcc82'
)
}
...
...
@@ -143,21 +143,21 @@ RSpec.describe Gitlab::Git::Tree, :seed_helper do
end
describe
'#readme?'
do
let
(
:file
)
{
entries
.
select
(
&
:readme?
).
first
}
let
(
:file
)
{
entries
.
find
(
&
:readme?
)
}
it
{
expect
(
file
).
to
be_kind_of
Gitlab
::
Git
::
Tree
}
it
{
expect
(
file
.
name
).
to
eq
(
'README.md'
)
}
end
describe
'#contributing?'
do
let
(
:file
)
{
entries
.
select
(
&
:contributing?
).
first
}
let
(
:file
)
{
entries
.
find
(
&
:contributing?
)
}
it
{
expect
(
file
).
to
be_kind_of
Gitlab
::
Git
::
Tree
}
it
{
expect
(
file
.
name
).
to
eq
(
'CONTRIBUTING.md'
)
}
end
describe
'#submodule?'
do
let
(
:submodule
)
{
entries
.
select
(
&
:submodule?
).
first
}
let
(
:submodule
)
{
entries
.
find
(
&
:submodule?
)
}
it
{
expect
(
submodule
).
to
be_kind_of
Gitlab
::
Git
::
Tree
}
it
{
expect
(
submodule
.
id
).
to
eq
(
'79bceae69cb5750d6567b223597999bfa91cb3b9'
)
}
...
...
spec/lib/gitlab/import_export/project/tree_restorer_spec.rb
View file @
1b73e05d
...
...
@@ -3,7 +3,7 @@
require
'spec_helper'
def
match_mr1_note
(
content_regex
)
MergeRequest
.
find_by
(
title:
'MR1'
).
notes
.
select
{
|
n
|
n
.
note
.
match
(
/
#{
content_regex
}
/
)}.
first
MergeRequest
.
find_by
(
title:
'MR1'
).
notes
.
find
{
|
n
|
n
.
note
.
match
(
/
#{
content_regex
}
/
)
}
end
RSpec
.
describe
Gitlab
::
ImportExport
::
Project
::
TreeRestorer
do
...
...
@@ -75,7 +75,7 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do
context
'for an Issue'
do
it
'does not import note_html'
do
note_content
=
'Quo reprehenderit aliquam qui dicta impedit cupiditate eligendi'
issue_note
=
Issue
.
find_by
(
description:
'Aliquam enim illo et possimus.'
).
notes
.
select
{
|
n
|
n
.
note
.
match
(
/
#{
note_content
}
/
)}.
first
issue_note
=
Issue
.
find_by
(
description:
'Aliquam enim illo et possimus.'
).
notes
.
find
{
|
n
|
n
.
note
.
match
(
/
#{
note_content
}
/
)
}
expect
(
issue_note
.
note_html
).
to
match
(
/
#{
note_content
}
/
)
end
...
...
@@ -552,7 +552,7 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do
it
'issue system note metadata restored successfully'
do
note_content
=
'created merge request !1 to address this issue'
note
=
project
.
issues
.
first
.
notes
.
select
{
|
n
|
n
.
note
.
match
(
/
#{
note_content
}
/
)}.
first
note
=
project
.
issues
.
first
.
notes
.
find
{
|
n
|
n
.
note
.
match
(
/
#{
note_content
}
/
)}
expect
(
note
.
noteable_type
).
to
eq
(
'Issue'
)
expect
(
note
.
system
).
to
eq
(
true
)
...
...
spec/models/event_spec.rb
View file @
1b73e05d
...
...
@@ -706,7 +706,7 @@ RSpec.describe Event do
describe
'.for_wiki_meta'
do
it
'finds events for a given wiki page metadata object'
do
event
=
events
.
select
(
&
:wiki_page?
).
first
event
=
events
.
find
(
&
:wiki_page?
)
expect
(
described_class
.
for_wiki_meta
(
event
.
target
)).
to
contain_exactly
(
event
)
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