1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-17 14:37:02 +00:00

Fix misc. linter issues (comments, variable naming, etc.)

We've accumulated a few linter issues around comments and a couple of
variable names.

While none of them is major, this patch cleans them up so it's easier to
go through the linter output, and we can start being more strict about
it.
This commit is contained in:
Alberto Bertogli
2022-08-27 23:16:01 +01:00
parent 6dfff9a790
commit e85c31782b
11 changed files with 30 additions and 13 deletions

View File

@@ -37,8 +37,7 @@ lint_task:
- linters:
- staticcheck
# SA1015: time.Tick leaks but it's ok on endless functions.
# SA1019: BuildNameToCertificate deprecation, remove on Go >= 1.14.
text: "SA1015:|SA1019:"
text: "SA1015:"
exclude-use-default: true
lint_config_file:
path: /tmp/lint.yml

View File

@@ -60,11 +60,11 @@ func usersWithXDontExist(user, domain string) (bool, error) {
return true, nil
}
var userLookupError = errors.New("test error userLookupError")
var errUserLookup = errors.New("test error errUserLookup")
func usersWithXErrorYDontExist(user, domain string) (bool, error) {
if strings.HasPrefix(user, "x") {
return false, userLookupError
return false, errUserLookup
}
if strings.HasPrefix(user, "y") {
return false, nil
@@ -134,12 +134,12 @@ func TestUserLookupErrors(t *testing.T) {
cases := Cases{
{"a@dom", []Recipient{{"a@remote", EMAIL}}, nil},
{"b@dom", nil, userLookupError},
{"b@dom", nil, errUserLookup},
{"c@dom", []Recipient{{"c@dom", EMAIL}}, nil},
{"x@dom", nil, userLookupError},
{"x@dom", nil, errUserLookup},
// This one goes through the catch-all.
{"y@dom", nil, userLookupError},
{"y@dom", nil, errUserLookup},
}
cases.check(t, resolver)
}

View File

@@ -113,6 +113,8 @@ func TestSanitize(t *testing.T) {
// http://www.user.uni-hannover.de/nhtcapri/bidirectional-text.html
// We allow them, they're the same on both sides.
{"١٩٩٩–١٢–٣١", "١٩٩٩–١٢–٣١"},
//lint:ignore ST1018 The use of a literal U+200C is intentional.
{"موزه‌ها", "موزه\u200cها"},
}
for _, c := range cases {

View File

@@ -20,7 +20,8 @@ var (
testMXI = expvar.NewMap("testMXI")
testMXF = expvar.NewMap("testMXF")
testMEmpty = expvar.NewMap("testMEmpty") //nolint // Unused.
//lint:ignore U1000 Intentionally unused, should not be exported.
testMEmpty = expvar.NewMap("testMEmpty") //nolint
testMOther = expvar.NewMap("testMOther")

View File

@@ -174,6 +174,8 @@ func (s *Server) periodicallyReload() {
if reloadEvery == nil {
return
}
//lint:ignore SA1015 This lasts the program's lifetime.
for range time.Tick(*reloadEvery) {
err := s.aliasesR.Reload()
if err != nil {

View File

@@ -137,7 +137,7 @@ func (c dumbCourier) Deliver(from string, to string, data []byte) (error, bool)
// DumbCourier always succeeds delivery, and ignores everything.
var DumbCourier = dumbCourier{}
// generateCert generates a new, INSECURE self-signed certificate and writes
// GenerateCert generates a new, INSECURE self-signed certificate and writes
// it to a pair of (cert.pem, key.pem) files to the given path.
// Note the certificate is only useful for testing purposes.
func GenerateCert(path string) (*tls.Config, error) {

View File

@@ -4,6 +4,7 @@
// Note that chasquid does NOT support this, we do it before starting up the
// daemon for testing purposes only.
//
//go:build ignore
// +build ignore
package main

View File

@@ -31,7 +31,6 @@ var (
var (
host string
exit bool
)
func main() {
@@ -73,8 +72,13 @@ func main() {
time.Sleep(24 * time.Hour)
}
}
for _, c := range conns {
c.close()
}
}
// C represents a single connection.
type C struct {
tr trace.Trace
n net.Conn

View File

@@ -90,6 +90,7 @@ func main() {
fmt.Printf("Total: %.1f\n", totals.TotalPercent())
}
// Totals is used to keep track of total counters.
type Totals struct {
// Total statements.
total int
@@ -104,6 +105,7 @@ type Totals struct {
coveredF map[string]int
}
// Add the given profile to the total counters.
func (t *Totals) Add(p *cover.Profile) {
for _, b := range p.Blocks {
t.total += b.NumStmt
@@ -115,10 +117,12 @@ func (t *Totals) Add(p *cover.Profile) {
}
}
// Percent covered for the given file.
func (t *Totals) Percent(f string) float32 {
return float32(t.coveredF[f]) / float32(t.totalF[f]) * 100
}
// TotalPercent covered, across all files.
func (t *Totals) TotalPercent() float32 {
return float32(t.covered) / float32(t.total) * 100
}

View File

@@ -126,7 +126,7 @@ func serial(id int) {
var count int64
start := time.Now()
for {
count += 1
count++
err := one()
if err != nil {
log.Fatalf("%v", err)

View File

@@ -119,7 +119,11 @@ func (m *miniDNS) listenAndServeUDP(addr string) {
log.Fatalf("error packing reply: %v", err)
}
conn.WriteTo(rbuf, addr)
_, err = conn.WriteTo(rbuf, addr)
if err != nil {
log.Infof("%v/%-5d error writing: %v",
addr, msg.ID, err)
}
}
}
@@ -245,7 +249,7 @@ func (m *miniDNS) loadZones(f *os.File) {
continue
}
vs := regexp.MustCompile("\\s+").Split(line, 3)
vs := regexp.MustCompile(`\s+`).Split(line, 3)
if len(vs) != 3 {
log.Fatalf("line %d: invalid format", lineno)
}