Class: GemXray::Analyzers::RedundantAnalyzer

Inherits:
Base
  • Object
show all
Defined in:
lib/gemxray/analyzers/redundant_analyzer.rb

Constant Summary

Constants inherited from Base

Base::AUTOLOADED_GEMS

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from GemXray::Analyzers::Base

Instance Method Details

#analyze(gems) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gemxray/analyzers/redundant_analyzer.rb', line 6

def analyze(gems)
  gem_names = gems.map(&:name)

  gems.filter_map do |gem_entry|
    next if skipped?(gem_entry)

    path = dependency_resolver.find_parent(
      target: gem_entry.name,
      roots: gem_names - [gem_entry.name],
      max_depth: config.redundant_depth
    )
    next unless path
    next unless compatible_dependency?(gem_entry, path[:edges].last)

    detail = "already installed as a dependency of #{path[:gems].first}"
    detail = "#{detail} (#{path[:gems].join(' -> ')})" if path[:gems].length > 2

    result = build_result(
      gem_entry: gem_entry,
      type: :redundant,
      severity: gem_entry.pinned_version? ? :info : :warning,
      detail: detail
    )

    if gem_entry.pinned_version?
      result.add_reason(
        type: :redundant,
        severity: :info,
        detail: "version is pinned in Gemfile (#{gem_entry.version}), so this may be intentional"
      )
    end

    result
  end
end