diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..366252d --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,5 @@ +version: "2" + +formatters: + enable: + - gofmt diff --git a/ecosystem.go b/ecosystem.go index a052faf..acdc0f7 100644 --- a/ecosystem.go +++ b/ecosystem.go @@ -16,9 +16,9 @@ var purlTypeForEcosystem = map[string]string{ // ecosystemAliases maps alternate names to canonical ecosystem names. var ecosystemAliases = map[string]string{ - "go": "golang", - "gem": "rubygems", - "composer": "packagist", + "go": "golang", + "gem": "rubygems", + "composer": "packagist", } // osvEcosystemNames maps PURL types to OSV ecosystem names. diff --git a/ecosystem_test.go b/ecosystem_test.go index f32cf54..09e6ba2 100644 --- a/ecosystem_test.go +++ b/ecosystem_test.go @@ -42,9 +42,9 @@ func TestEcosystemToPURLType(t *testing.T) { {"rubygems", "gem"}, {"packagist", "composer"}, {"cargo", "cargo"}, - {"go", "golang"}, // alias normalized first - {"gem", "gem"}, // alias to rubygems, then rubygems -> gem - {"composer", "composer"}, // alias to packagist, then packagist -> composer + {"go", "golang"}, // alias normalized first + {"gem", "gem"}, // alias to rubygems, then rubygems -> gem + {"composer", "composer"}, // alias to packagist, then packagist -> composer {"github-actions", "githubactions"}, {"unknown", "unknown"}, } diff --git a/makepurl_test.go b/makepurl_test.go index 2f9aeea..f9d977e 100644 --- a/makepurl_test.go +++ b/makepurl_test.go @@ -55,7 +55,7 @@ func TestBuildPURLString(t *testing.T) { want string }{ {"simple npm", "npm", "lodash", "4.17.21", "", "pkg:npm/lodash@4.17.21"}, - {"scoped npm", "npm", "@babel/core", "7.20.0", "", "pkg:npm/%40babel/core@7.20.0"}, // @ encoded in namespace + {"scoped npm", "npm", "@babel/core", "7.20.0", "", "pkg:npm/%40babel/core@7.20.0"}, // @ encoded in namespace {"gem", "rubygems", "rails", "7.0.0", "", "pkg:gem/rails@7.0.0"}, {"pypi", "pypi", "requests", "2.28.0", "", "pkg:pypi/requests@2.28.0"}, {"maven", "maven", "org.apache:commons", "1.0", "", "pkg:maven/org.apache/commons@1.0"}, @@ -112,4 +112,3 @@ func TestBuildPURLStringMatchesMakePURL(t *testing.T) { }) } } - diff --git a/registry_test.go b/registry_test.go index 90d729a..5679aa7 100644 --- a/registry_test.go +++ b/registry_test.go @@ -134,10 +134,10 @@ func TestRegistryURLWithVersion(t *testing.T) { func TestParseRegistryURLWithType(t *testing.T) { tests := []struct { - url string - purlType string - wantPURL string - wantErr bool + url string + purlType string + wantPURL string + wantErr bool }{ // npm {"https://www.npmjs.com/package/lodash", "npm", "pkg:npm/lodash", false}, diff --git a/types.go b/types.go index bfb2111..7776524 100644 --- a/types.go +++ b/types.go @@ -21,13 +21,13 @@ type TypeConfig struct { // RegistryConfig contains URL templates and patterns for registry URLs. type RegistryConfig struct { - BaseURL string `json:"base_url"` - ReverseRegex string `json:"reverse_regex"` - URITemplate string `json:"uri_template"` - URITemplateNoNamespace string `json:"uri_template_no_namespace"` - URITemplateWithVersion string `json:"uri_template_with_version"` - URITemplateWithVersionNoNS string `json:"uri_template_with_version_no_namespace"` - Components RegistryComponents `json:"components"` + BaseURL string `json:"base_url"` + ReverseRegex string `json:"reverse_regex"` + URITemplate string `json:"uri_template"` + URITemplateNoNamespace string `json:"uri_template_no_namespace"` + URITemplateWithVersion string `json:"uri_template_with_version"` + URITemplateWithVersionNoNS string `json:"uri_template_with_version_no_namespace"` + Components RegistryComponents `json:"components"` } // RegistryComponents describes which PURL components are used in registry URLs. diff --git a/types_test.go b/types_test.go index 0e6ffee..b74ed5c 100644 --- a/types_test.go +++ b/types_test.go @@ -24,20 +24,19 @@ func TestTypeInfo(t *testing.T) { if cfg != nil { t.Errorf("TypeInfo(%q) = %v, want nil", tt.purlType, cfg) } - return - } - if cfg == nil { - t.Fatalf("TypeInfo(%q) = nil, want non-nil", tt.purlType) - } - if cfg.Description != tt.wantDescription { - t.Errorf("Description = %q, want %q", cfg.Description, tt.wantDescription) - } - if cfg.DefaultRegistry == nil { - if tt.wantRegistry != "" { - t.Errorf("DefaultRegistry = nil, want %q", tt.wantRegistry) + } else if cfg == nil { + t.Errorf("TypeInfo(%q) = nil, want non-nil", tt.purlType) + } else { + if cfg.Description != tt.wantDescription { + t.Errorf("Description = %q, want %q", cfg.Description, tt.wantDescription) + } + if cfg.DefaultRegistry == nil { + if tt.wantRegistry != "" { + t.Errorf("DefaultRegistry = nil, want %q", tt.wantRegistry) + } + } else if *cfg.DefaultRegistry != tt.wantRegistry { + t.Errorf("DefaultRegistry = %q, want %q", *cfg.DefaultRegistry, tt.wantRegistry) } - } else if *cfg.DefaultRegistry != tt.wantRegistry { - t.Errorf("DefaultRegistry = %q, want %q", *cfg.DefaultRegistry, tt.wantRegistry) } }) } @@ -102,8 +101,8 @@ func TestDefaultRegistry(t *testing.T) { {"npm", "https://registry.npmjs.org"}, {"pypi", "https://pypi.org"}, {"cargo", "https://crates.io"}, - {"apk", ""}, // no default registry - {"deb", ""}, // no default registry + {"apk", ""}, // no default registry + {"deb", ""}, // no default registry {"unknown", ""}, } @@ -118,15 +117,15 @@ func TestDefaultRegistry(t *testing.T) { func TestNamespaceRequirement(t *testing.T) { tests := []struct { - purlType string - wantRequired bool - wantProhibited bool + purlType string + wantRequired bool + wantProhibited bool }{ {"maven", true, false}, {"composer", true, false}, {"gem", false, true}, {"cran", false, true}, - {"npm", false, false}, // optional + {"npm", false, false}, // optional {"cargo", false, false}, // no requirement }