Skip to content

Commit

Permalink
linter: reconfigure gocritic
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjan committed Mar 20, 2024
1 parent c3bdef6 commit da74f83
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 44 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ jobs:
- name: Configure Windows
if: matrix.os == 'windows-latest'
run: git config --global core.autocrlf false # fixes go lint fmt error
- name: Configure MySQL
if: matrix.os == 'ubuntu-latest'
uses: mirromutth/[email protected]
with:
host port: 3800
mysql version: '8'
mysql root password: test
- name: Checkout
uses: actions/checkout@v3
- name: Setup Go
Expand All @@ -43,6 +36,13 @@ jobs:
autopilot
bus bus/client
worker worker/client
- name: Configure MySQL
if: matrix.os == 'ubuntu-latest'
uses: mirromutth/[email protected]
with:
host port: 3800
mysql version: '8'
mysql root password: test
- name: Test
uses: n8maninger/action-golang-test@v1
with:
Expand Down
86 changes: 61 additions & 25 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ run:
# list of build tags, all linters use it. Default is empty list.
build-tags: []

# which dirs to skip: issues from them won't be reported;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but default dirs are skipped independently
# from this option's value (see skip-dirs-use-default).
skip-dirs:
- cover

# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true
Expand All @@ -37,7 +30,7 @@ run:
# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
format: colored-line-number
formats: colored-line-number

# print lines of code with issue, default is true
print-issued-lines: true
Expand All @@ -61,23 +54,66 @@ linters-settings:
# See https://go-critic.github.io/overview#checks-overview
# To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run`
# By default list of stable checks is used.
enabled-checks:
- argOrder # Diagnostic options
- badCond
- caseOrder
- dupArg
- dupBranchBody
- dupCase
- dupSubExpr
- nilValReturn
- offBy1
- weakCond
- boolExprSimplify # Style options here and below.
- builtinShadow
- emptyFallthrough
- hexLiteral
- underef
- equalFold
enabled-tags:
- diagnostic
- style
disabled-checks:
# diagnostic
- badRegexp
- badSorting
- badSyncOnceFunc
- builtinShadowDecl
- commentedOutCode
- dynamicFmtString
- emptyDecl
- evalOrder
- externalErrorReassign
- filepathJoin
- regexpPattern
- returnAfterHttpError
- sloppyReassign
- sortSlice
- sprintfQuotedString
- sqlQuery
- syncMapLoadAndDelete
- truncateCmp
- uncheckedInlineErr
- unnecessaryDefer

# style
- commentedOutImport
- deferUnlambda
- docStub
- dupImport
- emptyStringTest
- exitAfterDefer
- exposedSyncMutex
- httpNoBody
- ifElseChain
- importShadow
- initClause
- methodExprCall
- nestingReduce
- octalLiteral
- paramTypeCombine
- preferFilepathJoin
- ptrToRefParam
- redundantSprint
- regexpSimplify
- ruleguard
- stringConcatSimplify
- stringsCompare
- timeExprSimplify
- todoCommentWithoutDetail
- tooManyResultsChecker
- typeAssertChain
- typeDefFirst
- typeUnparen
- unlabelStmt
- unnamedResult
- unnecessaryBlock
- whyNoLint
- yodaStyleExpr
revive:
ignore-generated-header: true
rules:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,5 @@ triggers this endpoint after the user updates the configuration, but it can be
useful for debugging purposes too.

- `POST /api/autopilot/trigger`

## TODO: remove me
4 changes: 2 additions & 2 deletions api/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ func (opts SearchObjectOptions) Apply(values url.Values) {
}
}

