Skip to content

Commit

Permalink
chore: more idiomatic code (#212)
Browse files Browse the repository at this point in the history
Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
  • Loading branch information
testwill committed May 12, 2023
1 parent ee0b98b commit 13245e0
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
6 changes: 3 additions & 3 deletions reporter/reporter.go
Expand Up @@ -17,7 +17,7 @@ import (
// io.Writer, and outputs to the io.Writer a tabulated count of
// the number of Files for each unique LicenseConcluded in the set.
func Generate(pkg *spdx.Package, w io.Writer) error {
if pkg.FilesAnalyzed == false {
if !pkg.FilesAnalyzed {
return fmt.Errorf("Package FilesAnalyzed is false")
}
totalFound, totalNotFound, foundCounts := countLicenses(pkg)
Expand All @@ -29,10 +29,10 @@ func Generate(pkg *spdx.Package, w io.Writer) error {
fmt.Fprintf(wr, "%d\t TOTAL\n", totalFound+totalNotFound)
fmt.Fprintf(wr, "\n")

counts := []struct {
var counts []struct {
lic string
count int
}{}
}
for k, v := range foundCounts {
var entry struct {
lic string
Expand Down
8 changes: 4 additions & 4 deletions spdx/v2/v2_1/tagvalue/writer/save_package.go
Expand Up @@ -42,14 +42,14 @@ func renderPackage(pkg *spdx.Package, w io.Writer) error {
if pkg.PackageDownloadLocation != "" {
fmt.Fprintf(w, "PackageDownloadLocation: %s\n", pkg.PackageDownloadLocation)
}
if pkg.FilesAnalyzed == true {
if pkg.IsFilesAnalyzedTagPresent == true {
if pkg.FilesAnalyzed {
if pkg.IsFilesAnalyzedTagPresent {
fmt.Fprintf(w, "FilesAnalyzed: true\n")
}
} else {
fmt.Fprintf(w, "FilesAnalyzed: false\n")
}
if pkg.PackageVerificationCode.Value != "" && pkg.FilesAnalyzed == true {
if pkg.PackageVerificationCode.Value != "" && pkg.FilesAnalyzed {
if len(pkg.PackageVerificationCode.ExcludedFiles) == 0 {
fmt.Fprintf(w, "PackageVerificationCode: %s\n", pkg.PackageVerificationCode.Value)
} else {
Expand All @@ -70,7 +70,7 @@ func renderPackage(pkg *spdx.Package, w io.Writer) error {
if pkg.PackageLicenseConcluded != "" {
fmt.Fprintf(w, "PackageLicenseConcluded: %s\n", pkg.PackageLicenseConcluded)
}
if pkg.FilesAnalyzed == true {
if pkg.FilesAnalyzed {
for _, s := range pkg.PackageLicenseInfoFromFiles {
fmt.Fprintf(w, "PackageLicenseInfoFromFiles: %s\n", s)
}
Expand Down
2 changes: 1 addition & 1 deletion spdx/v2/v2_2/rdf/reader/license_utils.go
Expand Up @@ -71,7 +71,7 @@ func getAlgorithmFromURI(algorithmURI string) (checksumAlgorithm string, err err
// from a list of licenses, it returns a
// list of string representation of those licenses.
func mapLicensesToStrings(licences []AnyLicenseInfo) []string {
res := make([]string, len(licences), len(licences))
res := make([]string, len(licences))
for i, lic := range licences {
res[i] = lic.ToLicenseString()
}
Expand Down
3 changes: 3 additions & 0 deletions spdx/v2/v2_2/rdf/reader/parse_snippet_info.go
Expand Up @@ -34,6 +34,9 @@ func (parser *rdfParser2_2) getSnippetInformationFromNode2_2(node *gordfParser.N
return nil, err
}
docElemID, err := ExtractDocElementID(getLastPartOfURI(siTriple.Object.ID))
if err != nil {
return nil, err
}
si.SnippetFromFileSPDXIdentifier = docElemID.ElementRefID
case SPDX_RANGE:
// cardinality: min 1
Expand Down
8 changes: 4 additions & 4 deletions spdx/v2/v2_2/tagvalue/writer/save_package.go
Expand Up @@ -42,14 +42,14 @@ func renderPackage(pkg *spdx.Package, w io.Writer) error {
if pkg.PackageDownloadLocation != "" {
fmt.Fprintf(w, "PackageDownloadLocation: %s\n", pkg.PackageDownloadLocation)
}
if pkg.FilesAnalyzed == true {
if pkg.IsFilesAnalyzedTagPresent == true {
if pkg.FilesAnalyzed {
if pkg.IsFilesAnalyzedTagPresent {
fmt.Fprintf(w, "FilesAnalyzed: true\n")
}
} else {
fmt.Fprintf(w, "FilesAnalyzed: false\n")
}
if pkg.PackageVerificationCode.Value != "" && pkg.FilesAnalyzed == true {
if pkg.PackageVerificationCode.Value != "" && pkg.FilesAnalyzed {
if len(pkg.PackageVerificationCode.ExcludedFiles) == 0 {
fmt.Fprintf(w, "PackageVerificationCode: %s\n", pkg.PackageVerificationCode.Value)
} else {
Expand All @@ -70,7 +70,7 @@ func renderPackage(pkg *spdx.Package, w io.Writer) error {
if pkg.PackageLicenseConcluded != "" {
fmt.Fprintf(w, "PackageLicenseConcluded: %s\n", pkg.PackageLicenseConcluded)
}
if pkg.FilesAnalyzed == true {
if pkg.FilesAnalyzed {
for _, s := range pkg.PackageLicenseInfoFromFiles {
fmt.Fprintf(w, "PackageLicenseInfoFromFiles: %s\n", s)
}
Expand Down
2 changes: 1 addition & 1 deletion spdx/v2/v2_3/rdf/reader/license_utils.go
Expand Up @@ -71,7 +71,7 @@ func getAlgorithmFromURI(algorithmURI string) (checksumAlgorithm string, err err
// from a list of licenses, it returns a
// list of string representation of those licenses.
func mapLicensesToStrings(licences []AnyLicenseInfo) []string {
res := make([]string, len(licences), len(licences))
res := make([]string, len(licences))
for i, lic := range licences {
res[i] = lic.ToLicenseString()
}
Expand Down
6 changes: 3 additions & 3 deletions spdx/v2/v2_3/tagvalue/writer/save_package.go
Expand Up @@ -54,8 +54,8 @@ func renderPackage(pkg *spdx.Package, w io.Writer) error {
if pkg.ValidUntilDate != "" {
fmt.Fprintf(w, "ValidUntilDate: %s\n", pkg.ValidUntilDate)
}
if pkg.FilesAnalyzed == true {
if pkg.IsFilesAnalyzedTagPresent == true {
if pkg.FilesAnalyzed {
if pkg.IsFilesAnalyzedTagPresent {
fmt.Fprintf(w, "FilesAnalyzed: true\n")
}
} else {
Expand All @@ -82,7 +82,7 @@ func renderPackage(pkg *spdx.Package, w io.Writer) error {
if pkg.PackageLicenseConcluded != "" {
fmt.Fprintf(w, "PackageLicenseConcluded: %s\n", pkg.PackageLicenseConcluded)
}
if pkg.FilesAnalyzed == true {
if pkg.FilesAnalyzed {
for _, s := range pkg.PackageLicenseInfoFromFiles {
fmt.Fprintf(w, "PackageLicenseInfoFromFiles: %s\n", s)
}
Expand Down

0 comments on commit 13245e0

Please sign in to comment.