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:
@@ -37,8 +37,7 @@ lint_task:
|
|||||||
- linters:
|
- linters:
|
||||||
- staticcheck
|
- staticcheck
|
||||||
# SA1015: time.Tick leaks but it's ok on endless functions.
|
# SA1015: time.Tick leaks but it's ok on endless functions.
|
||||||
# SA1019: BuildNameToCertificate deprecation, remove on Go >= 1.14.
|
text: "SA1015:"
|
||||||
text: "SA1015:|SA1019:"
|
|
||||||
exclude-use-default: true
|
exclude-use-default: true
|
||||||
lint_config_file:
|
lint_config_file:
|
||||||
path: /tmp/lint.yml
|
path: /tmp/lint.yml
|
||||||
|
|||||||
@@ -60,11 +60,11 @@ func usersWithXDontExist(user, domain string) (bool, error) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var userLookupError = errors.New("test error userLookupError")
|
var errUserLookup = errors.New("test error errUserLookup")
|
||||||
|
|
||||||
func usersWithXErrorYDontExist(user, domain string) (bool, error) {
|
func usersWithXErrorYDontExist(user, domain string) (bool, error) {
|
||||||
if strings.HasPrefix(user, "x") {
|
if strings.HasPrefix(user, "x") {
|
||||||
return false, userLookupError
|
return false, errUserLookup
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(user, "y") {
|
if strings.HasPrefix(user, "y") {
|
||||||
return false, nil
|
return false, nil
|
||||||
@@ -134,12 +134,12 @@ func TestUserLookupErrors(t *testing.T) {
|
|||||||
|
|
||||||
cases := Cases{
|
cases := Cases{
|
||||||
{"a@dom", []Recipient{{"a@remote", EMAIL}}, nil},
|
{"a@dom", []Recipient{{"a@remote", EMAIL}}, nil},
|
||||||
{"b@dom", nil, userLookupError},
|
{"b@dom", nil, errUserLookup},
|
||||||
{"c@dom", []Recipient{{"c@dom", EMAIL}}, nil},
|
{"c@dom", []Recipient{{"c@dom", EMAIL}}, nil},
|
||||||
{"x@dom", nil, userLookupError},
|
{"x@dom", nil, errUserLookup},
|
||||||
|
|
||||||
// This one goes through the catch-all.
|
// This one goes through the catch-all.
|
||||||
{"y@dom", nil, userLookupError},
|
{"y@dom", nil, errUserLookup},
|
||||||
}
|
}
|
||||||
cases.check(t, resolver)
|
cases.check(t, resolver)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,6 +113,8 @@ func TestSanitize(t *testing.T) {
|
|||||||
// http://www.user.uni-hannover.de/nhtcapri/bidirectional-text.html
|
// http://www.user.uni-hannover.de/nhtcapri/bidirectional-text.html
|
||||||
// We allow them, they're the same on both sides.
|
// We allow them, they're the same on both sides.
|
||||||
{"١٩٩٩–١٢–٣١", "١٩٩٩–١٢–٣١"},
|
{"١٩٩٩–١٢–٣١", "١٩٩٩–١٢–٣١"},
|
||||||
|
|
||||||
|
//lint:ignore ST1018 The use of a literal U+200C is intentional.
|
||||||
{"موزهها", "موزه\u200cها"},
|
{"موزهها", "موزه\u200cها"},
|
||||||
}
|
}
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ var (
|
|||||||
testMXI = expvar.NewMap("testMXI")
|
testMXI = expvar.NewMap("testMXI")
|
||||||
testMXF = expvar.NewMap("testMXF")
|
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")
|
testMOther = expvar.NewMap("testMOther")
|
||||||
|
|
||||||
|
|||||||
@@ -174,6 +174,8 @@ func (s *Server) periodicallyReload() {
|
|||||||
if reloadEvery == nil {
|
if reloadEvery == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//lint:ignore SA1015 This lasts the program's lifetime.
|
||||||
for range time.Tick(*reloadEvery) {
|
for range time.Tick(*reloadEvery) {
|
||||||
err := s.aliasesR.Reload()
|
err := s.aliasesR.Reload()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ func (c dumbCourier) Deliver(from string, to string, data []byte) (error, bool)
|
|||||||
// DumbCourier always succeeds delivery, and ignores everything.
|
// DumbCourier always succeeds delivery, and ignores everything.
|
||||||
var DumbCourier = dumbCourier{}
|
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.
|
// it to a pair of (cert.pem, key.pem) files to the given path.
|
||||||
// Note the certificate is only useful for testing purposes.
|
// Note the certificate is only useful for testing purposes.
|
||||||
func GenerateCert(path string) (*tls.Config, error) {
|
func GenerateCert(path string) (*tls.Config, error) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
// Note that chasquid does NOT support this, we do it before starting up the
|
// Note that chasquid does NOT support this, we do it before starting up the
|
||||||
// daemon for testing purposes only.
|
// daemon for testing purposes only.
|
||||||
//
|
//
|
||||||
|
//go:build ignore
|
||||||
// +build ignore
|
// +build ignore
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ var (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
host string
|
host string
|
||||||
exit bool
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -73,8 +72,13 @@ func main() {
|
|||||||
time.Sleep(24 * time.Hour)
|
time.Sleep(24 * time.Hour)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, c := range conns {
|
||||||
|
c.close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// C represents a single connection.
|
||||||
type C struct {
|
type C struct {
|
||||||
tr trace.Trace
|
tr trace.Trace
|
||||||
n net.Conn
|
n net.Conn
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ func main() {
|
|||||||
fmt.Printf("Total: %.1f\n", totals.TotalPercent())
|
fmt.Printf("Total: %.1f\n", totals.TotalPercent())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Totals is used to keep track of total counters.
|
||||||
type Totals struct {
|
type Totals struct {
|
||||||
// Total statements.
|
// Total statements.
|
||||||
total int
|
total int
|
||||||
@@ -104,6 +105,7 @@ type Totals struct {
|
|||||||
coveredF map[string]int
|
coveredF map[string]int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add the given profile to the total counters.
|
||||||
func (t *Totals) Add(p *cover.Profile) {
|
func (t *Totals) Add(p *cover.Profile) {
|
||||||
for _, b := range p.Blocks {
|
for _, b := range p.Blocks {
|
||||||
t.total += b.NumStmt
|
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 {
|
func (t *Totals) Percent(f string) float32 {
|
||||||
return float32(t.coveredF[f]) / float32(t.totalF[f]) * 100
|
return float32(t.coveredF[f]) / float32(t.totalF[f]) * 100
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TotalPercent covered, across all files.
|
||||||
func (t *Totals) TotalPercent() float32 {
|
func (t *Totals) TotalPercent() float32 {
|
||||||
return float32(t.covered) / float32(t.total) * 100
|
return float32(t.covered) / float32(t.total) * 100
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ func serial(id int) {
|
|||||||
var count int64
|
var count int64
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
for {
|
for {
|
||||||
count += 1
|
count++
|
||||||
err := one()
|
err := one()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("%v", err)
|
log.Fatalf("%v", err)
|
||||||
|
|||||||
@@ -119,7 +119,11 @@ func (m *miniDNS) listenAndServeUDP(addr string) {
|
|||||||
log.Fatalf("error packing reply: %v", err)
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
vs := regexp.MustCompile("\\s+").Split(line, 3)
|
vs := regexp.MustCompile(`\s+`).Split(line, 3)
|
||||||
if len(vs) != 3 {
|
if len(vs) != 3 {
|
||||||
log.Fatalf("line %d: invalid format", lineno)
|
log.Fatalf("line %d: invalid format", lineno)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user