Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ linters:
govet:
disable:
- composites
staticcheck:
checks:
- all
- -QF1001 # De Morgan's law simplifications
- -QF1008 # Embedded field selector simplifications
- -ST1003 # Naming conventions (ID vs Id, URL vs Url, etc.)
exclusions:
generated: lax
presets:
Expand Down
2 changes: 1 addition & 1 deletion cmd/src/batch_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ func getBatchSpecDirectory(file string) (string, error) {
func checkExecutable(cmd string, args ...string) error {
if err := exec.Command(cmd, args...).Run(); err != nil {
return fmt.Errorf(
"failed to execute \"%s %s\":\n\t%s\n\n'src batch' requires %q to be available.",
"failed to execute \"%s %s\":\n\t%s\n\n'src batch' requires %q to be available",
cmd,
strings.Join(args, " "),
err,
Expand Down
10 changes: 6 additions & 4 deletions cmd/src/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,10 @@ func applyHighlightsForFile(fileContent string, highlights []highlight) string {
for _, highlight := range highlights {
line := lines[highlight.line]
for characterIndex, character := range []rune(line + "\n") {
if characterIndex == highlight.character {
switch characterIndex {
case highlight.character:
result = append(result, []rune(start)...)
} else if characterIndex == highlight.character+highlight.length {
case highlight.character + highlight.length:
result = append(result, []rune(end)...)
}
result = append(result, character)
Expand All @@ -478,9 +479,10 @@ func applyHighlights(input string, highlights []highlight, start, end string) st
for characterIndex, character := range []rune(line + "\n") {
for _, highlight := range highlights {
if highlight.line == lineNumber {
if characterIndex == highlight.character {
switch characterIndex {
case highlight.character:
result = append(result, []rune(start)...)
} else if characterIndex == highlight.character+highlight.length {
case highlight.character + highlight.length:
result = append(result, []rune(end)...)
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/src/signature_fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (c cosignConfig) verifySignatureForImageHash(image string, hash string) err

output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("Signature verification failed: %w\nOutput: %s", err, output)
return fmt.Errorf("signature verification failed: %w\nOutput: %s", err, output)
}

return nil
Expand Down
3 changes: 1 addition & 2 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ func (r *request) do(ctx context.Context, result interface{}) (bool, error) {

// Check trace header before we potentially early exit
if *r.client.opts.Flags.trace {
_, err := r.client.opts.Out.Write([]byte(fmt.Sprintf("x-trace: %s\n", resp.Header.Get("x-trace"))))
if err != nil {
if _, err := fmt.Fprintf(r.client.opts.Out, "x-trace: %s\n", resp.Header.Get("x-trace")); err != nil {
return false, err
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/api/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ func applyProxy(transport *http.Transport, proxyURL *url.URL, proxyPath string)
transport.Proxy = nil
proxyApplied = true
} else if proxyURL != nil {
if proxyURL.Scheme == "socks5" ||
proxyURL.Scheme == "socks5h" {
switch proxyURL.Scheme {
case "socks5", "socks5h":
// SOCKS proxies work out of the box - no need to manually dial
transport.Proxy = http.ProxyURL(proxyURL)
proxyApplied = true
} else if proxyURL.Scheme == "http" || proxyURL.Scheme == "https" {
case "http", "https":
dial := func(ctx context.Context, network, addr string) (net.Conn, error) {
// Dial the proxy
d := net.Dialer{}
Expand Down
1 change: 0 additions & 1 deletion internal/batches/debug.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build debug
// +build debug

package batches

Expand Down
2 changes: 1 addition & 1 deletion internal/batches/docker/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func CheckVersion(ctx context.Context) error {
_, err := executeFastCommand(ctx, "version")
if err != nil {
return fmt.Errorf(
"failed to execute \"docker version\":\n\t%s\n\n'src batch' requires \"docker\" to be available.",
"failed to execute \"docker version\":\n\t%s\n\n'src batch' requires \"docker\" to be available",
err,
)
}
Expand Down
5 changes: 2 additions & 3 deletions internal/batches/executor/execution_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@ import (

"github.com/google/go-cmp/cmp"

"github.com/sourcegraph/sourcegraph/lib/batches"
batcheslib "github.com/sourcegraph/sourcegraph/lib/batches"
"github.com/sourcegraph/sourcegraph/lib/batches/execution"
"github.com/sourcegraph/sourcegraph/lib/batches/execution/cache"
"github.com/sourcegraph/sourcegraph/lib/batches/git"
)

var cacheRepo1 = batches.Repository{
var cacheRepo1 = batcheslib.Repository{
ID: "src-cli",
Name: "github.com/sourcegraph/src-cli",
BaseRef: "refs/heads/main",
BaseRev: "d34db33f",
FileMatches: []string{"README.md", "main.go"},
}

var cacheRepo2 = batches.Repository{
var cacheRepo2 = batcheslib.Repository{
ID: "sourcegraph",
Name: "github.com/sourcegraph/sourcegraph",
BaseRef: "refs/heads/main-2",
Expand Down
1 change: 0 additions & 1 deletion internal/batches/workspace/bind_workspace_nonwin_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !windows
// +build !windows

package workspace

Expand Down
7 changes: 4 additions & 3 deletions internal/batches/workspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ const (

func NewCreator(ctx context.Context, preference, cacheDir, tempDir string, images map[string]docker.Image) (Creator, CreatorType) {
var workspaceType CreatorType
if preference == "volume" {
switch preference {
case "volume":
workspaceType = CreatorTypeVolume
} else if preference == "bind" {
case "bind":
workspaceType = CreatorTypeBind
} else {
default:
workspaceType = BestCreatorType(ctx, images)
}

Expand Down
7 changes: 4 additions & 3 deletions internal/validate/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,14 @@ func CurrentContextSetTo(clusterService string) error {
return err
}

if clusterService == "gke" {
switch clusterService {
case "gke":
got := strings.Split(currentContext, "_")[0]
want := clusterService
if got != want {
return errors.New("no gke cluster configured")
}
} else if clusterService == "eks" {
case "eks":
got := strings.Split(currentContext, ":")
want := []string{"arn", "aws", clusterService}

Expand All @@ -399,7 +400,7 @@ func CurrentContextSetTo(clusterService string) error {
return errors.New("no eks cluster configured")
}
}
} else if clusterService == "aks" {
case "aks":
colons := strings.Split(currentContext, ":") // aws string
underscores := strings.Split(currentContext, "_") // gke string

Expand Down
Loading