From f57989c2ed15c5d84f198ca334686f5bf7207f8e Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 8 Feb 2017 16:22:36 -0500 Subject: Add a spec for our custom GemFetcher cop --- rubocop/cop/gem_fetcher.rb | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'rubocop/cop') 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 -- cgit v1.2.3