Skip to content

Commit 7e0ceec

Browse files
committed
fix more linting rules
1 parent d9b665c commit 7e0ceec

File tree

13 files changed

+25
-50
lines changed

13 files changed

+25
-50
lines changed

cli/remoteforward.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func validateRemoteForward(flag string) bool {
4040
return isRemoteForwardTCP(flag) || isRemoteForwardUnixSocket(flag)
4141
}
4242

43-
func parseRemoteForwardTCP(matches []string) (net.Addr, net.Addr, error) {
43+
func parseRemoteForwardTCP(matches []string) (local net.Addr, remote net.Addr, err error) {
4444
remotePort, err := strconv.Atoi(matches[1])
4545
if err != nil {
4646
return nil, nil, xerrors.Errorf("remote port is invalid: %w", err)
@@ -69,7 +69,7 @@ func parseRemoteForwardTCP(matches []string) (net.Addr, net.Addr, error) {
6969
// parseRemoteForwardUnixSocket parses a remote forward flag. Note that
7070
// we don't verify that the local socket path exists because the user
7171
// may create it later. This behavior matches OpenSSH.
72-
func parseRemoteForwardUnixSocket(matches []string) (net.Addr, net.Addr, error) {
72+
func parseRemoteForwardUnixSocket(matches []string) (local net.Addr, remote net.Addr, err error) {
7373
remoteSocket := matches[1]
7474
localSocket := matches[2]
7575

@@ -85,7 +85,7 @@ func parseRemoteForwardUnixSocket(matches []string) (net.Addr, net.Addr, error)
8585
return localAddr, remoteAddr, nil
8686
}
8787

88-
func parseRemoteForward(flag string) (net.Addr, net.Addr, error) {
88+
func parseRemoteForward(flag string) (local net.Addr, remote net.Addr, err error) {
8989
tcpMatches := remoteForwardRegexTCP.FindStringSubmatch(flag)
9090

9191
if len(tcpMatches) > 0 {

cli/root.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,14 @@ func (r *RootCmd) RunWithSubcommands(subcommands []*serpent.Command) {
172172
err = exitErr.err
173173
}
174174
if errors.Is(err, cliui.ErrCanceled) {
175-
//nolint:revive
175+
//nolint:revive,gocritic
176176
os.Exit(code)
177177
}
178178
f := PrettyErrorFormatter{w: os.Stderr, verbose: r.verbose}
179179
if err != nil {
180180
f.Format(err)
181181
}
182-
//nolint:revive
182+
//nolint:revive,gocritic
183183
os.Exit(code)
184184
}
185185
}
@@ -891,7 +891,7 @@ func DumpHandler(ctx context.Context, name string) {
891891

892892
done:
893893
if sigStr == "SIGQUIT" {
894-
//nolint:revive
894+
//nolint:revive,gocritic
895895
os.Exit(1)
896896
}
897897
}

cmd/coder/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
)
1414

1515
func main() {
16+
panic("hey")
1617
if len(os.Args) > 1 && os.Args[1] == "agent-exec" {
1718
err := agentexec.CLI()
1819
_, _ = fmt.Fprintln(os.Stderr, err)

coderd/database/dbauthz/dbauthz.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1663,8 +1663,8 @@ func (q *querier) GetDeploymentWorkspaceStats(ctx context.Context) (database.Get
16631663
return q.db.GetDeploymentWorkspaceStats(ctx)
16641664
}
16651665

1666-
func (q *querier) GetEligibleProvisionerDaemonsByProvisionerJobIDs(ctx context.Context, provisionerJobIds []uuid.UUID) ([]database.GetEligibleProvisionerDaemonsByProvisionerJobIDsRow, error) {
1667-
return fetchWithPostFilter(q.auth, policy.ActionRead, q.db.GetEligibleProvisionerDaemonsByProvisionerJobIDs)(ctx, provisionerJobIds)
1666+
func (q *querier) GetEligibleProvisionerDaemonsByProvisionerJobIDs(ctx context.Context, provisionerJobIDs []uuid.UUID) ([]database.GetEligibleProvisionerDaemonsByProvisionerJobIDsRow, error) {
1667+
return fetchWithPostFilter(q.auth, policy.ActionRead, q.db.GetEligibleProvisionerDaemonsByProvisionerJobIDs)(ctx, provisionerJobIDs)
16681668
}
16691669

16701670
func (q *querier) GetExternalAuthLink(ctx context.Context, arg database.GetExternalAuthLinkParams) (database.ExternalAuthLink, error) {
@@ -3017,11 +3017,11 @@ func (q *querier) GetWorkspaceResourcesCreatedAfter(ctx context.Context, created
30173017
return q.db.GetWorkspaceResourcesCreatedAfter(ctx, createdAt)
30183018
}
30193019

3020-
func (q *querier) GetWorkspaceUniqueOwnerCountByTemplateIDs(ctx context.Context, templateIds []uuid.UUID) ([]database.GetWorkspaceUniqueOwnerCountByTemplateIDsRow, error) {
3020+
func (q *querier) GetWorkspaceUniqueOwnerCountByTemplateIDs(ctx context.Context, templateIDs []uuid.UUID) ([]database.GetWorkspaceUniqueOwnerCountByTemplateIDsRow, error) {
30213021
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceSystem); err != nil {
30223022
return nil, err
30233023
}
3024-
return q.db.GetWorkspaceUniqueOwnerCountByTemplateIDs(ctx, templateIds)
3024+
return q.db.GetWorkspaceUniqueOwnerCountByTemplateIDs(ctx, templateIDs)
30253025
}
30263026

30273027
func (q *querier) GetWorkspaces(ctx context.Context, arg database.GetWorkspacesParams) ([]database.GetWorkspacesRow, error) {

coderd/rbac/regosql/compile.go

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func convertQuery(cfg ConvertConfig, q ast.Body) (sqltypes.BooleanNode, error) {
7878

7979
func convertExpression(cfg ConvertConfig, e *ast.Expr) (sqltypes.BooleanNode, error) {
8080
if e.IsCall() {
81+
//nolint:forcetypeassert
8182
n, err := convertCall(cfg, e.Terms.([]*ast.Term))
8283
if err != nil {
8384
return nil, xerrors.Errorf("call: %w", err)

coderd/util/tz/tz_linux.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TimezoneIANA() (*time.Location, error) {
3535
if err != nil {
3636
return nil, xerrors.Errorf("read location of %s: %w", etcLocaltime, err)
3737
}
38-
stripped := strings.Replace(lp, zoneInfoPath, "", -1)
38+
stripped := strings.ReplaceAll(lp, zoneInfoPath, "")
3939
stripped = strings.TrimPrefix(stripped, string(filepath.Separator))
4040
loc, err = time.LoadLocation(stripped)
4141
if err != nil {

coderd/workspaces_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func TestWorkspace(t *testing.T) {
129129
want = want[:32-5] + "-test"
130130
}
131131
// Sometimes truncated names result in `--test` which is not an allowed name.
132-
want = strings.Replace(want, "--", "-", -1)
132+
want = strings.ReplaceAll(want, "--", "-")
133133
err := client.UpdateWorkspace(ctx, ws1.ID, codersdk.UpdateWorkspaceRequest{
134134
Name: want,
135135
})

helm/provisioner/tests/chart_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func TestRenderChart(t *testing.T) {
160160
require.NoError(t, err, "failed to read golden file %q", goldenFilePath)
161161

162162
// Remove carriage returns to make tests pass on Windows.
163-
goldenBytes = bytes.Replace(goldenBytes, []byte("\r"), []byte(""), -1)
163+
goldenBytes = bytes.ReplaceAll(goldenBytes, []byte("\r"), []byte(""))
164164
expected := string(goldenBytes)
165165

166166
require.NoError(t, err, "failed to load golden file %q")

provisioner/terraform/provision_test.go

-13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"net/http"
1212
"os"
1313
"path/filepath"
14-
"runtime"
1514
"sort"
1615
"strings"
1716
"testing"
@@ -119,10 +118,6 @@ func sendApply(sess proto.DRPCProvisioner_SessionClient, transition proto.Worksp
119118
// one process tries to do this simultaneously, it can cause "text file busy"
120119
// nolint: paralleltest
121120
func TestProvision_Cancel(t *testing.T) {
122-
if runtime.GOOS == "windows" {
123-
t.Skip("This test uses interrupts and is not supported on Windows")
124-
}
125-
126121
cwd, err := os.Getwd()
127122
require.NoError(t, err)
128123
fakeBin := filepath.Join(cwd, "testdata", "fake_cancel.sh")
@@ -215,10 +210,6 @@ func TestProvision_Cancel(t *testing.T) {
215210
// one process tries to do this, it can cause "text file busy"
216211
// nolint: paralleltest
217212
func TestProvision_CancelTimeout(t *testing.T) {
218-
if runtime.GOOS == "windows" {
219-
t.Skip("This test uses interrupts and is not supported on Windows")
220-
}
221-
222213
cwd, err := os.Getwd()
223214
require.NoError(t, err)
224215
fakeBin := filepath.Join(cwd, "testdata", "fake_cancel_hang.sh")
@@ -278,10 +269,6 @@ func TestProvision_CancelTimeout(t *testing.T) {
278269
// terraform-provider-coder
279270
// nolint: paralleltest
280271
func TestProvision_TextFileBusy(t *testing.T) {
281-
if runtime.GOOS == "windows" {
282-
t.Skip("This test uses unix sockets and is not supported on Windows")
283-
}
284-
285272
cwd, err := os.Getwd()
286273
require.NoError(t, err)
287274
fakeBin := filepath.Join(cwd, "testdata", "fake_text_file_busy.sh")

provisioner/terraform/resources_test.go

-13
Original file line numberDiff line numberDiff line change
@@ -1210,27 +1210,16 @@ func TestParameterValidation(t *testing.T) {
12101210
tfPlanGraph, err := os.ReadFile(filepath.Join(dir, "rich-parameters.tfplan.dot"))
12111211
require.NoError(t, err)
12121212

1213-
// Change all names to be identical.
1214-
var names []string
1215-
for _, resource := range tfPlan.PriorState.Values.RootModule.Resources {
1216-
if resource.Type == "coder_parameter" {
1217-
resource.AttributeValues["name"] = "identical"
1218-
names = append(names, resource.Name)
1219-
}
1220-
}
1221-
12221213
state, err := terraform.ConvertState(ctx, []*tfjson.StateModule{tfPlan.PriorState.Values.RootModule}, string(tfPlanGraph), logger)
12231214
require.Nil(t, state)
12241215
require.Error(t, err)
12251216
require.ErrorContains(t, err, "coder_parameter names must be unique but \"identical\" appears multiple times")
12261217

12271218
// Make two sets of identical names.
12281219
count := 0
1229-
names = nil
12301220
for _, resource := range tfPlan.PriorState.Values.RootModule.Resources {
12311221
if resource.Type == "coder_parameter" {
12321222
resource.AttributeValues["name"] = fmt.Sprintf("identical-%d", count%2)
1233-
names = append(names, resource.Name)
12341223
count++
12351224
}
12361225
}
@@ -1242,11 +1231,9 @@ func TestParameterValidation(t *testing.T) {
12421231

12431232
// Once more with three sets.
12441233
count = 0
1245-
names = nil
12461234
for _, resource := range tfPlan.PriorState.Values.RootModule.Resources {
12471235
if resource.Type == "coder_parameter" {
12481236
resource.AttributeValues["name"] = fmt.Sprintf("identical-%d", count%3)
1249-
names = append(names, resource.Name)
12501237
count++
12511238
}
12521239
}

provisioner/terraform/tfparse/tfparse.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ func WriteArchive(bs []byte, mimetype string, path string) error {
279279
return xerrors.Errorf("read zip file: %w", err)
280280
} else if tarBytes, err := archive.CreateTarFromZip(zr, maxFileSizeBytes); err != nil {
281281
return xerrors.Errorf("convert zip to tar: %w", err)
282-
} else {
282+
} else { //nolint:revive
283283
rdr = bytes.NewReader(tarBytes)
284284
}
285285
default:
@@ -558,9 +558,8 @@ func CtyValueString(val cty.Value) (string, error) {
558558
case cty.Bool:
559559
if val.True() {
560560
return "true", nil
561-
} else {
562-
return "false", nil
563561
}
562+
return "false", nil
564563
case cty.Number:
565564
return val.AsBigFloat().String(), nil
566565
case cty.String:

scripts/echoserver/main.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ func main() {
2020
defer l.Close()
2121
tcpAddr, valid := l.Addr().(*net.TCPAddr)
2222
if !valid {
23-
log.Fatal("address is not valid")
23+
log.Panic("address is not valid")
2424
}
2525

2626
remotePort := tcpAddr.Port
2727
_, err = fmt.Println(remotePort)
2828
if err != nil {
29-
log.Fatalf("print error: err=%s", err)
29+
log.Panicf("print error: err=%s", err)
3030
}
3131

3232
for {
3333
conn, err := l.Accept()
3434
if err != nil {
35-
log.Fatalf("accept error, err=%s", err)
35+
log.Panicf("accept error, err=%s", err)
3636
return
3737
}
3838

@@ -43,7 +43,7 @@ func main() {
4343
if errors.Is(err, io.EOF) {
4444
return
4545
} else if err != nil {
46-
log.Fatalf("copy error, err=%s", err)
46+
log.Panicf("copy error, err=%s", err)
4747
}
4848
}()
4949
}

scripts/migrate-test/main.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -82,25 +82,25 @@ func main() {
8282
_, _ = fmt.Fprintf(os.Stderr, "Init database at version %q\n", migrateFromVersion)
8383
if err := migrations.UpWithFS(conn, migrateFromFS); err != nil {
8484
friendlyError(os.Stderr, err, migrateFromVersion, migrateToVersion)
85-
os.Exit(1)
85+
panic("")
8686
}
8787

8888
_, _ = fmt.Fprintf(os.Stderr, "Migrate to version %q\n", migrateToVersion)
8989
if err := migrations.UpWithFS(conn, migrateToFS); err != nil {
9090
friendlyError(os.Stderr, err, migrateFromVersion, migrateToVersion)
91-
os.Exit(1)
91+
panic("")
9292
}
9393

9494
_, _ = fmt.Fprintf(os.Stderr, "Dump schema at version %q\n", migrateToVersion)
9595
dumpBytesAfter, err := dbtestutil.PGDumpSchemaOnly(postgresURL)
9696
if err != nil {
9797
friendlyError(os.Stderr, err, migrateFromVersion, migrateToVersion)
98-
os.Exit(1)
98+
panic("")
9999
}
100100

101101
if diff := cmp.Diff(string(dumpBytesAfter), string(stripGenPreamble(expectedSchemaAfter))); diff != "" {
102102
friendlyError(os.Stderr, xerrors.Errorf("Schema differs from expected after migration: %s", diff), migrateFromVersion, migrateToVersion)
103-
os.Exit(1)
103+
panic("")
104104
}
105105
_, _ = fmt.Fprintf(os.Stderr, "OK\n")
106106
}

0 commit comments

Comments
 (0)