Skip to content

Commit

Permalink
dragonfly: Fix staticcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
TwistedAsylumMC committed Aug 15, 2024
1 parent 44ad96b commit 5fd1432
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 36 deletions.
32 changes: 16 additions & 16 deletions cmd/blockhash/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"flag"
"fmt"
"go/ast"
"go/parser"
"go/token"
"golang.org/x/tools/go/packages"
"io"
"log"
"math/bits"
"os"
"path/filepath"
"sort"
"strconv"
"strings"
Expand All @@ -23,24 +23,25 @@ func main() {
if len(flag.Args()) != 1 {
log.Fatalln("Must pass one package to produce block hashes for.")
}
fs := token.NewFileSet()
packages, err := parser.ParseDir(fs, flag.Args()[0], nil, parser.ParseComments)
cfg := &packages.Config{
Mode: packages.NeedSyntax | packages.NeedTypes | packages.NeedTypesInfo | packages.NeedFiles,
}
pkgs, err := packages.Load(cfg, flag.Args()[0])
if err != nil {
log.Fatalln(err)
}
f, err := os.OpenFile(*out, os.O_CREATE|os.O_TRUNC|os.O_WRONLY|os.O_APPEND, 0644)
if err != nil {
log.Fatalln(err)
}
for _, pkg := range packages {
procPackage(pkg, fs, f)
for _, pkg := range pkgs {
procPackage(pkg, f)
}
_ = f.Close()
}

func procPackage(pkg *ast.Package, fs *token.FileSet, w io.Writer) {
func procPackage(pkg *packages.Package, w io.Writer) {
b := &hashBuilder{
fs: fs,
pkg: pkg,
fields: make(map[string][]*ast.Field),
aliases: make(map[string]string),
Expand All @@ -66,8 +67,7 @@ var (
)

type hashBuilder struct {
fs *token.FileSet
pkg *ast.Package
pkg *packages.Package
fields map[string][]*ast.Field
funcs map[string]*ast.FuncDecl
aliases map[string]string
Expand All @@ -89,7 +89,7 @@ func (b *hashBuilder) sortNames() {

// writePackage writes the package at the top of the file.
func (b *hashBuilder) writePackage(w io.Writer) {
if _, err := fmt.Fprintf(w, packageFormat, b.pkg.Name); err != nil {
if _, err := fmt.Fprintf(w, packageFormat, filepath.Base(b.pkg.ID)); err != nil {
log.Fatalln(err)
}
}
Expand Down Expand Up @@ -147,7 +147,7 @@ func (b *hashBuilder) writeMethods(w io.Writer, baseBits int) {
for _, n := range fun.Recv.List[0].Names {
recvName = n.Name
}
pos := b.fs.Position(fun.Body.Pos())
pos := b.pkg.Fset.Position(fun.Body.Pos())
f, err := os.Open(pos.Filename)
if err != nil {
log.Fatalln(err)
Expand Down Expand Up @@ -264,8 +264,8 @@ func (b *hashBuilder) resolveBlocks() {
}
}

func (b *hashBuilder) readFuncs(pkg *ast.Package) {
for _, f := range pkg.Files {
func (b *hashBuilder) readFuncs(pkg *packages.Package) {
for _, f := range pkg.Syntax {
ast.Inspect(f, b.readFuncDecls)
}
}
Expand All @@ -281,8 +281,8 @@ func (b *hashBuilder) readFuncDecls(node ast.Node) bool {
return true
}

func (b *hashBuilder) readStructFields(pkg *ast.Package) {
for _, f := range pkg.Files {
func (b *hashBuilder) readStructFields(pkg *packages.Package) {
for _, f := range pkg.Syntax {
ast.Inspect(f, b.readStructs)
}
b.resolveEmbedded()
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/sirupsen/logrus v1.9.3
golang.org/x/exp v0.0.0-20230206171751-46f607a40771
golang.org/x/text v0.16.0
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d
)

require (
Expand All @@ -29,8 +30,10 @@ require (
github.com/sandertv/go-raknet v1.14.1 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/image v0.17.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
)
9 changes: 8 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
Expand Down Expand Up @@ -69,6 +70,8 @@ golang.org/x/image v0.17.0 h1:nTRVVdajgB8zCMZVsViyzhnMKPwYeroEERRC64JuLco=
golang.org/x/image v0.17.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
Expand All @@ -83,6 +86,8 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -112,6 +117,8 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
Expand Down
17 changes: 0 additions & 17 deletions server/block/slab_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,6 @@ func encodeSlabBlock(block world.Block) (id string) {
panic("invalid block used for slab")
}

// encodeLegacySlabId encodes a legacy slab type to its identifier.
func encodeLegacySlabId(slabType string) string {
switch slabType {
case "wood_type":
return "wooden_slab"
case "stone_slab_type":
return "stone_block_slab"
case "stone_slab_type_2":
return "stone_block_slab2"
case "stone_slab_type_3":
return "stone_block_slab3"
case "stone_slab_type_4":
return "stone_block_slab4"
}
panic("invalid slab type")
}

// SlabBlocks returns a list of all possible blocks for a slab.
func SlabBlocks() []world.Block {
b := []world.Block{
Expand Down
7 changes: 5 additions & 2 deletions server/cmd/output.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package cmd

import "fmt"
import (
"errors"
"fmt"
)

// Output holds the output of a command execution. It holds success messages and error messages, which the
// source of a command execution gets sent.
Expand All @@ -16,7 +19,7 @@ func (o *Output) Errorf(format string, a ...any) {

// Error formats an error message and adds it to the command output.
func (o *Output) Error(a ...any) {
o.errors = append(o.errors, fmt.Errorf(fmt.Sprint(a...)))
o.errors = append(o.errors, errors.New(fmt.Sprint(a...)))
}

// Printf formats a (success) message and adds it to the command output.
Expand Down

0 comments on commit 5fd1432

Please sign in to comment.