Skip to content

Commit b305188

Browse files
committed
dragonfly: Integrate staticcheck, fixed several errors pointed out by it and resolved others using directives.
Only U1000 was left for now, most of which are false positives from compiler directives.
1 parent 2559ade commit b305188

File tree

10 files changed

+26
-9
lines changed

10 files changed

+26
-9
lines changed

dragonfly/block/parse.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package block
22

3+
//lint:file-ignore ST1005 Errors returned by this file are intentionally readable for an end user.
4+
35
import (
46
"fmt"
57
"git.jetbrains.space/dragonfly/dragonfly.git/dragonfly/internal/block_internal"

dragonfly/block/register.go

+2
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,15 @@ func init() {
109109

110110
// readSlice reads an interface slice from a map at the key passed.
111111
func readSlice(m map[string]interface{}, key string) []interface{} {
112+
//lint:ignore S1005 Double assignment is done explicitly to prevent panics.
112113
v, _ := m[key]
113114
b, _ := v.([]interface{})
114115
return b
115116
}
116117

117118
// readString reads a string from a map at the key passed.
118119
func readString(m map[string]interface{}, key string) string {
120+
//lint:ignore S1005 Double assignment is done explicitly to prevent panics.
119121
v, _ := m[key]
120122
b, _ := v.(string)
121123
return b

dragonfly/entity/movement.go

-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ type movementComputer struct {
2323
dragBeforeGravity bool
2424
}
2525

26-
// defaultGravity is the default gravity applied to entities.
27-
//noinspection GoUnusedConst
28-
const defaultGravity = 0.08
29-
3026
// tickMovement performs a movement tick on an entity. Velocity is applied and changed according to the values
3127
// of its drag and gravity.
3228
// The new position of the entity after movement is returned.

dragonfly/internal/nbtconv/item.go

+3
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,23 @@ func readByte(m map[string]interface{}, key string) byte {
149149

150150
// readInt16 reads an int16 from a map at the key passed.
151151
func readInt16(m map[string]interface{}, key string) int16 {
152+
//lint:ignore S1005 Double assignment is done explicitly to prevent panics.
152153
v, _ := m[key]
153154
b, _ := v.(int16)
154155
return b
155156
}
156157

157158
// readInt32 reads an int32 from a map at the key passed.
158159
func readInt32(m map[string]interface{}, key string) int32 {
160+
//lint:ignore S1005 Double assignment is done explicitly to prevent panics.
159161
v, _ := m[key]
160162
b, _ := v.(int32)
161163
return b
162164
}
163165

164166
// readString reads a string from a map at the key passed.
165167
func readString(m map[string]interface{}, key string) string {
168+
//lint:ignore S1005 Double assignment is done explicitly to prevent panics.
166169
v, _ := m[key]
167170
b, _ := v.(string)
168171
return b

dragonfly/item/stack.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (s Stack) Grow(n int) Stack {
5959
return s
6060
}
6161

62-
// BaseDurability returns the current durability of the item stack. If the item is not one that implements the
62+
// Durability returns the current durability of the item stack. If the item is not one that implements the
6363
// Durable interface, BaseDurability will always return -1.
6464
// The closer the durability returned is to 0, the closer the item is to breaking.
6565
func (s Stack) Durability() int {

dragonfly/session/world.go

+1
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ func (s *Session) blockRuntimeID(b world.Block) uint32 {
477477
// entityRuntimeID returns the runtime ID of the entity passed.
478478
func (s *Session) entityRuntimeID(e world.Entity) uint64 {
479479
s.entityMutex.RLock()
480+
//lint:ignore S1005 Double assignment is done explicitly to prevent panics.
480481
id, _ := s.entityRuntimeIDs[e]
481482
s.entityMutex.RUnlock()
482483
return id

dragonfly/world/axis.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const (
1717
X
1818
)
1919

20-
// EncodeBlock converts an Axis into either x, y or z, depending on which axis it is.
20+
// String converts an Axis into either x, y or z, depending on which axis it is.
2121
func (a Axis) String() string {
2222
if a == X {
2323
return "x"

dragonfly/world/position.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,14 @@ func (p BlockPos) Side(face Face) BlockPos {
5454
return p
5555
}
5656

57-
// BlockPosFromNBT returns a position from the X, Y and Z components stored in the NBT data map passed. The
57+
// blockPosFromNBT returns a position from the X, Y and Z components stored in the NBT data map passed. The
5858
// map is assumed to have an 'x', 'y' and 'z' key.
59-
func BlockPosFromNBT(data map[string]interface{}) BlockPos {
59+
func blockPosFromNBT(data map[string]interface{}) BlockPos {
60+
//lint:ignore S1005 Double assignment is done explicitly to prevent panics.
6061
xInterface, _ := data["x"]
62+
//lint:ignore S1005 Double assignment is done explicitly to prevent panics.
6163
yInterface, _ := data["y"]
64+
//lint:ignore S1005 Double assignment is done explicitly to prevent panics.
6265
zInterface, _ := data["z"]
6366
x, _ := xInterface.(int32)
6467
y, _ := yInterface.(int32)

dragonfly/world/world.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ func (w *World) spreadLight(c *chunk.Chunk, pos ChunkPos) {
10351035
// have block NBT will then be stored into memory.
10361036
func (w *World) loadIntoBlocks(c *chunk.Chunk, blockEntityData []map[string]interface{}) {
10371037
for _, data := range blockEntityData {
1038-
pos := BlockPosFromNBT(data)
1038+
pos := blockPosFromNBT(data)
10391039
b, err := w.block(c, pos)
10401040
if err != nil {
10411041
w.log.Errorf("error loading block for block entity: %v", err)

staticcheck.conf

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
checks = ["all", "-ST1000", "-ST1003", "-ST1016"]
2+
initialisms = ["ACL", "API", "ASCII", "CPU", "CSS", "DNS",
3+
"EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID",
4+
"IP", "JSON", "QPS", "RAM", "RPC", "SLA",
5+
"SMTP", "SQL", "SSH", "TCP", "TLS", "TTL",
6+
"UDP", "UI", "GID", "UID", "UUID", "URI",
7+
"URL", "UTF8", "VM", "XML", "XMPP", "XSRF",
8+
"XSS", "XUID"]
9+
dot_import_whitelist = []
10+
http_status_code_whitelist = ["200", "400", "404", "500"]

0 commit comments

Comments
 (0)