Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code optimization #212

Merged
merged 1 commit into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions reporter/reporter.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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