From beb9a3f0bac2d8c500499ad25809fbc75ca00524 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Wed, 12 Nov 2025 22:43:12 +0100 Subject: [PATCH] build: add even more linting rules Notably, shorten function signatures by not repeating types. --- common/clickhousedb/utils.go | 2 +- common/helpers/cache/cache_test.go | 2 +- console/widgets.go | 6 +++--- orchestrator/clickhouse/http.go | 2 +- orchestrator/clickhouse/migrations_helpers.go | 2 +- orchestrator/geoip/database.go | 2 +- orchestrator/geoip/root_test.go | 2 +- outlet/core/enricher.go | 7 +++---- outlet/routing/provider/bioris/root.go | 4 ++-- outlet/routing/provider/bmp/lookup.go | 2 +- outlet/routing/root.go | 2 +- revive.toml | 4 ++++ 12 files changed, 20 insertions(+), 17 deletions(-) diff --git a/common/clickhousedb/utils.go b/common/clickhousedb/utils.go index d935e871..ef656039 100644 --- a/common/clickhousedb/utils.go +++ b/common/clickhousedb/utils.go @@ -43,7 +43,7 @@ var ( // TransformQueryOnCluster turns a ClickHouse query into its equivalent to be // run on a cluster by adding the ON CLUSTER directive. -func TransformQueryOnCluster(query string, cluster string) string { +func TransformQueryOnCluster(query, cluster string) string { // From utils/antlr/ClickHouseParser.g4: // // ALTER TABLE tableIdentifier clusterClause? alterTableClause (COMMA alterTableClause)* diff --git a/common/helpers/cache/cache_test.go b/common/helpers/cache/cache_test.go index af68fcde..1d0c474a 100644 --- a/common/helpers/cache/cache_test.go +++ b/common/helpers/cache/cache_test.go @@ -12,7 +12,7 @@ import ( "akvorado/common/helpers/cache" ) -func expectCacheGet(t *testing.T, c *cache.Cache[netip.Addr, string], key string, expectedResult string, expectedOk bool) { +func expectCacheGet(t *testing.T, c *cache.Cache[netip.Addr, string], key, expectedResult string, expectedOk bool) { t.Helper() ip := netip.MustParseAddr(key) ip = helpers.AddrTo6(ip) diff --git a/console/widgets.go b/console/widgets.go index 8d6646a5..81dc8eab 100644 --- a/console/widgets.go +++ b/console/widgets.go @@ -152,9 +152,6 @@ func (c *Component) widgetTopHandlerFunc(gc *gin.Context) { } switch uriParams.WidgetName { - default: - gc.JSON(http.StatusNotFound, gin.H{"message": "Unknown top request."}) - return case HomepageTopWidgetSrcAS: selector = fmt.Sprintf(`concat(toString(SrcAS), ': ', dictGetOrDefault('%s', 'name', SrcAS, '???'))`, schema.DictionaryASNs) groupby = `SrcAS` @@ -181,6 +178,9 @@ func (c *Component) widgetTopHandlerFunc(gc *gin.Context) { selector = fmt.Sprintf(`concat(dictGetOrDefault('%s', 'name', Proto, '???'), '/', toString(DstPort))`, schema.DictionaryProtocols) groupby = `Proto, DstPort` mainTableRequired = true + default: + gc.JSON(http.StatusNotFound, gin.H{"message": "Unknown top request."}) + return } if strings.HasPrefix(gc.Param("name"), "src-") { filter = "AND InIfBoundary = 'external'" diff --git a/orchestrator/clickhouse/http.go b/orchestrator/clickhouse/http.go index 9bd22070..da02e64d 100644 --- a/orchestrator/clickhouse/http.go +++ b/orchestrator/clickhouse/http.go @@ -17,7 +17,7 @@ import ( "akvorado/common/embed" ) -func (c *Component) addHandlerEmbedded(url string, path string) { +func (c *Component) addHandlerEmbedded(url, path string) { data, _ := fs.Sub(embed.Data(), "orchestrator/clickhouse") c.d.HTTP.AddHandler(url, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { diff --git a/orchestrator/clickhouse/migrations_helpers.go b/orchestrator/clickhouse/migrations_helpers.go index 2a4b6f4e..dcf11ff0 100644 --- a/orchestrator/clickhouse/migrations_helpers.go +++ b/orchestrator/clickhouse/migrations_helpers.go @@ -97,7 +97,7 @@ func (c *Component) tableAlreadyExists(ctx context.Context, table, column, targe // mergeTreeEngine returns a MergeTree engine definition, either plain or using // Replicated if we are on a cluster. -func (c *Component) mergeTreeEngine(table string, variant string, args ...string) string { +func (c *Component) mergeTreeEngine(table, variant string, args ...string) string { if c.d.ClickHouse.ClusterName() != "" { return fmt.Sprintf(`Replicated%sMergeTree(%s)`, variant, strings.Join( append([]string{ diff --git a/orchestrator/geoip/database.go b/orchestrator/geoip/database.go index 1e5d5938..bf1d9db1 100644 --- a/orchestrator/geoip/database.go +++ b/orchestrator/geoip/database.go @@ -25,7 +25,7 @@ type geoDatabase interface { // openDatabase opens the provided database and closes the current // one. Do nothing if the path is empty. -func (c *Component) openDatabase(which string, path string, notifySubscribers bool) error { +func (c *Component) openDatabase(which, path string, notifySubscribers bool) error { if path == "" { return nil } diff --git a/orchestrator/geoip/root_test.go b/orchestrator/geoip/root_test.go index ae84a711..0ff2dacb 100644 --- a/orchestrator/geoip/root_test.go +++ b/orchestrator/geoip/root_test.go @@ -16,7 +16,7 @@ import ( "akvorado/common/reporter" ) -func copyFile(t *testing.T, src string, dst string) { +func copyFile(t *testing.T, src, dst string) { t.Helper() source, err := os.Open(src) if err != nil { diff --git a/outlet/core/enricher.go b/outlet/core/enricher.go index 7113cc26..e7676861 100644 --- a/outlet/core/enricher.go +++ b/outlet/core/enricher.go @@ -199,7 +199,7 @@ func (c *Component) getNetMask(flowMask, bmpMask uint8) (mask uint8) { return mask } -func (c *Component) getNextHop(flowNextHop netip.Addr, bmpNextHop netip.Addr) (nextHop netip.Addr) { +func (c *Component) getNextHop(flowNextHop, bmpNextHop netip.Addr) (nextHop netip.Addr) { nextHop = netip.IPv6Unspecified() for _, provider := range c.config.NetProviders { if !nextHop.IsUnspecified() { @@ -227,7 +227,7 @@ func (c *Component) writeExporter(flow *schema.FlowMessage, classification expor return true } -func (c *Component) classifyExporter(t time.Time, ip string, name string, flow *schema.FlowMessage, classification exporterClassification) bool { +func (c *Component) classifyExporter(t time.Time, ip, name string, flow *schema.FlowMessage, classification exporterClassification) bool { // we already have the info provided by the metadata component if (classification != exporterClassification{}) { return c.writeExporter(flow, classification) @@ -281,8 +281,7 @@ func (c *Component) writeInterface(flow *schema.FlowMessage, classification inte func (c *Component) classifyInterface( t time.Time, - ip string, - exporterName string, + ip, exporterName string, fl *schema.FlowMessage, ifIndex uint32, ifName, diff --git a/outlet/routing/provider/bioris/root.go b/outlet/routing/provider/bioris/root.go index aa82ed9c..b5bea19a 100644 --- a/outlet/routing/provider/bioris/root.go +++ b/outlet/routing/provider/bioris/root.go @@ -205,7 +205,7 @@ func (p *Provider) Refresh(ctx context.Context) { // Lookup does an lookup on one of the specified RIS Instances and returns the // well known bmp lookup result. NextHopIP is ignored, but maintained for // compatibility to the internal bmp -func (p *Provider) Lookup(ctx context.Context, ip netip.Addr, _ netip.Addr, agent netip.Addr) (provider.LookupResult, error) { +func (p *Provider) Lookup(ctx context.Context, ip, _, agent netip.Addr) (provider.LookupResult, error) { p.mu.RLock() defer p.mu.RUnlock() @@ -326,7 +326,7 @@ func (p *Provider) lpmResponseToLookupResult(lpm *pb.LPMResponse) (bmp.LookupRes } // lookupLPM does an lookupLPM GRPC call to a BioRis instance -func (p *Provider) lookupLPM(ctx context.Context, ip netip.Addr, agent netip.Addr) (*pb.LPMResponse, error) { +func (p *Provider) lookupLPM(ctx context.Context, ip, agent netip.Addr) (*pb.LPMResponse, error) { // Choose router id and ris chosenRouterID, chosenRis, err := p.chooseRouter(agent) if err != nil { diff --git a/outlet/routing/provider/bmp/lookup.go b/outlet/routing/provider/bmp/lookup.go index 7fc5b77d..5e1a169b 100644 --- a/outlet/routing/provider/bmp/lookup.go +++ b/outlet/routing/provider/bmp/lookup.go @@ -21,7 +21,7 @@ var errNoRouteFound = errors.New("no route found") // we use the best route we have, while the exporter may not have this // best route available. The returned result should not be modified! // The last parameter, the agent, is ignored by this provider. -func (p *Provider) Lookup(_ context.Context, ip netip.Addr, nh netip.Addr, _ netip.Addr) (LookupResult, error) { +func (p *Provider) Lookup(_ context.Context, ip, nh, _ netip.Addr) (LookupResult, error) { if !p.config.CollectASNs && !p.config.CollectASPaths && !p.config.CollectCommunities { return LookupResult{}, nil } diff --git a/outlet/routing/root.go b/outlet/routing/root.go index 3d279c9d..89845b22 100644 --- a/outlet/routing/root.go +++ b/outlet/routing/root.go @@ -75,7 +75,7 @@ type stopper interface { } // Lookup uses the selected provider to get an answer. -func (c *Component) Lookup(ctx context.Context, ip netip.Addr, nh netip.Addr, agent netip.Addr) provider.LookupResult { +func (c *Component) Lookup(ctx context.Context, ip, nh, agent netip.Addr) provider.LookupResult { c.metrics.routingLookups.Inc() result, err := c.provider.Lookup(ctx, ip, nh, agent) if err != nil { diff --git a/revive.toml b/revive.toml index eaa8007d..d788d2c4 100644 --- a/revive.toml +++ b/revive.toml @@ -11,6 +11,10 @@ confidence = 0.8 [rule.defer] [rule.dot-imports] [rule.empty-block] +[rule.enforce-repeated-arg-type-style] +arguments = ["short"] +[rule.enforce-switch-style] +arguments = ["allowNoDefault"] [rule.error-naming] [rule.error-return] [rule.error-strings]