Skip to content

Commit 3e69de3

Browse files
committed
Fix lint findings surfaced by stricter golangci-lint config
Extracts an argPackage constant for the repeated "package" template-arg key, reworks PolicyRunner.Run to slice off the manager and operation tokens incrementally instead of indexing from a hard-coded offset, and excludes dupl from tests and goconst from docs/examples since literal repetition is the clearer choice in both places.
1 parent 096c856 commit 3e69de3

3 files changed

Lines changed: 20 additions & 9 deletions

File tree

.golangci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,11 @@ linters:
1515
settings:
1616
goconst:
1717
ignore-tests: true
18+
exclusions:
19+
rules:
20+
- path: _test\.go
21+
linters:
22+
- dupl
23+
- path: ^docs/examples/
24+
linters:
25+
- goconst

generic_manager.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"github.com/git-pkgs/managers/definitions"
77
)
88

9+
const argPackage = "package"
10+
911
type GenericManager struct {
1012
def *definitions.Definition
1113
dir string
@@ -65,7 +67,7 @@ func (m *GenericManager) Install(ctx context.Context, opts InstallOptions) (*Res
6567
func (m *GenericManager) Add(ctx context.Context, pkg string, opts AddOptions) (*Result, error) {
6668
input := CommandInput{
6769
Args: map[string]string{
68-
"package": pkg,
70+
argPackage: pkg,
6971
},
7072
Flags: map[string]any{
7173
"dev": opts.Dev,
@@ -90,7 +92,7 @@ func (m *GenericManager) Add(ctx context.Context, pkg string, opts AddOptions) (
9092
func (m *GenericManager) Remove(ctx context.Context, pkg string) (*Result, error) {
9193
input := CommandInput{
9294
Args: map[string]string{
93-
"package": pkg,
95+
argPackage: pkg,
9496
},
9597
Flags: map[string]any{},
9698
}
@@ -138,7 +140,7 @@ func (m *GenericManager) Update(ctx context.Context, pkg string) (*Result, error
138140
}
139141

140142
if pkg != "" {
141-
input.Args["package"] = pkg
143+
input.Args[argPackage] = pkg
142144
}
143145

144146
cmd, err := m.translator.BuildCommand(m.def.Name, "update", input)
@@ -200,7 +202,7 @@ func (m *GenericManager) Resolve(ctx context.Context) (*Result, error) {
200202
func (m *GenericManager) Path(ctx context.Context, pkg string) (*PathResult, error) {
201203
input := CommandInput{
202204
Args: map[string]string{
203-
"package": pkg,
205+
argPackage: pkg,
204206
},
205207
Flags: map[string]any{},
206208
}

policy.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,17 @@ func (pr *PolicyRunner) Run(ctx context.Context, dir string, args ...string) (*R
152152
}
153153

154154
// Extract manager and operation from command if possible
155-
if len(args) > 0 {
156-
op.Manager = args[0]
155+
rest := args
156+
if len(rest) > 0 {
157+
op.Manager, rest = rest[0], rest[1:]
157158
}
158-
if len(args) > 1 {
159-
op.Operation = args[1]
159+
if len(rest) > 0 {
160+
op.Operation, rest = rest[0], rest[1:]
160161
}
161162
// Populate Packages from positional args so policies that inspect
162163
// package names (e.g. PackageBlocklistPolicy) actually see them when
163164
// invoked through the Runner interface.
164-
for _, a := range args[min(2, len(args)):] {
165+
for _, a := range rest {
165166
if a == "" || strings.HasPrefix(a, "-") {
166167
continue
167168
}

0 commit comments

Comments
 (0)