Class: Rubocop::Cop::GemFetcher

Inherits:
RuboCop::Cop::Base
  • Object
show all
Defined in:
lib/rubocop/cop/gem_fetcher.rb

Overview

Prevents usage of the ‘git` and `github` arguments to `gem` in a `Gemfile` in order to avoid additional points of failure beyond rubygems.org.

Constant Summary collapse

MSG =
'Do not use gems from git repositories, only use gems from RubyGems or vendored gems. ' \
'See https://docs.gitlab.com/ee/development/gemfile.html#no-gems-fetched-from-git-repositories'
GIT_SOURCES =
%i[git github gist bitbucket].freeze
RESTRICT_ON_SEND =
%i[gem].freeze

Instance Method Summary collapse

Instance Method Details

#gem_option(node) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/rubocop/cop/gem_fetcher.rb', line 16

def_node_matcher :gem_option, <<~PATTERN
  (send nil? :gem _ ...
    (hash
      <$(pair (sym {#{GIT_SOURCES.map(&:inspect).join(' ')}}) _)
      ...>
    )
  )
PATTERN

#on_send(node) ⇒ Object



27
28
29
30
31
32
# File 'lib/rubocop/cop/gem_fetcher.rb', line 27

def on_send(node)
  pair_node = gem_option(node)
  return unless pair_node

  add_offense(pair_node)
end