Class: Dependabot::GoModules::GoWorkParser

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/go_modules/go_work_parser.rb

Class Method Summary collapse

Class Method Details

.use_paths(content) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dependabot/go_modules/go_work_parser.rb', line 16

def self.use_paths(content)
  paths = T.let([], T::Array[String])

  # Multi-line use block: use (\n  ./path\n  ...\n)
  content.scan(/^use\s+\(([^)]+)\)/m).each do |block_match|
    T.must(block_match[0]).each_line do |line|
      path = line.split("//").first&.strip || ""
      next if path.empty?

      paths << path.sub(%r{^\./}, "")
    end
  end

  # Single-line use directive: use . or use ./path
  # [^\s]* (zero-or-more) so bare `use .` is captured
  content.scan(/^use\s+(?!\()(\.[^\s]*)/m).each do |match|
    path = T.must(match[0]).sub(%r{^\./}, "")
    paths << path
  end

  paths.uniq
end