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
f57989c2
Commit
f57989c2
authored
Feb 08, 2017
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a spec for our custom GemFetcher cop
parent
75092d96
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
19 deletions
+76
-19
.rubocop.yml
.rubocop.yml
+12
-10
rubocop/cop/gem_fetcher.rb
rubocop/cop/gem_fetcher.rb
+16
-7
rubocop/rubocop.rb
rubocop/rubocop.rb
+2
-2
spec/rubocop/cop/gem_fetcher_spec.rb
spec/rubocop/cop/gem_fetcher_spec.rb
+46
-0
No files found.
.rubocop.yml
View file @
f57989c2
...
@@ -31,8 +31,7 @@ AllCops:
...
@@ -31,8 +31,7 @@ AllCops:
-
'
lib/gitlab/seeder.rb'
-
'
lib/gitlab/seeder.rb'
-
'
generator_templates/**/*'
-
'
generator_templates/**/*'
# Style #######################################################################
##################### Style ##################################
# Check indentation of private/protected visibility modifiers.
# Check indentation of private/protected visibility modifiers.
Style/AccessModifierIndentation
:
Style/AccessModifierIndentation
:
...
@@ -471,7 +470,7 @@ Style/WhileUntilModifier:
...
@@ -471,7 +470,7 @@ Style/WhileUntilModifier:
Style/WordArray
:
Style/WordArray
:
Enabled
:
false
Enabled
:
false
#
################### Metrics
################################
#
Metrics #####################################
################################
# A calculated magnitude based on number of assignments,
# A calculated magnitude based on number of assignments,
# branches, and conditions.
# branches, and conditions.
...
@@ -516,8 +515,7 @@ Metrics/PerceivedComplexity:
...
@@ -516,8 +515,7 @@ Metrics/PerceivedComplexity:
Enabled
:
true
Enabled
:
true
Max
:
18
Max
:
18
# Lint ########################################################################
#################### Lint ################################
# Checks for useless access modifiers.
# Checks for useless access modifiers.
Lint/UselessAccessModifier
:
Lint/UselessAccessModifier
:
...
@@ -679,8 +677,7 @@ Lint/UselessSetterCall:
...
@@ -679,8 +677,7 @@ Lint/UselessSetterCall:
Lint/Void
:
Lint/Void
:
Enabled
:
true
Enabled
:
true
# Performance #################################################################
##################### Performance ############################
# Use `casecmp` rather than `downcase ==`.
# Use `casecmp` rather than `downcase ==`.
Performance/Casecmp
:
Performance/Casecmp
:
...
@@ -718,8 +715,7 @@ Performance/StringReplacement:
...
@@ -718,8 +715,7 @@ Performance/StringReplacement:
Performance/TimesMap
:
Performance/TimesMap
:
Enabled
:
true
Enabled
:
true
# Rails #######################################################################
##################### Rails ##################################
# Enables Rails cops.
# Enables Rails cops.
Rails
:
Rails
:
...
@@ -767,7 +763,7 @@ Rails/ReadWriteAttribute:
...
@@ -767,7 +763,7 @@ Rails/ReadWriteAttribute:
Rails/ScopeArgs
:
Rails/ScopeArgs
:
Enabled
:
true
Enabled
:
true
#
#################### RSpec
##################################
#
RSpec #####################################
##################################
# Check that instances are not being stubbed globally.
# Check that instances are not being stubbed globally.
RSpec/AnyInstance
:
RSpec/AnyInstance
:
...
@@ -828,3 +824,9 @@ RSpec/NotToNot:
...
@@ -828,3 +824,9 @@ RSpec/NotToNot:
# Prefer using verifying doubles over normal doubles.
# Prefer using verifying doubles over normal doubles.
RSpec/VerifiedDoubles
:
RSpec/VerifiedDoubles
:
Enabled
:
false
Enabled
:
false
# Custom ######################################################################
# Disallow the `git` and `github` arguments in the Gemfile.
GemFetcher
:
Enabled
:
true
rubocop/cop/gem_fetcher.rb
View file @
f57989c2
module
RuboCop
module
RuboCop
module
Cop
module
Cop
# Cop that checks for all gems specified in the Gemfile, and will
# This cop prevents usage of the `git` and `github` arguments to `gem` in a
# alert if any gem is to be fetched not from the RubyGems index.
# `Gemfile` in order to avoid additional points of failure beyond
# This enforcement is done so as to minimize external build
# rubygems.org.
# dependencies and build times.
class
GemFetcher
<
RuboCop
::
Cop
::
Cop
class
GemFetcher
<
RuboCop
::
Cop
::
Cop
MSG
=
'Do not use gems from git repositories, only use gems from RubyGems.'
MSG
=
'Do not use gems from git repositories, only use gems from RubyGems.'
GIT_KEYS
=
[
:git
,
:github
]
GIT_KEYS
=
[
:git
,
:github
]
def
on_send
(
node
)
def
on_send
(
node
)
file_path
=
node
.
location
.
expression
.
source_buffer
.
name
return
unless
gemfile?
(
node
)
return
unless
file_path
.
end_with?
(
"Gemfile"
)
func_name
=
node
.
children
[
1
]
func_name
=
node
.
children
[
1
]
return
unless
func_name
==
:gem
return
unless
func_name
==
:gem
...
@@ -19,10 +17,21 @@ module RuboCop
...
@@ -19,10 +17,21 @@ module RuboCop
node
.
children
.
last
.
each_node
(
:pair
)
do
|
pair
|
node
.
children
.
last
.
each_node
(
:pair
)
do
|
pair
|
key_name
=
pair
.
children
[
0
].
children
[
0
].
to_sym
key_name
=
pair
.
children
[
0
].
children
[
0
].
to_sym
if
GIT_KEYS
.
include?
(
key_name
)
if
GIT_KEYS
.
include?
(
key_name
)
add_offense
(
node
,
:selector
)
add_offense
(
node
,
pair
.
source_range
,
MSG
)
end
end
end
end
end
end
private
def
gemfile?
(
node
)
node
.
location
.
expression
.
source_buffer
.
name
.
end_with?
(
"Gemfile"
)
end
end
end
end
end
end
end
rubocop/rubocop.rb
View file @
f57989c2
require_relative
'cop/
migration/add_index
'
require_relative
'cop/
gem_fetcher
'
require_relative
'cop/migration/add_column'
require_relative
'cop/migration/add_column'
require_relative
'cop/migration/add_column_with_default'
require_relative
'cop/migration/add_column_with_default'
require_relative
'cop/
gem_fetcher
'
require_relative
'cop/
migration/add_index
'
spec/rubocop/cop/gem_fetcher_spec.rb
0 → 100644
View file @
f57989c2
require
'spec_helper'
require
'rubocop'
require
'rubocop/rspec/support'
require_relative
'../../../rubocop/cop/gem_fetcher'
describe
RuboCop
::
Cop
::
GemFetcher
do
include
CopHelper
subject
(
:cop
)
{
described_class
.
new
}
context
'in Gemfile'
do
before
do
allow
(
cop
).
to
receive
(
:gemfile?
).
and_return
(
true
)
end
it
'registers an offense when a gem uses `git`'
do
inspect_source
(
cop
,
'gem "foo", git: "https://gitlab.com/foo/bar.git"'
)
aggregate_failures
do
expect
(
cop
.
offenses
.
size
).
to
eq
(
1
)
expect
(
cop
.
offenses
.
map
(
&
:line
)).
to
eq
([
1
])
expect
(
cop
.
highlights
).
to
eq
([
'git: "https://gitlab.com/foo/bar.git"'
])
end
end
it
'registers an offense when a gem uses `github`'
do
inspect_source
(
cop
,
'gem "foo", github: "foo/bar.git"'
)
aggregate_failures
do
expect
(
cop
.
offenses
.
size
).
to
eq
(
1
)
expect
(
cop
.
offenses
.
map
(
&
:line
)).
to
eq
([
1
])
expect
(
cop
.
highlights
).
to
eq
([
'github: "foo/bar.git"'
])
end
end
end
context
'outside of Gemfile'
do
it
'registers no offense'
do
inspect_source
(
cop
,
'gem "foo", git: "https://gitlab.com/foo/bar.git"'
)
expect
(
cop
.
offenses
.
size
).
to
eq
(
0
)
end
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