class RuboCop::Cop::Chef::Sharing::InvalidLicenseString

metadata.rb license field should include a SPDX compliant string or “all right reserved” (not case sensitive)

@example

#### incorrect
license 'Apache 2.0'

#### correct
license 'Apache-2.0'
license 'all rights reserved'

list of valid SPDX.org license strings. To build an array run this ruby: “‘ruby require ’json’ require ‘net/http’ json_data = JSON.parse(Net::HTTP.get(URI(‘raw.githubusercontent.com/spdx/license-list-data/master/json/licenses.json’))) licenses = json_data.map {|l| l }.sort “‘

Constants

COMMON_TYPOS
MSG
RESTRICT_ON_SEND
VALID_LICENSE_STRING

Public Instance Methods

autocorrect_license_string(bad_string) click to toggle source

private

# File lib/rubocop/cop/chef/sharing/invalid_license_string.rb, line 530
def autocorrect_license_string(bad_string)
  COMMON_TYPOS[bad_string.delete(',').downcase.to_sym]
end
on_send(node) click to toggle source
# File lib/rubocop/cop/chef/sharing/invalid_license_string.rb, line 518
def on_send(node)
  license?(node) do |license|
    return if valid_license?(license.str_content)
    add_offense(license, severity: :refactor) do |corrector|
      correct_string = autocorrect_license_string(license.str_content)
      corrector.replace(license, "'#{correct_string}'") if correct_string
    end
  end
end
valid_license?(license) click to toggle source
# File lib/rubocop/cop/chef/sharing/invalid_license_string.rb, line 534
def valid_license?(license)
  VALID_LICENSE_STRING.include?(license) ||
    license.casecmp('all rights reserved') == 0
end