From 096c856fc3acb5b067e5cca811ce0d0de1858bb7 Mon Sep 17 00:00:00 2001 From: Andrew Nesbitt Date: Fri, 22 May 2026 11:27:29 +0100 Subject: [PATCH 1/2] Add golangci-lint config enabling stricter linters Enables the same linter set used across other git-pkgs applications (gocritic, gocognit, gocyclo, maintidx, dupl, mnd, unparam, ireturn, goconst, errcheck) and configures goconst to skip test files. --- .golangci.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..69e69b6 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,17 @@ +version: "2" + +linters: + enable: + - gocritic + - gocognit + - gocyclo + - maintidx + - dupl + - mnd + - unparam + - ireturn + - goconst + - errcheck + settings: + goconst: + ignore-tests: true From 3e69de31d2567a8533782c73fe2a683b35e598fa Mon Sep 17 00:00:00 2001 From: Andrew Nesbitt Date: Fri, 22 May 2026 11:54:32 +0100 Subject: [PATCH 2/2] 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. --- .golangci.yml | 8 ++++++++ generic_manager.go | 10 ++++++---- policy.go | 11 ++++++----- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 69e69b6..f7dd188 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -15,3 +15,11 @@ linters: settings: goconst: ignore-tests: true + exclusions: + rules: + - path: _test\.go + linters: + - dupl + - path: ^docs/examples/ + linters: + - goconst diff --git a/generic_manager.go b/generic_manager.go index 6b40f20..7462122 100644 --- a/generic_manager.go +++ b/generic_manager.go @@ -6,6 +6,8 @@ import ( "github.com/git-pkgs/managers/definitions" ) +const argPackage = "package" + type GenericManager struct { def *definitions.Definition dir string @@ -65,7 +67,7 @@ func (m *GenericManager) Install(ctx context.Context, opts InstallOptions) (*Res func (m *GenericManager) Add(ctx context.Context, pkg string, opts AddOptions) (*Result, error) { input := CommandInput{ Args: map[string]string{ - "package": pkg, + argPackage: pkg, }, Flags: map[string]any{ "dev": opts.Dev, @@ -90,7 +92,7 @@ func (m *GenericManager) Add(ctx context.Context, pkg string, opts AddOptions) ( func (m *GenericManager) Remove(ctx context.Context, pkg string) (*Result, error) { input := CommandInput{ Args: map[string]string{ - "package": pkg, + argPackage: pkg, }, Flags: map[string]any{}, } @@ -138,7 +140,7 @@ func (m *GenericManager) Update(ctx context.Context, pkg string) (*Result, error } if pkg != "" { - input.Args["package"] = pkg + input.Args[argPackage] = pkg } cmd, err := m.translator.BuildCommand(m.def.Name, "update", input) @@ -200,7 +202,7 @@ func (m *GenericManager) Resolve(ctx context.Context) (*Result, error) { func (m *GenericManager) Path(ctx context.Context, pkg string) (*PathResult, error) { input := CommandInput{ Args: map[string]string{ - "package": pkg, + argPackage: pkg, }, Flags: map[string]any{}, } diff --git a/policy.go b/policy.go index 607cafc..d94a038 100644 --- a/policy.go +++ b/policy.go @@ -152,16 +152,17 @@ func (pr *PolicyRunner) Run(ctx context.Context, dir string, args ...string) (*R } // Extract manager and operation from command if possible - if len(args) > 0 { - op.Manager = args[0] + rest := args + if len(rest) > 0 { + op.Manager, rest = rest[0], rest[1:] } - if len(args) > 1 { - op.Operation = args[1] + if len(rest) > 0 { + op.Operation, rest = rest[0], rest[1:] } // Populate Packages from positional args so policies that inspect // package names (e.g. PackageBlocklistPolicy) actually see them when // invoked through the Runner interface. - for _, a := range args[min(2, len(args)):] { + for _, a := range rest { if a == "" || strings.HasPrefix(a, "-") { continue }