diff options
author | Robert Speicher <robert@gitlab.com> | 2017-01-31 20:52:57 +0300 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2017-01-31 20:52:57 +0300 |
commit | 2c358b4b5613d6d398533dc559674da14de3c0d7 (patch) | |
tree | 3308849ac88d65ddff01dc6b1f49453a33e8fd51 | |
parent | d4246054b4604a4494b60fee9ca3235a3e659d05 (diff) | |
parent | 78a3bba62e41831a1b4d994d040a0f8327a3e173 (diff) |
Merge branch 'cop-gem-fetcher' into 'master'
Cop for gem fetched from a git source
Closes #27311
See merge request !8856
-rw-r--r-- | changelogs/unreleased/cop-gem-fetcher.yml | 4 | ||||
-rw-r--r-- | rubocop/cop/gem_fetcher.rb | 28 | ||||
-rw-r--r-- | rubocop/rubocop.rb | 1 |
3 files changed, 33 insertions, 0 deletions
diff --git a/changelogs/unreleased/cop-gem-fetcher.yml b/changelogs/unreleased/cop-gem-fetcher.yml new file mode 100644 index 00000000000..506815a5b54 --- /dev/null +++ b/changelogs/unreleased/cop-gem-fetcher.yml @@ -0,0 +1,4 @@ +--- +title: Cop for gem fetched from a git source +merge_request: 8856 +author: Adam Pahlevi diff --git a/rubocop/cop/gem_fetcher.rb b/rubocop/cop/gem_fetcher.rb new file mode 100644 index 00000000000..4a63c760744 --- /dev/null +++ b/rubocop/cop/gem_fetcher.rb @@ -0,0 +1,28 @@ +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. + 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") + + 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 + if GIT_KEYS.include?(key_name) + add_offense(node, :selector) + end + end + end + end + end +end diff --git a/rubocop/rubocop.rb b/rubocop/rubocop.rb index 7922e19768b..7f20754ee51 100644 --- a/rubocop/rubocop.rb +++ b/rubocop/rubocop.rb @@ -1,3 +1,4 @@ require_relative 'migration_helpers' require_relative 'cop/migration/add_index' require_relative 'cop/migration/column_with_default' +require_relative 'cop/gem_fetcher' |