various: add golangci-lint, fix issues (#7905)

This adds an initial and intentionally minimal configuration for
golang-ci, fixes the issues reported, and adds a GitHub Action to check
new pull requests against this linter configuration.

Signed-off-by: Andrew Dunham <andrew@du.nham.ca>
Change-Id: I8f38fbc315836a19a094d0d3e986758b9313f163
This commit is contained in:
Andrew Dunham
2023-04-17 18:38:24 -04:00
committed by GitHub
parent ff1b35ec6c
commit 280255acae
34 changed files with 529 additions and 269 deletions
+7 -7
View File
@@ -134,7 +134,7 @@ func newTestchain(t *testing.T, input string, options ...testchainOpt) *testChai
out.recordPos(s.TokenText(), s.Pos())
// If the last token was '->', that means
// that the next identifier has a child relationship
// with the identifier preceeding '->'.
// with the identifier preceding '->'.
if lastWasChain {
out.recordParent(t, s.TokenText(), lastIdent)
}
@@ -347,16 +347,16 @@ func TestNewTestchain(t *testing.T) {
`, optTemplate("test", AUM{MessageKind: AUMNoOp, KeyID: []byte{10}}))
want := map[string]*testchainNode{
"genesis": &testchainNode{Name: "genesis", Uses: []scanner.Position{{Line: 2, Column: 16}}},
"B": &testchainNode{
"genesis": {Name: "genesis", Uses: []scanner.Position{{Line: 2, Column: 16}}},
"B": {
Name: "B",
Parent: "genesis",
Uses: []scanner.Position{{Line: 2, Column: 21}, {Line: 3, Column: 21}, {Line: 4, Column: 21}},
},
"C": &testchainNode{Name: "C", Parent: "B", Uses: []scanner.Position{{Line: 2, Column: 26}}},
"D": &testchainNode{Name: "D", Parent: "B", Uses: []scanner.Position{{Line: 3, Column: 26}}},
"E": &testchainNode{Name: "E", Parent: "B", HashSeed: 12, Uses: []scanner.Position{{Line: 4, Column: 26}, {Line: 6, Column: 10}}},
"F": &testchainNode{Name: "F", Parent: "E", Template: "test", Uses: []scanner.Position{{Line: 4, Column: 31}, {Line: 7, Column: 10}}},
"C": {Name: "C", Parent: "B", Uses: []scanner.Position{{Line: 2, Column: 26}}},
"D": {Name: "D", Parent: "B", Uses: []scanner.Position{{Line: 3, Column: 26}}},
"E": {Name: "E", Parent: "B", HashSeed: 12, Uses: []scanner.Position{{Line: 4, Column: 26}, {Line: 6, Column: 10}}},
"F": {Name: "F", Parent: "E", Template: "test", Uses: []scanner.Position{{Line: 4, Column: 31}, {Line: 7, Column: 10}}},
}
if diff := cmp.Diff(want, c.Nodes, cmpopts.IgnoreFields(scanner.Position{}, "Offset")); diff != "" {
+1 -1
View File
@@ -153,7 +153,7 @@ func TestApplyUpdatesChain(t *testing.T) {
Keys: []Key{{Kind: Key25519, Public: []byte{1, 2, 3, 4}}},
}, PrevAUMHash: fromHex("f09bda3bb7cf6756ea9adc25770aede4b3ca8142949d6ef5ca0add29af912fd4")},
},
State{DisablementSecrets: [][]byte{[]byte{1, 2, 3, 4}}},
State{DisablementSecrets: [][]byte{{1, 2, 3, 4}}},
State{
Keys: []Key{{Kind: Key25519, Public: []byte{1, 2, 3, 4}}},
LastAUMHash: hashFromHex("57343671da5eea3cfb502954e976e8028bffd3540b50a043b2a65a8d8d8217d0"),
+3 -3
View File
@@ -649,7 +649,7 @@ func markActiveChain(storage Chonk, verdict map[AUMHash]retainState, minChain in
// candidate AUMs must exist in verdict.
func markYoungAUMs(storage CompactableChonk, verdict map[AUMHash]retainState, minAge time.Duration) error {
minTime := time.Now().Add(-minAge)
for h, _ := range verdict {
for h := range verdict {
commitTime, err := storage.CommitTime(h)
if err != nil {
return err
@@ -788,7 +788,7 @@ func markDescendantAUMs(storage Chonk, verdict map[AUMHash]retainState) error {
nextIterScan := make([]AUMHash, 0, len(verdict))
for _, h := range toScan {
if verdict[h]&retainStateLeaf != 0 {
// This AUM and its decendants have already been marked.
// This AUM and its descendants have already been marked.
continue
}
verdict[h] |= retainStateLeaf
@@ -832,7 +832,7 @@ func Compact(storage CompactableChonk, head AUMHash, opts CompactionOptions) (la
return AUMHash{}, fmt.Errorf("marking young AUMs: %w", err)
}
if err := markDescendantAUMs(storage, verdict); err != nil {
return AUMHash{}, fmt.Errorf("marking decendant AUMs: %w", err)
return AUMHash{}, fmt.Errorf("marking descendant AUMs: %w", err)
}
if lastActiveAncestor, err = markAncestorIntersectionAUMs(storage, verdict, lastActiveAncestor); err != nil {
return AUMHash{}, fmt.Errorf("marking ancestor intersection: %w", err)
+1 -1
View File
@@ -600,7 +600,7 @@ type compactingChonkFake struct {
func (c *compactingChonkFake) AllAUMs() ([]AUMHash, error) {
out := make([]AUMHash, 0, len(c.Mem.aums))
for h, _ := range c.Mem.aums {
for h := range c.Mem.aums {
out = append(out, h)
}
return out, nil
+2 -2
View File
@@ -359,7 +359,7 @@ func computeActiveAncestor(storage Chonk, chains []chain) (AUMHash, error) {
if len(ancestors) == 1 {
// There's only one. DOPE.
for k, _ := range ancestors {
for k := range ancestors {
return k, nil
}
}
@@ -390,7 +390,7 @@ func computeActiveAncestor(storage Chonk, chains []chain) (AUMHash, error) {
// formerly (in a previous run) part of the chain.
// 3. Compute the state of the state machine at this ancestor. This is
// needed for fast-forward, as each update operates on the state of
// the update preceeding it.
// the update preceding it.
// 4. Iteratively apply updates till we reach head ('fast forward').
func computeActiveChain(storage Chonk, lastKnownOldest *AUMHash, maxIter int) (chain, error) {
chains, err := computeChainCandidates(storage, lastKnownOldest, maxIter)
+1 -1
View File
@@ -195,7 +195,7 @@ func TestComputeStateAt(t *testing.T) {
// provided int can be used to tweak the resulting hash (needed
// for tests you want one AUM to be 'lower' than another, so that
// that chain is taken based on fork resolution rules).
func fakeAUM(t *testing.T, template interface{}, parent *AUMHash) (AUM, AUMHash) {
func fakeAUM(t *testing.T, template any, parent *AUMHash) (AUM, AUMHash) {
if seed, ok := template.(int); ok {
a := AUM{MessageKind: AUMNoOp, KeyID: []byte{byte(seed)}}
if parent != nil {