diff options
author | Ryan Beltran <ryanbeltran@chromium.org> | 2023-08-14 20:40:18 +0000 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-08-14 21:44:16 +0000 |
commit | bba5a5cbfedfdac635827b82f02a927224baecee (patch) | |
tree | d4829f2cfcc13dd380e596b42f26501ee1c60dd1 | |
parent | c12ea463f09b850db009f51d44a87b975fd5cd93 (diff) | |
download | toolchain-utils-bba5a5cbfedfdac635827b82f02a927224baecee.tar.gz |
compiler_wrapper: Fix findings from staticcheck
This CL fixes the following staticcheck findings:
clang_tidy_flag.go:235:6: func hasAtLeastOneSuffix is unused (U1000)
command.go:96:13: error strings should not be capitalized (ST1005)
compiler_wrapper.go:97:22: should use time.Since instead of time.Now().Sub (S1012)
compiler_wrapper.go:154:3: this value of cSrcFile is never used (SA4006)
compiler_wrapper.go:187:12: unnecessary use of fmt.Sprintf (S1039)
env.go:148:5: var _env is unused (U1000)
env_test.go:228:2: this value of err is never used (SA4006)
iwyu_flag.go:18:7: const iwyuCrashSubstring is unused (U1000)
BUG=b:295930281
TEST=go test
Change-Id: I3d365243192f9041d12b9c8385d4bd8ff1bd5669
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/4779192
Reviewed-by: George Burgess <gbiv@chromium.org>
Commit-Queue: Ryan Beltran <ryanbeltran@chromium.org>
Tested-by: Ryan Beltran <ryanbeltran@chromium.org>
-rw-r--r-- | compiler_wrapper/clang_tidy_flag.go | 9 | ||||
-rw-r--r-- | compiler_wrapper/command.go | 2 | ||||
-rw-r--r-- | compiler_wrapper/compiler_wrapper.go | 6 | ||||
-rw-r--r-- | compiler_wrapper/env.go | 2 | ||||
-rw-r--r-- | compiler_wrapper/env_test.go | 3 | ||||
-rw-r--r-- | compiler_wrapper/iwyu_flag.go | 2 | ||||
-rw-r--r-- | compiler_wrapper/testutil_test.go | 1 |
7 files changed, 8 insertions, 17 deletions
diff --git a/compiler_wrapper/clang_tidy_flag.go b/compiler_wrapper/clang_tidy_flag.go index e3940825..9722b39e 100644 --- a/compiler_wrapper/clang_tidy_flag.go +++ b/compiler_wrapper/clang_tidy_flag.go @@ -231,12 +231,3 @@ func runClangTidy(env env, clangCmd *command, cSrcFile string, extraTidyFlags [] } return err } - -func hasAtLeastOneSuffix(s string, suffixes []string) bool { - for _, suffix := range suffixes { - if strings.HasSuffix(s, suffix) { - return true - } - } - return false -} diff --git a/compiler_wrapper/command.go b/compiler_wrapper/command.go index e2a5176d..d19c903a 100644 --- a/compiler_wrapper/command.go +++ b/compiler_wrapper/command.go @@ -93,7 +93,7 @@ func resolveAgainstPathEnv(env env, cmd string) (string, error) { return resolvedPath, nil } } - return "", fmt.Errorf("Couldn't find cmd %q in path", cmd) + return "", fmt.Errorf("couldn't find cmd %q in path", cmd) } func getAbsCmdPath(env env, cmd *command) string { diff --git a/compiler_wrapper/compiler_wrapper.go b/compiler_wrapper/compiler_wrapper.go index a299698c..bb144881 100644 --- a/compiler_wrapper/compiler_wrapper.go +++ b/compiler_wrapper/compiler_wrapper.go @@ -94,7 +94,7 @@ func runAndroidClangTidy(env env, cmd *command) error { if !errors.Is(err, context.DeadlineExceeded) { // When used time is over half of TIDY_TIMEOUT, give a warning. // These warnings allow users to fix slow jobs before they get worse. - usedSeconds := int(time.Now().Sub(startTime) / time.Second) + usedSeconds := int(time.Since(startTime) / time.Second) if usedSeconds > seconds/2 { warning := "%s:1:1: warning: clang-tidy used %d seconds.\n" fmt.Fprintf(env.stdout(), warning, getSourceFile(), usedSeconds) @@ -151,7 +151,7 @@ func callCompilerInternal(env env, cfg *config, inputCmd *command) (exitCode int return 0, newErrorwithSourceLocf("unsupported compiler: %s", mainBuilder.target.compiler) } } else { - cSrcFile, tidyFlags, tidyMode := processClangTidyFlags(mainBuilder) + _, tidyFlags, tidyMode := processClangTidyFlags(mainBuilder) cSrcFile, iwyuFlags, iwyuMode := processIWYUFlags(mainBuilder) if mainBuilder.target.compilerType == clangType { err := prepareClangCommand(mainBuilder) @@ -184,7 +184,7 @@ func callCompilerInternal(env env, cfg *config, inputCmd *command) (exitCode int if iwyuMode != iwyuModeNone { if iwyuMode == iwyuModeError { - panic(fmt.Sprintf("Unknown IWYU mode")) + panic("Unknown IWYU mode") } allowCCache = false diff --git a/compiler_wrapper/env.go b/compiler_wrapper/env.go index 2dad6115..38f07cab 100644 --- a/compiler_wrapper/env.go +++ b/compiler_wrapper/env.go @@ -145,7 +145,7 @@ type printingEnv struct { env } -var _env = (*printingEnv)(nil) +var _ env = (*printingEnv)(nil) func (env *printingEnv) exec(cmd *command) error { printCmd(env, cmd) diff --git a/compiler_wrapper/env_test.go b/compiler_wrapper/env_test.go index 6b00a8b5..c10942de 100644 --- a/compiler_wrapper/env_test.go +++ b/compiler_wrapper/env_test.go @@ -226,6 +226,9 @@ func TestNewProcessEnvResolvesPwdAwayProperly(t *testing.T) { os.Unsetenv(envPwd) initialWd, err := os.Getwd() + if err != nil { + t.Fatalf("Failed getting working directory: %v", err) + } if initialWd == "/proc/self/cwd" { t.Fatalf("Working directory should never be %q when env is unset", initialWd) } diff --git a/compiler_wrapper/iwyu_flag.go b/compiler_wrapper/iwyu_flag.go index 6194bf40..5788d8c7 100644 --- a/compiler_wrapper/iwyu_flag.go +++ b/compiler_wrapper/iwyu_flag.go @@ -15,8 +15,6 @@ import ( type useIWYUMode int -const iwyuCrashSubstring = "PLEASE submit a bug report" - const ( iwyuModeNone useIWYUMode = iota iwyuModeAll diff --git a/compiler_wrapper/testutil_test.go b/compiler_wrapper/testutil_test.go index 74e05a63..8bac479b 100644 --- a/compiler_wrapper/testutil_test.go +++ b/compiler_wrapper/testutil_test.go @@ -39,7 +39,6 @@ type testContext struct { tempDir string env []string cfg *config - inputCmd *command lastCmd *command cmdCount int cmdMock func(cmd *command, stdin io.Reader, stdout io.Writer, stderr io.Writer) error |