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

refactor: remove unused functions and variables #499

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ linters:
- thelper
- unconvert
# - unparam
# - unused
- unused
# - usestdlibvars
- wastedassign
- whitespace
Expand Down
15 changes: 0 additions & 15 deletions artifact/image/layerscanning/image/layer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,21 +585,6 @@ func TestChainFSReadDir(t *testing.T) {
// CHAINLAYER TESTING HELPER METHODS
// ========================================================

func checkError(t *testing.T, funcName string, gotErr error, wantErr error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@another-rex do we need these for layer extraction?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I don't think so, and I think we would want to use cmp.Diff instead anyway I believe.

t.Helper()
if wantErr != nil {
if !errors.Is(gotErr, wantErr) {
t.Fatalf("%s returned error: %v, want error: %v", funcName, gotErr, wantErr)
}
return
}

if gotErr != nil {
t.Fatalf("%s returned error: %v", funcName, gotErr)
return
}
}

func setUpEmptyChainFS(t *testing.T) FS {
t.Helper()

Expand Down
21 changes: 0 additions & 21 deletions binary/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,19 +224,6 @@ func validateImagePlatform(imagePlatform string) error {
return nil
}

func validateSPDXCreators(creators string) error {
if len(creators) == 0 {
return nil
}
for _, item := range strings.Split(creators, ",") {
c := strings.Split(item, ":")
if len(c) != 2 {
return fmt.Errorf("invalid spdx-creators format, should follow a format like --spdx-creators=Tool:SCALIBR,Organization:Google")
}
}
return nil
}

func validateMultiStringArg(arg []string) error {
if len(arg) == 0 {
return nil
Expand Down Expand Up @@ -594,11 +581,3 @@ func (f *Flags) dirsToSkip(scanRoots []*scalibrfs.ScanRoot) []string {
}
return result
}

func keys(m map[string][]string) []string {
ret := make([]string, 0, len(m))
for k := range m {
ret = append(ret, k)
}
return ret
}
25 changes: 0 additions & 25 deletions detector/cve/cve202338408/semantic/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,9 @@
package semantic

import (
"fmt"
"math/big"
)

func convertToBigIntOrPanic(str string) *big.Int {
if num, isNumber := convertToBigInt(str); isNumber {
return num
}

panic(fmt.Sprintf("failed to convert %s to a number", str))
}

func convertToBigInt(str string) (*big.Int, bool) {
i, ok := new(big.Int).SetString(str, 10)

Expand All @@ -40,19 +31,3 @@ func minInt(x, y int) int {

return x
}

func maxInt(x, y int) int {
if x < y {
return y
}

return x
}

func fetch(slice []string, i int, def string) string {
if len(slice) <= i {
return def
}

return slice[i]
}
16 changes: 0 additions & 16 deletions extractor/filesystem/language/javascript/yarnlock/yarnlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,6 @@ var (
// Format for yarn.lock v1: `resolved "git+ssh://[email protected]:G-Rath/repo-2#hash"`
// Format for yarn.lock v2: `resolution: "@my-scope/my-first-package@https://github.com/my-org/my-first-package.git#commit=hash"`
yarnPackageResolutionRe = regexp.MustCompile(`^ {2}"?(?:resolution:|resolved)"? "([^ '"]+)"$`)
// Regexes for matching commit hashes in the resolution.
commitMatchers = []*regexp.Regexp{
// ssh://...
// git://...
// git+ssh://...
// git+https://...
regexp.MustCompile(`(?:^|.+@)(?:git(?:\+(?:ssh|https))?|ssh)://.+#(\w+)$`),
// https://....git/...
regexp.MustCompile(`(?:^|.+@)https://.+\.git#(\w+)$`),
regexp.MustCompile(`https://codeload\.github\.com(?:/[\w-.]+){2}/tar\.gz/(\w+)$`),
regexp.MustCompile(`.+#commit[:=](\w+)$`),
// github:...
// gitlab:...
// bitbucket:...
regexp.MustCompile(`^(?:github|gitlab|bitbucket):.+#(\w+)$`),
}
)

func shouldSkipYarnLine(line string) bool {
Expand Down
12 changes: 0 additions & 12 deletions extractor/filesystem/language/python/setup/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,15 +390,3 @@ func TestToPURL(t *testing.T) {
t.Errorf("ToPURL(%v) (-want +got):\n%s", i, diff)
}
}

func defaultConfigWith(cfg setup.Config) setup.Config {
newCfg := setup.DefaultConfig()

if cfg.MaxFileSizeBytes > 0 {
newCfg.MaxFileSizeBytes = cfg.MaxFileSizeBytes
}
if cfg.Stats != nil {
newCfg.Stats = cfg.Stats
}
return newCfg
}
7 changes: 2 additions & 5 deletions internal/guidedremediation/manifest/maven/pomxml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ import (
)

var (
depMgmt = depTypeWithOrigin("management")
depParent = depTypeWithOrigin("parent")
depPlugin = depTypeWithOrigin("[email protected]:plugin")
depProfileOne = depTypeWithOrigin("profile@profile-one")
depProfileTwoMgmt = depTypeWithOrigin("profile@profile-two@management")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these will be needed when we gradually migrate guided remediation, but we can add them back anyway, so I am fine with removing them. for other changes, I will let @erikvarga to take a look.

depMgmt = depTypeWithOrigin("management")
depParent = depTypeWithOrigin("parent")
)

func depTypeWithOrigin(origin string) dep.Type {
Expand Down
9 changes: 0 additions & 9 deletions scalibr.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,6 @@ func newScanResult(o *newScanResultOptions) *ScanResult {
return r
}

func hasFailedPlugins(statuses []*plugin.Status) bool {
for _, s := range statuses {
if s.Status.Status != plugin.ScanStatusSucceeded {
return true
}
}
return false
}

// sortResults sorts the result to make the output deterministic and diffable.
func sortResults(results *ScanResult) {
for _, inventory := range results.Inventories {
Expand Down