func FormatETag(ETag string) string {
return fmt.Sprintf("\"%s\"", ETag)
func FormatETag(eTag string) string {
return fmt.Sprintf("\"%s\"", eTag)
}

func ObjectPathEscape(path string) string {
Expand Down
2 changes: 1 addition & 1 deletion autopilot/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (hosts scoredHosts) randSelectByScore(n int) (selected []scoredHost) {
total += h.score
}
for i := range candidates {
candidates[i].score = candidates[i].score / total
candidates[i].score /= total
}

// select
Expand Down
11 changes: 9 additions & 2 deletions internal/test/e2e/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2062,6 +2062,9 @@ func TestMultipartUploads(t *testing.T) {
etag1 := putPart(1, 0, data1)
etag3 := putPart(3, len(data1)+len(data2), data3)
size := int64(len(data1) + len(data2) + len(data3))
expectedData := data1
expectedData = append(expectedData, data2...)
expectedData = append(expectedData, data3...)

// List parts
mup, err := b.MultipartUploadParts(context.Background(), api.DefaultBucketName, objPath, mpr.UploadID, 0, 0)
Expand Down Expand Up @@ -2118,7 +2121,7 @@ func TestMultipartUploads(t *testing.T) {
t.Fatal("unexpected size:", gor.Size)
} else if data, err := io.ReadAll(gor.Content); err != nil {
t.Fatal(err)
} else if expectedData := append(data1, append(data2, data3...)...); !bytes.Equal(data, expectedData) {
} else if !bytes.Equal(data, expectedData) {
t.Fatal("unexpected data:", cmp.Diff(data, expectedData))
}

Expand Down Expand Up @@ -2417,6 +2420,11 @@ func TestMultipartUploadWrappedByPartialSlabs(t *testing.T) {
})
tt.OK(err)

// combine all parts data
expectedData := part1Data
expectedData = append(expectedData, part2Data...)
expectedData = append(expectedData, part3Data...)

// finish the upload
tt.OKAll(b.CompleteMultipartUpload(context.Background(), api.DefaultBucketName, objPath, mpr.UploadID, []api.MultipartCompletedPart{
{
Expand All @@ -2436,7 +2444,6 @@ func TestMultipartUploadWrappedByPartialSlabs(t *testing.T) {
// download the object and verify its integrity
dst := new(bytes.Buffer)
tt.OK(w.DownloadObject(context.Background(), dst, api.DefaultBucketName, objPath, api.DownloadObjectOptions{}))
expectedData := append(part1Data, append(part2Data, part3Data...)...)
receivedData := dst.Bytes()
if len(receivedData) != len(expectedData) {
t.Fatalf("expected %v bytes, got %v", len(expectedData), len(receivedData))
Expand Down
2 changes: 1 addition & 1 deletion stores/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4538,7 +4538,7 @@ func TestTypeCurrency(t *testing.T) {
var result bool
query := fmt.Sprintf("SELECT ? %s ?", test.cmp)
if !isSQLite(ss.db) {
query = strings.Replace(query, "?", "HEX(?)", -1)
query = strings.ReplaceAll(query, "?", "HEX(?)")
}
if err := ss.db.Raw(query, test.a, test.b).Scan(&result).Error; err != nil {
t.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion worker/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func newObjectStoreMock(bucket string) *objectStoreMock {
return os
}

func (os *objectStoreMock) AddMultipartPart(ctx context.Context, bucket, path, contractSet, ETag, uploadID string, partNumber int, slices []object.SlabSlice) (err error) {
func (os *objectStoreMock) AddMultipartPart(ctx context.Context, bucket, path, contractSet, eTag, uploadID string, partNumber int, slices []object.SlabSlice) (err error) {
return nil
}

Expand Down
10 changes: 8 additions & 2 deletions worker/rhpv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,14 @@ func RPCFormContract(ctx context.Context, t *rhpv2.Transport, renterKey types.Pr
return rhpv2.ContractRevision{}, nil, err
}

txn.Signatures = append(renterContractSignatures, hostSigs.ContractSignatures...)
signedTxnSet := append(resp.Parents, append(parents, txn)...)
txn.Signatures = make([]types.TransactionSignature, 0, len(renterContractSignatures)+len(hostSigs.ContractSignatures))
txn.Signatures = append(txn.Signatures, renterContractSignatures...)
txn.Signatures = append(txn.Signatures, hostSigs.ContractSignatures...)

signedTxnSet := make([]types.Transaction, 0, len(resp.Parents)+len(parents)+1)
signedTxnSet = append(signedTxnSet, resp.Parents...)
signedTxnSet = append(signedTxnSet, parents...)
signedTxnSet = append(signedTxnSet, txn)
return rhpv2.ContractRevision{
Revision: initRevision,
Signatures: [2]types.TransactionSignature{
Expand Down
7 changes: 5 additions & 2 deletions worker/rhpv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,9 @@ func (a *accounts) deriveAccountKey(hostKey types.PublicKey) types.PrivateKey {
// Append the host for which to create it and the index to the
// corresponding sub-key.
subKey := a.key
data := append(subKey, hostKey[:]...)
data := make([]byte, 0, len(subKey)+len(hostKey)+1)
data = append(data, subKey[:]...)
data = append(data, hostKey[:]...)
data = append(data, index)

seed := types.HashBytes(data)
Expand Down Expand Up @@ -1078,7 +1080,8 @@ func RPCRenew(ctx context.Context, rrr api.RHPRenewRequest, bus Bus, t *transpor
txn.Signatures = append(txn.Signatures, hostSigs.TransactionSignatures...)

// Add the parents to get the full txnSet.
txnSet = append(parents, txn)
txnSet = parents
txnSet = append(txnSet, txn)

return rhpv2.ContractRevision{
Revision: noOpRevision,
Expand Down
3 changes: 2 additions & 1 deletion worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,8 @@ func (w *worker) rhpBroadcastHandler(jc jape.Context) {
return
}
// Broadcast the txn.
txnSet := append(parents, txn)
txnSet := parents
txnSet = append(txnSet, txn)
err = w.bus.BroadcastTransaction(ctx, txnSet)
if jc.Check("failed to broadcast transaction", err) != nil {
_ = w.bus.WalletDiscard(ctx, txn)
Expand Down

0 comments on commit da74f83

Please sign in to comment.