diff options
author | Robert Speicher <rspeicher@gmail.com> | 2017-02-08 16:22:36 -0500 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2017-02-09 12:11:19 -0500 |
commit | f57989c2ed15c5d84f198ca334686f5bf7207f8e (patch) | |
tree | dc3427e8017cc146b4e24d7784edbdb177f56c60 /rubocop | |
parent | 75092d9647bab00070b0b77f0fe1050d900a39a1 (diff) | |
download | gitlab-ce-f57989c2ed15c5d84f198ca334686f5bf7207f8e.tar.gz |
Add a spec for our custom GemFetcher coprs-gemfetcher-cop-spec
Diffstat (limited to 'rubocop')
-rw-r--r-- | rubocop/cop/gem_fetcher.rb | 23 | ||||
-rw-r--r-- | rubocop/rubocop.rb | 4 |
2 files changed, 18 insertions, 9 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 diff --git a/rubocop/rubocop.rb b/rubocop/rubocop.rb index 3e292a4527c..aa35fb1701c 100644 --- a/rubocop/rubocop.rb +++ b/rubocop/rubocop.rb @@ -1,4 +1,4 @@ -require_relative 'cop/migration/add_index' +require_relative 'cop/gem_fetcher' require_relative 'cop/migration/add_column' require_relative 'cop/migration/add_column_with_default' -require_relative 'cop/gem_fetcher' +require_relative 'cop/migration/add_index' |