fork of indigo with slightly nicer lexgen

batch of golangci-lint fixes in `atproto/*` (#1031)

This isn't everything, just a first pass. There were some real issues
with errors not getting wired through.

I'm kind of ambivalent about the pattern:

```go
defer func() {
_ = resp.Body.Close()
}()
```

but do want to make any non-defer error returns explicit.

authored by bnewbold.net and committed by GitHub 2773179a 539c5771

+1
.gitignore
··· 36 36 # Don't ignore this file itself, or other specific dotfiles 37 37 !.gitignore 38 38 !.github/ 39 + !.golangci.yaml 39 40 40 41 # Don't commit your (default location) creds 41 42 bsky.auth
+17
.golangci.yaml
··· 1 + version: "2" 2 + 3 + issues: 4 + max-issues-per-linter: 0 5 + max-same-issues: 0 6 + 7 + linters: 8 + disable: 9 + - errcheck 10 + - gocritic 11 + - unused 12 + settings: 13 + errcheck: 14 + check-type-assertions: true 15 + disable-default-exclusions: true 16 + gocritic: 17 + enable-all: true
-5
atproto/identity/apidir/apidir.go
··· 40 40 DID syntax.DID `json:"did"` 41 41 } 42 42 43 - type errorBody struct { 44 - Name string `json:"error"` 45 - Message string `json:"message,omitempty"` 46 - } 47 - 48 43 func NewAPIDirectory(host string) APIDirectory { 49 44 return APIDirectory{ 50 45 Client: &http.Client{
+1 -1
atproto/identity/directory.go
··· 57 57 var ErrKeyNotDeclared = errors.New("DID document did not declare a relevant public key") 58 58 59 59 // Handle was invalid, in a situation where a valid handle is required. 60 - var ErrInvalidHandle = errors.New("Invalid Handle") 60 + var ErrInvalidHandle = errors.New("invalid handle") 61 61 62 62 var DefaultPLCURL = "https://plc.directory" 63 63
+3
atproto/lexicon/cmd/lextool/net.go
··· 65 65 } 66 66 67 67 body, err := data.UnmarshalJSON(respBytes) 68 + if err != nil { 69 + return err 70 + } 68 71 record, ok := body["value"].(map[string]any) 69 72 if !ok { 70 73 return fmt.Errorf("fetched record was not an object")
+1 -2
atproto/repo/mst/mst_interop_test.go
··· 104 104 } 105 105 106 106 func TestInteropKnownMapsTricky(t *testing.T) { 107 + t.Skip("TODO: these are currently disallowed in typescript implementation") 107 108 assert := assert.New(t) 108 - 109 - t.Skip("TODO: these are currently disallowed in typescript implementation") 110 109 111 110 cid1str := "bafyreie5cvv4h45feadgeuwhbcutmh6t2ceseocckahdoe6uat64zmz454" 112 111
+1 -1
atproto/repo/mst/mst_test.go
··· 180 180 181 181 mapKeys := make([]string, len(inMap)) 182 182 i := 0 183 - for k, _ := range inMap { 183 + for k := range inMap { 184 184 mapKeys[i] = k 185 185 i++ 186 186 }
+1 -1
atproto/repo/mst/node.go
··· 186 186 // TODO: should we actually return 0 in this case? 187 187 return 0, fmt.Errorf("can't determine key range of empty MST node") 188 188 } 189 - if markDirty == true { 189 + if markDirty { 190 190 n.Dirty = true 191 191 } 192 192 // check if lower than this entire node
+4 -1
atproto/repo/mst/node_insert.go
··· 1 1 package mst 2 2 3 3 import ( 4 + "errors" 4 5 "fmt" 5 6 "slices" 6 7 ··· 66 67 } 67 68 68 69 // include "covering" proof for this operation 69 - proveMutation(n, key) 70 + if err := proveMutation(n, key); err != nil && !errors.Is(err, ErrPartialTree) { 71 + return nil, nil, err 72 + } 70 73 71 74 if !split { 72 75 // TODO: is this really necessary? or can we just slices.Insert beyond the end of a slice?
+4 -1
atproto/repo/mst/node_remove.go
··· 1 1 package mst 2 2 3 3 import ( 4 + "errors" 4 5 "fmt" 5 6 "slices" 6 7 ··· 61 62 } 62 63 63 64 // marks adjacent child nodes dirty to include as "proof" 64 - proveMutation(n, key) 65 + if err := proveMutation(n, key); err != nil && !errors.Is(err, ErrPartialTree) { 66 + return nil, nil, err 67 + } 65 68 66 69 // check if top of node is now just a pointer 67 70 if top {
+1 -1
atproto/repo/operation.go
··· 147 147 148 148 set := map[string]bool{} 149 149 for _, op := range list { 150 - if _, ok := set[op.Path]; ok != false { 150 + if _, ok := set[op.Path]; ok { 151 151 return nil, fmt.Errorf("duplicate path in operation list") 152 152 } 153 153 set[op.Path] = true
+3 -2
atproto/repo/operation_test.go
··· 91 91 assert.NoError(err) 92 92 assert.Error(CheckOp(tree, op)) 93 93 94 - op, err = ApplyOp(tree, "color/pink", &c3) 94 + _, err = ApplyOp(tree, "color/pink", &c3) 95 95 assert.NoError(err) 96 96 op, err = ApplyOp(tree, "color/pink", &c2) 97 + assert.NoError(err) 97 98 assert.NoError(CheckOp(tree, op)) 98 99 assert.True(op.IsUpdate()) 99 100 err = InvertOp(tree, op) ··· 130 131 } 131 132 mapKeys := make([]string, len(startMap)) 132 133 i := 0 133 - for k, _ := range startMap { 134 + for k := range startMap { 134 135 mapKeys[i] = k 135 136 i++ 136 137 }
-1
atproto/syntax/did.go
··· 14 14 type DID string 15 15 16 16 var didRegex = regexp.MustCompile(`^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$`) 17 - var plcChars = "" 18 17 19 18 func isASCIIAlphaNum(c rune) bool { 20 19 if (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') {
+1 -1
atproto/syntax/tid.go
··· 58 58 59 59 // Constructs a new TID from a UNIX timestamp (in milliseconds) and clock ID value. 60 60 func NewTID(unixMicros int64, clockId uint) TID { 61 - var v uint64 = (uint64(unixMicros&0x1F_FFFF_FFFF_FFFF) << 10) | uint64(clockId&0x3FF) 61 + v := (uint64(unixMicros&0x1F_FFFF_FFFF_FFFF) << 10) | uint64(clockId&0x3FF) 62 62 return NewTIDFromInteger(v) 63 63 } 64 64