Skip to content

Commit

Permalink
Turn on most gocritic lints (#1217)
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex authored Feb 7, 2024
1 parent 151bb10 commit eb7dc78
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 22 deletions.
14 changes: 14 additions & 0 deletions flow/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,22 @@ linters-settings:
- 'prefix(github.com/PeerDB-io)'
- default
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- ifElseChain
- importShadow
- paramTypeCombine
- sprintfQuotedString
- unnamedResult
- whyNoLint
settings:
hugeParam:
sizeThreshold: 512
stylecheck:
checks:
- all
Expand Down
2 changes: 1 addition & 1 deletion flow/cmd/mirror_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func (h *FlowRequestHandler) isCDCFlow(ctx context.Context, flowJobName string)
return false, fmt.Errorf("unable to query flow: %w", err)
}

if !query.Valid || len(query.String) == 0 {
if !query.Valid || query.String == "" {
return true, nil
}

Expand Down
2 changes: 1 addition & 1 deletion flow/cmd/validate_peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (h *FlowRequestHandler) ValidatePeer(
}, nil
}

if len(req.Peer.Name) == 0 {
if req.Peer.Name == "" {
return &protos.ValidatePeerResponse{
Status: protos.ValidatePeerStatus_INVALID,
Message: "no peer name provided",
Expand Down
3 changes: 0 additions & 3 deletions flow/connectors/clickhouse/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ func (c *ClickhouseConnector) NormalizeRecords(req *model.NormalizeRecordsReques
ct := column.Type

colSelector.WriteString(fmt.Sprintf("%s,", cn))
// if i < numCols-1 {
// colSelector.WriteString(",")
// }

extractionFuction := "JSONExtractRaw"
switch qvalue.QValueKind(ct) {
Expand Down
19 changes: 6 additions & 13 deletions flow/connectors/postgres/qrep_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ func newTestCaseForCTID(schema string, name string, rows uint32, expectedNum int
}

func TestGetQRepPartitions(t *testing.T) {
// log.SetLevel(log.DebugLevel)

const connStr = "postgres://postgres:postgres@localhost:7132/postgres"

// Setup the DB
Expand Down Expand Up @@ -222,23 +220,18 @@ func prepareTestData(t *testing.T, pool *pgx.Conn, schema string) int {

// Define the start and end times
startTime := time.Date(2010, time.January, 1, 10, 0, 0, 0, time.UTC)
endTime := time.Date(2010, time.January, 30, 10, 0, 0, 0, time.UTC)

// Prepare the time range
var times []time.Time
for t := startTime; !t.After(endTime); t = t.Add(24 * time.Hour) {
times = append(times, t)
}
endTime := time.Date(2010, time.January, 31, 10, 0, 0, 0, time.UTC)

// Insert the test data
for i, time := range times {
times := 0
for tm := startTime; tm.Before(endTime); tm = tm.Add(24 * time.Hour) {
times += 1
_, err := pool.Exec(context.Background(), fmt.Sprintf(`
INSERT INTO %s.test (value, "from") VALUES ($1, $2)
`, schema), i+1, time)
`, schema), times, tm)
if err != nil {
t.Fatalf("Failed to insert test data: %v", err)
}
}

return len(times)
return times
}
1 change: 0 additions & 1 deletion flow/connectors/postgres/qvalue_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ func parseFieldFromQValueKind(qvalueKind qvalue.QValueKind, value interface{}) (
Value: fmt.Sprintf("POINT(%f %f)", xCoord, yCoord),
}
default:
// log.Warnf("unhandled QValueKind => %v, parsing as string", qvalueKind)
textVal, ok := value.(string)
if !ok {
return qvalue.QValue{}, fmt.Errorf("failed to parse value %v into QValueKind %v", value, qvalueKind)
Expand Down
4 changes: 2 additions & 2 deletions flow/workflows/qrep_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,12 +468,12 @@ func QRepFlowWorkflow(
}

logger.Info("partitions to replicate - ", len(partitions.Partitions))
if err = q.processPartitions(ctx, maxParallelWorkers, partitions.Partitions); err != nil {
if err := q.processPartitions(ctx, maxParallelWorkers, partitions.Partitions); err != nil {
return err
}

logger.Info("consolidating partitions for peer flow - ", slog.String("flowName", config.FlowJobName))
if err = q.consolidatePartitions(ctx); err != nil {
if err := q.consolidatePartitions(ctx); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion flow/workflows/xmin_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func XminFlowWorkflow(
return fmt.Errorf("xmin replication failed: %w", err)
}

if err = q.consolidatePartitions(ctx); err != nil {
if err := q.consolidatePartitions(ctx); err != nil {
return err
}

Expand Down

0 comments on commit eb7dc78

Please sign in to comment.