lib/rubocop/cop/chef/sharing/invalid_license_string.rb in cookstyle-6.15.9 vs lib/rubocop/cop/chef/sharing/invalid_license_string.rb in cookstyle-6.16.4

- old
+ new

@@ -35,11 +35,13 @@ # require 'json' # require 'net/http' # json_data = JSON.parse(Net::HTTP.get(URI('https://raw.githubusercontent.com/spdx/license-list-data/master/json/licenses.json'))) # licenses = json_data['licenses'].map {|l| l['licenseId'] }.sort # - class InvalidLicenseString < Cop + class InvalidLicenseString < Base + extend AutoCorrector + VALID_LICENSE_STRING = %w( 0BSD AAL ADSL AFL-1.1 @@ -459,20 +461,13 @@ def_node_matcher :license?, '(send nil? :license $str ...)' def on_send(node) license?(node) do |license| - unless valid_license?(license.str_content) - add_offense(license, location: :expression, message: MSG, severity: :refactor) - end - end - end - - def autocorrect(node) - correct_string = autocorrect_license_string(node.str_content) - if correct_string - lambda do |corrector| - corrector.replace(node.loc.expression, "'#{correct_string}'") + return if valid_license?(license.str_content) + add_offense(license, message: MSG, severity: :refactor) do |corrector| + correct_string = autocorrect_license_string(license.str_content) + corrector.replace(license.loc.expression, "'#{correct_string}'") if correct_string end end end # private