class Danger::DangerWCC::YarnDeduplicate
Constants
- DEDUPE_REGEXP
rubocop:disable Layout/LineLength
- DEFAULT_OPTIONS
Public Class Methods
new(plugin, options = {})
click to toggle source
# File lib/wcc/yarn_deduplicate.rb, line 19 def initialize(plugin, options = {}) @plugin = plugin @options = DEFAULT_OPTIONS.merge(options) end
Public Instance Methods
perform()
click to toggle source
# File lib/wcc/yarn_deduplicate.rb, line 24 def perform diff = run_yarn_deduplicate_diff each_addition_in_diff(diff) do |line| add_deduplicate_warning(line) end end
yarn_info()
click to toggle source
# File lib/wcc/yarn_deduplicate.rb, line 14 def yarn_info @yarn_info ||= Danger::DangerWCC::Util::YarnInfo.new(self, @options) end
Private Instance Methods
add_deduplicate_warning(line)
click to toggle source
rubocop:enable Layout/LineLength
# File lib/wcc/yarn_deduplicate.rb, line 47 def add_deduplicate_warning(line) # rubocop:disable Metrics/MethodLength warning = line.content.match(DEDUPE_REGEXP) return unless warning pkg, _semver, wanted, got = warning.captures idx = yarn_info.find_index_in_lockfile( pkg, got ) msg = <<~HEREDOC You have an opportunity to deduplicate "#{pkg}". It's using #{got} but could use the existing version #{wanted}. You can fix this by running : `npx yarn-deduplicate -s fewer --packages "#{pkg}"` HEREDOC plugin.public_send(@options[:severity], msg, file: @options[:lockfile], line: idx) end
run_yarn_deduplicate_diff()
click to toggle source
# File lib/wcc/yarn_deduplicate.rb, line 34 def run_yarn_deduplicate_diff diff = run_and_diff do run('npx yarn-deduplicate -s fewer --list '\ "#{@options[:lockfile]}") end GitDiff.from_string(diff) end