Skip to content

Commit

Permalink
fix lints
Browse files Browse the repository at this point in the history
Signed-off-by: cpanato <[email protected]>
  • Loading branch information
cpanato committed Apr 3, 2024
1 parent b3172fe commit cf707d0
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 39 deletions.
29 changes: 0 additions & 29 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,8 @@ linters-settings:
gocritic:
enabled-checks:
# Diagnostic
- appendAssign
- argOrder
- badCond
- caseOrder
- codegenComment
- commentedOutCode
- deprecatedComment
- dupArg
- dupBranchBody
- dupCase
- dupSubExpr
- exitAfterDefer
- flagDeref
- flagName
- nilValReturn
- offBy1
- sloppyReassign
- weakCond
- octalLiteral
Expand All @@ -129,31 +115,16 @@ linters-settings:
- rangeValCopy

# Style
- assignOp
- boolExprSimplify
- captLocal
- commentFormatting
- commentedOutImport
- defaultCaseOrder
- docStub
- elseif
- emptyFallthrough
- emptyStringTest
- hexLiteral
- methodExprCall
- regexpMust
- singleCaseSwitch
- sloppyLen
- stringXbytes
- switchTrue
- typeAssertChain
- typeSwitchVar
- underef
- unlabelStmt
- unlambda
- unslice
- valSwap
- wrapperFunc
- yodaStyleExpr
# - ifElseChain

Expand Down
2 changes: 1 addition & 1 deletion cmd/bom/cmd/document_outline.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ set the --spdx-ids to only output the IDs of the entities.
Use: "outline SPDX_FILE|URL",
SilenceUsage: true,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
if len(args) == 0 {
args = append(args, "")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/bom/cmd/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ for checking files.
SilenceErrors: true,
PersistentPreRunE: initLogging,

RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
for i, arg := range args {
if util.Exists(arg) {
file, err := os.Open(arg)
Expand Down
2 changes: 1 addition & 1 deletion pkg/spdx/implementation.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ func (di *spdxDefaultImplementation) IgnorePatterns(
scanner := bufio.NewScanner(f)
for scanner.Scan() {
s := scanner.Text()
if !strings.HasPrefix(s, "#") && len(strings.TrimSpace(s)) > 0 {
if !strings.HasPrefix(s, "#") && strings.TrimSpace(s) != "" {
logrus.Debugf("Loaded .gitignore pattern: >>%s<<", s)
patterns = append(patterns, gitignore.ParsePattern(s, nil))
}
Expand Down
15 changes: 9 additions & 6 deletions pkg/spdx/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ func OpenDoc(path string) (doc *Document, err error) {
// support reading SBOMs from STDIN
var file *os.File
var isTemp bool
if path == "-" || path == "" {

switch {
case path == "-", path == "":
if path == "" {
fi, err := os.Stdin.Stat()
if err != nil {
Expand All @@ -64,13 +66,13 @@ func OpenDoc(path string) (doc *Document, err error) {
if err != nil {
return nil, fmt.Errorf("reading STDIN: %w", err)
}
} else if isURL(path) {
case isURL(path):
file, err = tempFileFromURL(path)
if err != nil {
return nil, fmt.Errorf("get temp file from url: %w", err)
}
isTemp = true
} else {
default:
file, err = os.Open(path)
if err != nil {
return nil, fmt.Errorf("opening document from %s: %w", path, err)
Expand Down Expand Up @@ -331,17 +333,18 @@ func parseJSON(file *os.File) (doc *Document, err error) {
continue
}

switch {
// Look for the peer element, exception: peer may be
// an external reference
if strings.HasPrefix(relatedID, "DocumentRef-") {
case strings.HasPrefix(relatedID, "DocumentRef-"):
externalID = relatedID
parts := strings.SplitN(relatedID, ":", 2)
if len(parts) != 2 {
logrus.Errorf("Unable to parse external reference %s", relatedID)
continue
}
relatedID = parts[1]
} else if typeID == string(DESCRIBES) && elementID == jsonDoc.GetID() {
case (typeID == string(DESCRIBES) && elementID == jsonDoc.GetID()):
// Handle top-level packages marked by a relationship
if p, ok := allPackages[relatedID]; ok {
doc.Packages[relatedID] = p
Expand All @@ -352,7 +355,7 @@ func parseJSON(file *os.File) (doc *Document, err error) {
continue
}
seenObjects[relatedID] = relatedID
} else {
default:
if _, ok := allPackages[relatedID]; ok {
peer = allPackages[relatedID]
} else if _, ok := allFiles[relatedID]; ok {
Expand Down
2 changes: 1 addition & 1 deletion pkg/spdx/parser_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestDetectSBOMEncoding(t *testing.T) {
Creator: Tool: tern-2.10.1
Created: 2022-07-04T18:43:35Z
DocumentComment: <text>This document was generated by the Tern Project: https://github.com/tern-tools/tern</text>
PackageName: nginx
SPDXID: SPDXRef-nginx-latest
PackageVersion: latest
Expand Down

0 comments on commit cf707d0

Please sign in to comment.