Class: RuboCop::Cop::Chef::Modernize::LegacyBerksfileSource

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/chef/modernize/berksfile_source.rb

Overview

There have been many different valid community site / Supermarket URLs to use in a cookbook’s Berksfile. These old URLs continue to function via redirects, but should be updated to point to the latest Supermarket URL.

Examples:


### incorrect
source 'http://community.opscode.com/api/v3'
source 'https://supermarket.getchef.com'
source 'https://api.berkshelf.com'
site :opscode

### correct
source 'https://supermarket.chef.io'

Constant Summary collapse

MSG =
'Do not use legacy Berksfile community sources. Use Chef Supermarket instead.'
RESTRICT_ON_SEND =
[:source, :site].freeze

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#old_berkshelf_url?(url) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/rubocop/cop/chef/modernize/berksfile_source.rb', line 49

def old_berkshelf_url?(url)
  %w(http://community.opscode.com/api/v3 https://supermarket.getchef.com https://api.berkshelf.com).include?(url)
end

#on_send(node) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rubocop/cop/chef/modernize/berksfile_source.rb', line 53

def on_send(node)
  berksfile_source?(node) do
    add_offense(node, severity: :refactor) do |corrector|
      corrector.replace(node, "source 'https://supermarket.chef.io'")
    end
  end

  berksfile_site?(node) do
    add_offense(node, severity: :refactor) do |corrector|
      corrector.replace(node, "source 'https://supermarket.chef.io'")
    end
  end
end