summaryrefslogtreecommitdiff
path: root/rubocop/cop
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2017-02-08 16:22:36 -0500
committerRobert Speicher <rspeicher@gmail.com>2017-02-09 12:11:19 -0500
commitf57989c2ed15c5d84f198ca334686f5bf7207f8e (patch)
treedc3427e8017cc146b4e24d7784edbdb177f56c60 /rubocop/cop
parent75092d9647bab00070b0b77f0fe1050d900a39a1 (diff)
downloadgitlab-ce-f57989c2ed15c5d84f198ca334686f5bf7207f8e.tar.gz
Add a spec for our custom GemFetcher coprs-gemfetcher-cop-spec
Diffstat (limited to 'rubocop/cop')
-rw-r--r--rubocop/cop/gem_fetcher.rb23
1 files changed, 16 insertions, 7 deletions
diff --git a/rubocop/cop/gem_fetcher.rb b/rubocop/cop/gem_fetcher.rb
index 4a63c760744..c199f6acab2 100644
--- a/rubocop/cop/gem_fetcher.rb
+++ b/rubocop/cop/gem_fetcher.rb
@@ -1,17 +1,15 @@
module RuboCop
module Cop
- # Cop that checks for all gems specified in the Gemfile, and will
- # alert if any gem is to be fetched not from the RubyGems index.
- # This enforcement is done so as to minimize external build
- # dependencies and build times.
+ # This cop prevents usage of the `git` and `github` arguments to `gem` in a
+ # `Gemfile` in order to avoid additional points of failure beyond
+ # rubygems.org.
class GemFetcher < RuboCop::Cop::Cop
MSG = 'Do not use gems from git repositories, only use gems from RubyGems.'
GIT_KEYS = [:git, :github]
def on_send(node)
- file_path = node.location.expression.source_buffer.name
- return unless file_path.end_with?("Gemfile")
+ return unless gemfile?(node)
func_name = node.children[1]
return unless func_name == :gem
@@ -19,10 +17,21 @@ module RuboCop
node.children.last.each_node(:pair) do |pair|
key_name = pair.children[0].children[0].to_sym
if GIT_KEYS.include?(key_name)
- add_offense(node, :selector)
+ add_offense(node, pair.source_range, MSG)
end
end
end
+
+ private
+
+ def gemfile?(node)
+ node
+ .location
+ .expression
+ .source_buffer
+ .name
+ .end_with?("Gemfile")
+ end
end
end
end