chore: linter: staticcheck

Signed-off-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
Jakob Borg
2025-10-23 22:48:54 +02:00
parent 98cf5872e9
commit df8d8c276e
7 changed files with 33 additions and 21 deletions
+6
View File
@@ -70,6 +70,12 @@ linters:
# Rollback errors can be ignored # Rollback errors can be ignored
- linters: [errcheck] - linters: [errcheck]
source: Rollback source: Rollback
# Embedded fields named in selectors may add clarity
- linters: [staticcheck]
text: QF1008
# Don't necessarily rewrite !(foo || bar) to !foo && !bar
- linters: [staticcheck]
text: QF1001
settings: settings:
sloglint: sloglint:
context: "scope" context: "scope"
+4 -3
View File
@@ -659,13 +659,14 @@ func auditWriter(auditFile string) io.Writer {
var auditDest string var auditDest string
var auditFlags int var auditFlags int
if auditFile == "-" { switch auditFile {
case "-":
fd = os.Stdout fd = os.Stdout
auditDest = "stdout" auditDest = "stdout"
} else if auditFile == "--" { case "--":
fd = os.Stderr fd = os.Stderr
auditDest = "stderr" auditDest = "stderr"
} else { default:
if auditFile == "" { if auditFile == "" {
auditFile = locations.GetTimestamped(locations.AuditLog) auditFile = locations.GetTimestamped(locations.AuditLog)
auditFlags = os.O_WRONLY | os.O_CREATE | os.O_EXCL auditFlags = os.O_WRONLY | os.O_CREATE | os.O_EXCL
+4 -3
View File
@@ -428,11 +428,12 @@ func migrateToConfigV12(cfg *Configuration) {
var newDiscoServers []string var newDiscoServers []string
var useDefault bool var useDefault bool
for _, addr := range cfg.Options.RawGlobalAnnServers { for _, addr := range cfg.Options.RawGlobalAnnServers {
if addr == "udp4://announce.syncthing.net:22026" { switch addr {
case "udp4://announce.syncthing.net:22026":
useDefault = true useDefault = true
} else if addr == "udp6://announce-v6.syncthing.net:22026" { case "udp6://announce-v6.syncthing.net:22026":
useDefault = true useDefault = true
} else { default:
newDiscoServers = append(newDiscoServers, addr) newDiscoServers = append(newDiscoServers, addr)
} }
} }
+4 -3
View File
@@ -81,11 +81,12 @@ func (t *tcpListener) serve(ctx context.Context) error {
defer slog.InfoContext(ctx, "TCP listener shutting down", slogutil.Address(tcaddr)) defer slog.InfoContext(ctx, "TCP listener shutting down", slogutil.Address(tcaddr))
var ipVersion nat.IPVersion var ipVersion nat.IPVersion
if t.uri.Scheme == "tcp4" { switch t.uri.Scheme {
case "tcp4":
ipVersion = nat.IPv4Only ipVersion = nat.IPv4Only
} else if t.uri.Scheme == "tcp6" { case "tcp6":
ipVersion = nat.IPv6Only ipVersion = nat.IPv6Only
} else { default:
ipVersion = nat.IPvAny ipVersion = nat.IPvAny
} }
mapping := t.natService.NewMapping(nat.TCP, ipVersion, tcaddr.IP, tcaddr.Port) mapping := t.natService.NewMapping(nat.TCP, ipVersion, tcaddr.IP, tcaddr.Port)
+4 -4
View File
@@ -140,12 +140,12 @@ func (evType EventType) Merge(other EventType) EventType {
} }
func (evType EventType) String() string { func (evType EventType) String() string {
switch { switch evType {
case evType == NonRemove: case NonRemove:
return "non-remove" return "non-remove"
case evType == Remove: case Remove:
return "remove" return "remove"
case evType == Mixed: case Mixed:
return "mixed" return "mixed"
default: default:
panic("bug: Unknown event type") panic("bug: Unknown event type")
+8 -6
View File
@@ -132,11 +132,12 @@ func (s *IGDService) AddPinhole(ctx context.Context, protocol nat.Protocol, intA
func (s *IGDService) tryAddPinholeForIP6(ctx context.Context, protocol nat.Protocol, port int, duration time.Duration, ip net.IP) error { func (s *IGDService) tryAddPinholeForIP6(ctx context.Context, protocol nat.Protocol, port int, duration time.Duration, ip net.IP) error {
var protoNumber int var protoNumber int
if protocol == nat.TCP { switch protocol {
case nat.TCP:
protoNumber = 6 protoNumber = 6
} else if protocol == nat.UDP { case nat.UDP:
protoNumber = 17 protoNumber = 17
} else { default:
return errors.New("protocol not supported") return errors.New("protocol not supported")
} }
@@ -258,11 +259,12 @@ func (s *IGDService) GetLocalIPv4Address() net.IP {
// SupportsIPVersion checks whether this is a WANIPv6FirewallControl device, // SupportsIPVersion checks whether this is a WANIPv6FirewallControl device,
// in which case pinholing instead of port mapping should be done // in which case pinholing instead of port mapping should be done
func (s *IGDService) SupportsIPVersion(version nat.IPVersion) bool { func (s *IGDService) SupportsIPVersion(version nat.IPVersion) bool {
if version == nat.IPvAny { switch version {
case nat.IPvAny:
return true return true
} else if version == nat.IPv6Only { case nat.IPv6Only:
return s.URN == urnWANIPv6FirewallControlV1 return s.URN == urnWANIPv6FirewallControlV1
} else if version == nat.IPv4Only { case nat.IPv4Only:
return s.URN != urnWANIPv6FirewallControlV1 return s.URN != urnWANIPv6FirewallControlV1
} }
+3 -2
View File
@@ -449,10 +449,11 @@ func (a *aggregator) updateConfig(folderCfg config.FolderConfiguration) {
} }
func updateInProgressSet(event events.Event, inProgress map[string]struct{}) { func updateInProgressSet(event events.Event, inProgress map[string]struct{}) {
if event.Type == events.ItemStarted { switch event.Type {
case events.ItemStarted:
path := event.Data.(map[string]string)["item"] path := event.Data.(map[string]string)["item"]
inProgress[path] = struct{}{} inProgress[path] = struct{}{}
} else if event.Type == events.ItemFinished { case events.ItemFinished:
path := event.Data.(map[string]interface{})["item"].(string) path := event.Data.(map[string]interface{})["item"].(string)
delete(inProgress, path) delete(inProgress, path)
} }