Skip to content

Commit b5ef298

Browse files
feat: add lint command with go-errorlint analyzer (#693)
- Add new 'orchestrion lint' command - Use multichecker framework to run static analysis checks - Include custom help formatting to maintain Orchestrion CLI consistency - Add go-errorlint as the first linter - Enable comparison and asserts checks by default for error handling validation Needs polyfloyd/go-errorlint#107 before merging. Signed-off-by: Kemal Akkoyun <[email protected]> --------- Signed-off-by: Kemal Akkoyun <[email protected]> Co-authored-by: dd-k9-library-go[bot] <214463715+dd-k9-library-go[bot]@users.noreply.github.com>
1 parent 89c03a2 commit b5ef298

File tree

11 files changed

+76
-0
lines changed

11 files changed

+76
-0
lines changed

LICENSE-3rdparty.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ orchestrion,github.com/outcaste-io/ristretto/z,MIT,unknown
6666
orchestrion,github.com/philhofer/fwd,MIT,"Copyright (c) 2014-2015, Philip Hofer"
6767
orchestrion,github.com/pkg/errors,BSD-2-Clause,"Copyright (c) 2015, Dave Cheney <[email protected]>"
6868
orchestrion,github.com/planetscale/vtprotobuf/protohelpers,BSD-3-Clause,"Copyright (c) 2021, PlanetScale Inc. All rights reserved. | Copyright (c) 2013, The GoGo Authors. All rights reserved. | Copyright (c) 2018 The Go Authors. All rights reserved."
69+
orchestrion,github.com/polyfloyd/go-errorlint/errorlint,MIT,Copyright (c) 2019 polyfloyd
6970
orchestrion,github.com/puzpuzpuz/xsync/v3,Apache-2.0,unknown
7071
orchestrion,github.com/rivo/uniseg,MIT,Copyright (c) 2019 Oliver Kuederle
7172
orchestrion,github.com/rs/zerolog,MIT,Copyright (c) 2017 Olivier Poitrey

_docs/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ require (
333333
github.com/pkg/errors v0.9.1 // indirect
334334
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
335335
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
336+
github.com/polyfloyd/go-errorlint v1.8.1-0.20250906200200-9b25878c4dea // indirect
336337
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
337338
github.com/prometheus/common v0.62.0 // indirect
338339
github.com/puzpuzpuz/xsync/v3 v3.5.1 // indirect

_docs/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,8 @@ github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1
10721072
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
10731073
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
10741074
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1075+
github.com/polyfloyd/go-errorlint v1.8.1-0.20250906200200-9b25878c4dea h1:0hdZfdf74rU/bEndy2uZJyNeY21jmH751KmdAjOmEiA=
1076+
github.com/polyfloyd/go-errorlint v1.8.1-0.20250906200200-9b25878c4dea/go.mod h1:msT1JMnFNM1gqj7rtZYaA0EtpIYNeLQSsKJChZNA+5A=
10751077
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 h1:o4JXh1EVt9k/+g42oCprj/FisM4qX9L3sZB3upGN2ZU=
10761078
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
10771079
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require (
1515
github.com/nats-io/nats-server/v2 v2.11.8
1616
github.com/nats-io/nats.go v1.45.0
1717
github.com/otiai10/copy v1.14.1
18+
github.com/polyfloyd/go-errorlint v1.8.1-0.20250906200200-9b25878c4dea
1819
github.com/rs/zerolog v1.34.0
1920
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2
2021
github.com/shirou/gopsutil/v4 v4.25.8

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1
185185
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
186186
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
187187
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
188+
github.com/polyfloyd/go-errorlint v1.8.1-0.20250906200200-9b25878c4dea h1:0hdZfdf74rU/bEndy2uZJyNeY21jmH751KmdAjOmEiA=
189+
github.com/polyfloyd/go-errorlint v1.8.1-0.20250906200200-9b25878c4dea/go.mod h1:msT1JMnFNM1gqj7rtZYaA0EtpIYNeLQSsKJChZNA+5A=
188190
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 h1:o4JXh1EVt9k/+g42oCprj/FisM4qX9L3sZB3upGN2ZU=
189191
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
190192
github.com/puzpuzpuz/xsync/v3 v3.5.1 h1:GJYJZwO6IdxN/IKbneznS6yPkVC+c3zyY/j19c++5Fg=

instrument/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ require (
221221
github.com/pkg/errors v0.9.1 // indirect
222222
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
223223
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
224+
github.com/polyfloyd/go-errorlint v1.8.1-0.20250906200200-9b25878c4dea // indirect
224225
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
225226
github.com/puzpuzpuz/xsync/v3 v3.5.1 // indirect
226227
github.com/rcrowley/go-metrics v0.0.0-20250401214520-65e299d6c5c9 // indirect

instrument/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,8 @@ github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1
793793
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
794794
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
795795
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
796+
github.com/polyfloyd/go-errorlint v1.8.1-0.20250906200200-9b25878c4dea h1:0hdZfdf74rU/bEndy2uZJyNeY21jmH751KmdAjOmEiA=
797+
github.com/polyfloyd/go-errorlint v1.8.1-0.20250906200200-9b25878c4dea/go.mod h1:msT1JMnFNM1gqj7rtZYaA0EtpIYNeLQSsKJChZNA+5A=
796798
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 h1:o4JXh1EVt9k/+g42oCprj/FisM4qX9L3sZB3upGN2ZU=
797799
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
798800
github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q=

internal/cmd/lint.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed
2+
// under the Apache License Version 2.0.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
// Copyright 2023-present Datadog, Inc.
5+
6+
package cmd
7+
8+
import (
9+
"fmt"
10+
"os"
11+
"slices"
12+
"strings"
13+
"text/template"
14+
15+
"github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"
16+
"github.com/polyfloyd/go-errorlint/errorlint"
17+
"github.com/urfave/cli/v2"
18+
"golang.org/x/tools/go/analysis"
19+
"golang.org/x/tools/go/analysis/multichecker"
20+
)
21+
22+
var Lint = &cli.Command{
23+
Name: "lint",
24+
Usage: "Run selected static analysis checks on Go code for Orchestrion to work better for certain features.",
25+
UsageText: "orchestrion lint [lint arguments...]",
26+
Args: true,
27+
SkipFlagParsing: true,
28+
Action: func(clictx *cli.Context) (err error) {
29+
span, _ := tracer.StartSpanFromContext(clictx.Context, "lint",
30+
tracer.ResourceName(strings.Join(clictx.Args().Slice(), " ")),
31+
)
32+
defer func() { span.Finish(tracer.WithError(err)) }()
33+
34+
// Check if help was requested and print Orchestrion-style header.
35+
args := clictx.Args().Slice()
36+
if slices.Contains(args, "-help") || slices.Contains(args, "--help") || slices.Contains(args, "-h") {
37+
tmpl := template.Must(template.New("help").Parse(cli.CommandHelpTemplate))
38+
if err := tmpl.Execute(os.Stdout, clictx.Command); err != nil {
39+
fmt.Printf("NAME:\n orchestrion lint - %s\n\n", clictx.Command.Usage)
40+
fmt.Printf("USAGE:\n %s\n\n", clictx.Command.UsageText)
41+
fmt.Println()
42+
}
43+
}
44+
45+
// Set up os.Args to include the lint subcommand args.
46+
// Replace "orchestrion lint" with "orchestrion-lint",
47+
// so multichecker sees proper args
48+
args = append([]string{"orchestrion-lint"}, args...)
49+
os.Args = args
50+
51+
// Run multichecker. This will take over with its own flags.
52+
analyzers := []*analysis.Analyzer{
53+
errorlint.NewAnalyzer(
54+
errorlint.WithComparison(true),
55+
errorlint.WithAsserts(true),
56+
),
57+
}
58+
multichecker.Main(analyzers...)
59+
60+
return nil
61+
},
62+
}

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ func main() {
145145
cmd.Version,
146146
cmd.Server,
147147
cmd.Diff,
148+
cmd.Lint,
148149
},
149150
Before: func(ctx *cli.Context) error {
150151
profiles := ctx.StringSlice("profile")

samples/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ require (
245245
github.com/pkg/errors v0.9.1 // indirect
246246
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
247247
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
248+
github.com/polyfloyd/go-errorlint v1.8.1-0.20250906200200-9b25878c4dea // indirect
248249
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
249250
github.com/puzpuzpuz/xsync/v3 v3.5.1 // indirect
250251
github.com/rcrowley/go-metrics v0.0.0-20250401214520-65e299d6c5c9 // indirect

0 commit comments

Comments
 (0)