mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
build: add more linting rules with revive
This commit is contained in:
4
Makefile
4
Makefile
@@ -239,8 +239,8 @@ test-coverage-js: ; $(info $(M) running JS coverage tests…) @ ## Run JS covera
|
||||
|
||||
.PHONY: lint
|
||||
lint: .lint-go~ .lint-js~ ## Run linting
|
||||
.lint-go~: $(shell $(LSFILES) '*.go' 2> /dev/null) ; $(info $(M) running golint…)
|
||||
$Q $(REVIVE) -formatter stylish -set_exit_status ./...
|
||||
.lint-go~: revive.toml $(shell $(LSFILES) '*.go' 2> /dev/null) ; $(info $(M) running golint…)
|
||||
$Q $(REVIVE) -config $(PWD)/revive.toml -formatter stylish -set_exit_status ./...
|
||||
$Q touch $@
|
||||
.lint-js~: $(shell $(LSFILES) '*.js' '*.ts' '*.vue' '*.html' 2> /dev/null)
|
||||
.lint-js~: $(GENERATED_JS) ; $(info $(M) running jslint…)
|
||||
|
||||
@@ -147,7 +147,8 @@ var subnetLookAlikeRegex = regexp.MustCompile("^([a-fA-F:.0-9]*[:.][a-fA-F:.0-9]
|
||||
|
||||
// LooksLikeSubnetMap returns true iff the provided value could be a SubnetMap
|
||||
// (but not 100% sure).
|
||||
func LooksLikeSubnetMap(v reflect.Value) (result bool) {
|
||||
func LooksLikeSubnetMap(v reflect.Value) bool {
|
||||
var result bool
|
||||
if v.Kind() == reflect.Map {
|
||||
// When we have a map, we check if all keys look like a subnet.
|
||||
result = true
|
||||
@@ -163,7 +164,7 @@ func LooksLikeSubnetMap(v reflect.Value) (result bool) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
return result
|
||||
}
|
||||
|
||||
// SubnetMapUnmarshallerHook decodes SubnetMap and notably check that valid
|
||||
|
||||
@@ -55,7 +55,8 @@ func (m *Metrics) HTTPHandler() http.Handler {
|
||||
})
|
||||
}
|
||||
|
||||
func getPrefix(module string) (moduleName string) {
|
||||
func getPrefix(module string) string {
|
||||
var moduleName string
|
||||
if !strings.HasPrefix(module, stack.ModuleName) {
|
||||
moduleName = stack.ModuleName
|
||||
} else {
|
||||
@@ -64,7 +65,7 @@ func getPrefix(module string) (moduleName string) {
|
||||
moduleName = strings.ReplaceAll(moduleName, "/", "_")
|
||||
moduleName = strings.ReplaceAll(moduleName, ".", "_")
|
||||
moduleName = fmt.Sprintf("%s_", moduleName)
|
||||
return
|
||||
return moduleName
|
||||
}
|
||||
|
||||
// Factory returns a factory to register new metrics with promauto. It
|
||||
|
||||
@@ -188,6 +188,7 @@ func TestMultipleServers(t *testing.T) {
|
||||
for range 10 {
|
||||
r := reporter.NewMock(t)
|
||||
sch := schema.NewMock(t)
|
||||
func() {
|
||||
ctx, cancel := context.WithTimeout(t.Context(), 5*time.Second)
|
||||
defer cancel()
|
||||
ctx = clickhousego.Context(ctx, clickhousego.WithSettings(clickhousego.Settings{
|
||||
@@ -223,6 +224,7 @@ func TestMultipleServers(t *testing.T) {
|
||||
bf.Finalize()
|
||||
w := ch.NewWorker(1, bf)
|
||||
w.Flush(ctx)
|
||||
}()
|
||||
|
||||
// Check metrics
|
||||
gotMetrics := r.GetMetrics("akvorado_outlet_clickhouse_", "errors_total")
|
||||
|
||||
@@ -19,11 +19,14 @@ type exporterAndInterfaceInfo struct {
|
||||
}
|
||||
|
||||
// enrichFlow adds more data to a flow.
|
||||
func (w *worker) enrichFlow(exporterIP netip.Addr, exporterStr string) (skip bool) {
|
||||
var flowExporterName string
|
||||
var flowInIfName, flowInIfDescription, flowOutIfName, flowOutIfDescription string
|
||||
var flowInIfSpeed, flowOutIfSpeed, flowInIfIndex, flowOutIfIndex uint32
|
||||
var flowInIfVlan, flowOutIfVlan uint16
|
||||
func (w *worker) enrichFlow(exporterIP netip.Addr, exporterStr string) bool {
|
||||
var (
|
||||
flowExporterName string
|
||||
flowInIfName, flowInIfDescription, flowOutIfName, flowOutIfDescription string
|
||||
flowInIfSpeed, flowOutIfSpeed, flowInIfIndex, flowOutIfIndex uint32
|
||||
flowInIfVlan, flowOutIfVlan uint16
|
||||
)
|
||||
var skip bool
|
||||
|
||||
t := time.Now() // only call it once
|
||||
expClassification := exporterClassification{}
|
||||
@@ -102,7 +105,7 @@ func (w *worker) enrichFlow(exporterIP netip.Addr, exporterStr string) (skip boo
|
||||
}
|
||||
|
||||
if skip {
|
||||
return
|
||||
return true
|
||||
}
|
||||
|
||||
// Classification
|
||||
@@ -148,7 +151,7 @@ func (w *worker) enrichFlow(exporterIP netip.Addr, exporterStr string) (skip boo
|
||||
flow.AppendUint(schema.ColumnInIfSpeed, uint64(flowInIfSpeed))
|
||||
flow.AppendUint(schema.ColumnOutIfSpeed, uint64(flowOutIfSpeed))
|
||||
|
||||
return
|
||||
return skip
|
||||
}
|
||||
|
||||
// getASNumber retrieves the AS number for a flow, depending on user preferences.
|
||||
|
||||
@@ -46,6 +46,7 @@ func TestMock(t *testing.T) {
|
||||
}
|
||||
|
||||
c.Stop()
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
if !shutdownCalled {
|
||||
t.Error("Stop() should have triggered shutdown function")
|
||||
}
|
||||
|
||||
@@ -72,9 +72,7 @@ func (s *scalerState) nextWorkerCount(request ScaleRequest, currentWorkers, minW
|
||||
func scaleWhileDraining(ctx context.Context, ch <-chan ScaleRequest, scaleFn func()) {
|
||||
var wg sync.WaitGroup
|
||||
done := make(chan struct{})
|
||||
wg.Add(2)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
wg.Go(func() {
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
@@ -85,12 +83,11 @@ func scaleWhileDraining(ctx context.Context, ch <-chan ScaleRequest, scaleFn fun
|
||||
// Discard signal
|
||||
}
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
})
|
||||
wg.Go(func() {
|
||||
scaleFn()
|
||||
close(done)
|
||||
}()
|
||||
})
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
|
||||
@@ -36,8 +36,8 @@ func (c *mockComponent) StartWorkers(workerBuilder WorkerBuilderFunc) error {
|
||||
}()
|
||||
for i := range c.config.MinWorkers {
|
||||
callback, shutdown := workerBuilder(i, ch)
|
||||
defer shutdown()
|
||||
go func() {
|
||||
defer shutdown()
|
||||
for {
|
||||
message, ok := <-c.incoming
|
||||
if !ok {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
package gnmi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
"net/netip"
|
||||
"reflect"
|
||||
"time"
|
||||
@@ -197,7 +197,7 @@ func AuthenticationParameterUnmarshallerHook() mapstructure.DecodeHookFunc {
|
||||
|
||||
// If we have new TLS key and any old keys, that's an error
|
||||
if tlsKey != nil && (insecureKey != nil || skipVerifyKey != nil || tlsCAKey != nil || tlsCertKey != nil || tlsKeyKey != nil) {
|
||||
return nil, fmt.Errorf("cannot mix old TLS configuration (Insecure, SkipVerify, TLSCA, TLSCert, TLSKey) with new TLS configuration")
|
||||
return nil, errors.New("cannot mix old TLS configuration (Insecure, SkipVerify, TLSCA, TLSCert, TLSKey) with new TLS configuration")
|
||||
}
|
||||
|
||||
// If no old keys, we need to set default TLS.Enable
|
||||
|
||||
35
revive.toml
Normal file
35
revive.toml
Normal file
@@ -0,0 +1,35 @@
|
||||
enableDefaultRules = true
|
||||
ignoreGeneratedHeader = false
|
||||
confidence = 0.8
|
||||
|
||||
[rule.atomic]
|
||||
[rule.bare-return]
|
||||
[rule.blank-imports]
|
||||
[rule.bool-literal-in-expr]
|
||||
[rule.context-as-argument]
|
||||
[rule.context-keys-type]
|
||||
[rule.defer]
|
||||
[rule.dot-imports]
|
||||
[rule.empty-block]
|
||||
[rule.error-naming]
|
||||
[rule.error-return]
|
||||
[rule.error-strings]
|
||||
[rule.errorf]
|
||||
[rule.exported]
|
||||
[rule.increment-decrement]
|
||||
[rule.indent-error-flow]
|
||||
[rule.package-comments]
|
||||
[rule.range]
|
||||
[rule.receiver-naming]
|
||||
[rule.redefines-builtin-id]
|
||||
[rule.superfluous-else]
|
||||
[rule.time-equal]
|
||||
[rule.time-naming]
|
||||
[rule.unexported-return]
|
||||
[rule.unreachable-code]
|
||||
[rule.unused-parameter]
|
||||
[rule.use-any]
|
||||
[rule.use-errors-new]
|
||||
[rule.use-waitgroup-go]
|
||||
[rule.var-declaration]
|
||||
[rule.var-naming]
|
||||
Reference in New Issue
Block a user