Skip to content

Commit a2f6175

Browse files
RestartFUdidntpot
andauthored
dragonfly: add gocritic to golangci-lint config (df-mc#1245)
* feat(dragonfly): add gocritic to golangci-lint * various changes --------- Co-authored-by: هـ <104190360+didntpot@users.noreply.github.com>
1 parent db2d6a4 commit a2f6175

15 files changed

Lines changed: 55 additions & 41 deletions

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
# JetBrains
1+
# IDEs
22
.idea/
3+
.zed/
4+
.vscode/
35

46
# Dragonfly
57
/world/

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: "2"
22

33
linters:
44
default: none
5-
enable: [govet, staticcheck, ineffassign]
5+
enable: [govet, staticcheck, ineffassign, gocritic]
66
settings:
77
staticcheck:
88
checks: [all, -ST1000, -ST1003, -ST1016]

server/block/cube/trace/trace.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,20 @@ func TraverseBlocks(start, end mgl64.Vec3, f func(pos cube.Pos) (con bool)) {
3030
return
3131
}
3232

33-
if max[0] < max[1] && max[0] < max[2] {
33+
switch {
34+
case max[0] < max[1] && max[0] < max[2]:
3435
if max[0] > r {
3536
return
3637
}
3738
b[0] += stepX
3839
max[0] += delta[0]
39-
} else if max[1] < max[2] {
40+
case max[1] < max[2]:
4041
if max[1] > r {
4142
return
4243
}
4344
b[1] += stepY
4445
max[1] += delta[1]
45-
} else {
46+
default:
4647
if max[2] > r {
4748
return
4849
}

server/block/smelter.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ func (s *smelter) tickSmelting(requirement, decrement time.Duration, lit bool, s
221221
s.remainingDuration -= time.Millisecond * 50
222222

223223
// If we have a valid smeltable item, process a single stage of smelting.
224-
if canSmelt {
224+
switch {
225+
case canSmelt:
225226
// Increase the cook duration by a tick.
226227
s.cookDuration += time.Millisecond * 50
227228

@@ -243,10 +244,10 @@ func (s *smelter) tickSmelting(requirement, decrement time.Duration, lit bool, s
243244
s.cookDuration -= requirement
244245
s.experience += int(earned)
245246
}
246-
} else if s.remainingDuration == 0 {
247+
case s.remainingDuration == 0:
247248
// We've run out of fuel, so we need to reset the max duration too.
248249
s.maxDuration = 0
249-
} else {
250+
default:
250251
// We still have some remaining fuel, but the input isn't smeltable, so we reset the cook duration.
251252
s.cookDuration = 0
252253
}

server/block/wall.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,15 @@ func (w Wall) calculatePost(tx *world.Tx, pos cube.Pos) (Wall, bool) {
224224
}
225225
if !post {
226226
// If a wall has two connections that are in different axis then it becomes a post regardless of the above block.
227-
post = connections < 2
228-
if connections >= 2 {
229-
if w.NorthConnection != NoWallConnection() && w.SouthConnection != NoWallConnection() {
227+
if connections < 2 {
228+
post = true
229+
} else {
230+
switch {
231+
case w.NorthConnection != NoWallConnection() && w.SouthConnection != NoWallConnection():
230232
post = w.EastConnection != NoWallConnection() || w.WestConnection != NoWallConnection()
231-
} else if w.EastConnection != NoWallConnection() && w.WestConnection != NoWallConnection() {
233+
case w.EastConnection != NoWallConnection() && w.WestConnection != NoWallConnection():
232234
post = w.NorthConnection != NoWallConnection() || w.SouthConnection != NoWallConnection()
233-
} else {
235+
default:
234236
post = true
235237
}
236238
}

server/entity/experience.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,13 @@ func (e *ExperienceManager) Reset() {
7676
// progressFromExperience returns the level and progress from the total experience given.
7777
func progressFromExperience(experience float64) (level int, progress float64) {
7878
var a, b, c float64
79-
if experience <= float64(experienceForLevels(16)) {
79+
80+
switch {
81+
case experience <= float64(experienceForLevels(16)):
8082
a, b = 1.0, 6.0
81-
} else if experience <= float64(experienceForLevels(31)) {
83+
case experience <= float64(experienceForLevels(31)):
8284
a, b, c = 2.5, -40.5, 360.0
83-
} else {
85+
default:
8486
a, b, c = 4.5, -162.5, 2220.0
8587
}
8688

server/item/book_and_quill.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ func (b BookAndQuill) SwapPages(pageOne, pageTwo int) BookAndQuill {
8181
if _, ok := b.Page(max(pageOne, pageTwo)); !ok {
8282
panic("invalid page number")
8383
}
84-
temp := b.Pages[pageOne]
85-
b.Pages[pageOne] = b.Pages[pageTwo]
86-
b.Pages[pageTwo] = temp
84+
b.Pages[pageOne], b.Pages[pageTwo] = b.Pages[pageTwo], b.Pages[pageOne]
8785
return b
8886
}
8987

server/item/inventory/inventory.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,9 @@ func (inv *Inventory) Merge(inv2 *Inventory, f func(int, item.Stack, item.Stack)
302302
defer inv2.mu.RUnlock()
303303

304304
n := New(len(inv.slots)+len(inv2.slots), f)
305-
n.slots = append(inv.slots, inv2.slots...)
305+
n.slots = make([]item.Stack, 0, len(inv.slots)+len(inv2.slots))
306+
n.slots = append(n.slots, inv.slots...)
307+
n.slots = append(n.slots, inv2.slots...)
306308
return n
307309
}
308310

server/player/player.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,14 +537,15 @@ func (p *Player) Heal(health float64, source world.HealingSource) {
537537

538538
// updateFallState is called to update the entities falling state.
539539
func (p *Player) updateFallState(distanceThisTick float64) {
540-
if p.OnGround() {
540+
switch {
541+
case p.OnGround():
541542
if p.fallDistance > 0 {
542543
p.fall(p.fallDistance)
543544
p.ResetFallDistance()
544545
}
545-
} else if distanceThisTick < p.fallDistance {
546+
case distanceThisTick < p.fallDistance:
546547
p.fallDistance -= distanceThisTick
547-
} else {
548+
default:
548549
p.ResetFallDistance()
549550
}
550551
}
@@ -588,7 +589,7 @@ func (p *Player) Hurt(dmg float64, src world.DamageSource) (float64, bool) {
588589

589590
immune := time.Now().Before(p.immuneUntil)
590591
if immune {
591-
if damageLeft = damageLeft - p.lastDamage; damageLeft <= 0 {
592+
if damageLeft -= p.lastDamage; damageLeft <= 0 {
592593
return 0, false
593594
}
594595
}

server/player/playerdb/effect.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ func dataToEffects(data []jsonEffect) []effect.Effect {
3030
}
3131
switch eff := e.(type) {
3232
case effect.LastingType:
33-
if d.Ambient {
33+
switch {
34+
case d.Ambient:
3435
effects[i] = effect.NewAmbient(eff, d.Level, d.Duration)
35-
} else if d.Infinite {
36+
case d.Infinite:
3637
effects[i] = effect.NewInfinite(eff, d.Level)
37-
} else {
38+
default:
3839
effects[i] = effect.New(eff, d.Level, d.Duration)
3940
}
4041

0 commit comments

Comments
 (0)