Helpers shared by the cops in this package. They centralise the parsing of pkg/config/ / paths and pkg/config/vN import paths, so each cop can focus on its rule rather than on regular expressions. versionFromDir parses a "vN" directory name and returns N. Returns false for any other name (latest
(dir string)
| 15 | // versionFromDir parses a "vN" directory name and returns N. Returns false |
| 16 | // for any other name (latest, types, vendor, ...). |
| 17 | func versionFromDir(dir string) (int, bool) { |
| 18 | if len(dir) < 2 || dir[0] != 'v' { |
| 19 | return 0, false |
| 20 | } |
| 21 | n, err := strconv.Atoi(dir[1:]) |
| 22 | if err != nil { |
| 23 | return 0, false |
| 24 | } |
| 25 | return n, true |
| 26 | } |
| 27 | |
| 28 | // versionFromImport returns N if importPath ends with "pkg/config/vN". |
| 29 | // Re-uses [versionFromDir] for the vN suffix, so the two helpers cannot |
no outgoing calls
no test coverage detected