(r io.Reader)
| 83 | } |
| 84 | |
| 85 | func parseModulesTxtDependencies(r io.Reader) ([]dependency, error) { |
| 86 | var dependencies []dependency |
| 87 | s := bufio.NewScanner(r) |
| 88 | for s.Scan() { |
| 89 | ln := strings.TrimSpace(s.Text()) |
| 90 | if ln == "" { |
| 91 | continue |
| 92 | } |
| 93 | parts := strings.Fields(ln) |
| 94 | if parts[0] != "#" { |
| 95 | continue |
| 96 | } |
| 97 | |
| 98 | // See https://golang.org/ref/mod#go-mod-file-replace for |
| 99 | // syntax on replace directives |
| 100 | var commitOrVersionPart string |
| 101 | if len(parts) == 3 { |
| 102 | commitOrVersionPart = parts[2] |
| 103 | } else if len(parts) == 5 && parts[2] == "=>" { |
| 104 | // replace directive in go.mod without old version |
| 105 | // no need to care since it will has corresponding one with old version |
| 106 | continue |
| 107 | } else if len(parts) == 6 && parts[3] == "=>" { |
| 108 | commitOrVersionPart = parts[5] |
| 109 | } else if (len(parts) == 4 && parts[2] == "=>") || (len(parts) == 5 && parts[3] == "=>") { |
| 110 | // Ignore replace directive which uses filepath |
| 111 | continue |
| 112 | } else { |
| 113 | return nil, fmt.Errorf("%w: %s", errUnknownFormat, ln) |
| 114 | } |
| 115 | commitOrVersion, isSha := getCommitOrVersion(commitOrVersionPart) |
| 116 | if commitOrVersion == "" { |
| 117 | return nil, fmt.Errorf("%w: poorly formatted version in replace section %s", errUnknownFormat, parts[2]) |
| 118 | } |
| 119 | |
| 120 | dependencies = append(dependencies, formatDependency(parts[1], commitOrVersion, isSha)) |
| 121 | } |
| 122 | return dependencies, nil |
| 123 | } |
| 124 | |
| 125 | func parseGoModDependencies(r io.Reader) ([]dependency, error) { |
| 126 | var err error |
no test coverage detected