Sha256: fa23cb3299e51a6d96b927d784b549aaeabaebb8d04f29e36e3cb13a22129a29

Contents?: true

Size: 1.1 KB

Versions: 6

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Gitlab
  module Styles
    module Rubocop
      module Cop
        # 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].freeze

          def on_send(node)
            return unless gemfile?(node)

            func_name = node.children[1]
            return unless func_name == :gem

            node.children.last.each_node(:pair) do |pair|
              key_name = pair.children[0].children[0].to_sym
              add_offense(node, location: pair.source_range, message: MSG) if GIT_KEYS.include?(key_name)
            end
          end

          private

          def gemfile?(node)
            node
              .location
              .expression
              .source_buffer
              .name
              .end_with?("Gemfile")
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gitlab-styles-5.0.0 lib/gitlab/styles/rubocop/cop/gem_fetcher.rb
gitlab-styles-4.3.0 lib/gitlab/styles/rubocop/cop/gem_fetcher.rb
gitlab-styles-4.2.0 lib/gitlab/styles/rubocop/cop/gem_fetcher.rb
gitlab-styles-4.1.0 lib/gitlab/styles/rubocop/cop/gem_fetcher.rb
gitlab-styles-4.0.0 lib/gitlab/styles/rubocop/cop/gem_fetcher.rb
gitlab-styles-3.4.0 lib/gitlab/styles/rubocop/cop/gem_fetcher.rb