Skip to content

Commit

Permalink
maint: mark function arguments as unused where applicable (#918)
Browse files Browse the repository at this point in the history
The easiest and safest approach to satisfy the revive linter, as these
functions must have this exact signature. The occurrences were mostly
split between Cobra and tests, hence the separate commits for easier
review.

Fixes UDENG-2287

Note that the latest version of golangci-lint (currently 1.56.2) pulls
in a version of gosec where the `#nosec` directive is sort of
[broken](securego/gosec#1105), hence the
additional influx of warnings in the [dependabot
PR](#915).
  • Loading branch information
GabrielNagy authored Feb 21, 2024
2 parents b5de9aa + bf0da61 commit 19cfcf7
Show file tree
Hide file tree
Showing 30 changed files with 65 additions and 65 deletions.
8 changes: 4 additions & 4 deletions cmd/admxgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func main() {
Long: gotext.Get(`Generate ADMX and intermediary working files from a list of policy definition files.`),
Args: cmdhandler.SubcommandsRequiredWithSuggestions,
RunE: cmdhandler.NoCmd,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
PersistentPreRunE: func(_ *cobra.Command, _ []string) error {
config.SetVerboseMode(viper.GetInt("verbose"))
return nil
},
Expand Down Expand Up @@ -75,7 +75,7 @@ func installExpand(rootCmd *cobra.Command, viper *viper.Viper) error {
Long: gotext.Get(`Generates an intermediary policy definition file into DEST directory from all the policy definition files in SOURCE directory, using the correct decoder.
The generated definition file will be of the form expanded_policies.RELEASE.yaml`),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
return admxgen.Expand(args[0], args[1], viper.GetString("root"), viper.GetString("current-session"))
},
}
Expand All @@ -97,7 +97,7 @@ func installAdmx(rootCmd *cobra.Command, viper *viper.Viper) error {
Short: gotext.Get("Create finale admx and adml files"),
Long: gotext.Get("Collects all intermediary policy definition files in SOURCE directory to create admx and adml templates in DEST, based on CATEGORIES_DEF.yaml."),
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
return admxgen.GenerateAD(args[0], args[1], args[2], *autoDetectReleases, *allowMissingKeys)
},
}
Expand All @@ -117,7 +117,7 @@ func installDoc(rootCmd *cobra.Command, viper *viper.Viper) error {
Short: gotext.Get("Create markdown documentation"),
Long: gotext.Get("Collects all intermediary policy definition files in SOURCE directory to create markdown documentation in DEST, based on CATEGORIES_DEF.yaml."),
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
return admxgen.GenerateDoc(args[0], args[1], args[2])
},
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/adsysd/client/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (a *App) installDoc() {
Use: "doc [CHAPTER]",
Short: gotext.Get("Documentation"),
Args: cobra.MaximumNArgs(1),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
ValidArgsFunction: func(_ *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
Expand All @@ -38,7 +38,7 @@ func (a *App) installDoc() {
}
return r.GetChapters(), cobra.ShellCompDirectiveNoFileComp
},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
var chapter string
if len(args) > 0 {
chapter = args[0]
Expand Down
2 changes: 1 addition & 1 deletion cmd/adsysd/client/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func (a *App) AddWaitCommand() {
a.rootCmd.AddCommand(&cobra.Command{
Use: "wait",
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
select {
case <-time.After(50 * time.Millisecond):
return errors.New("End of wait command reached")
Expand Down
20 changes: 10 additions & 10 deletions cmd/adsysd/client/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ func (a *App) installPolicy() {
Use: "admx lts-only|all",
Short: gotext.Get("Dump windows policy definitions"),
Args: cobra.ExactArgs(1),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
ValidArgsFunction: func(_ *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
return []string{"lts-only", "all"}, cobra.ShellCompDirectiveNoFileComp
},
RunE: func(cmd *cobra.Command, args []string) error { return a.getPolicyDefinitions(args[0], *distro) },
RunE: func(_ *cobra.Command, args []string) error { return a.getPolicyDefinitions(args[0], *distro) },
}
distro = mainCmd.Flags().StringP("distro", "", consts.DistroID, gotext.Get("distro for which to retrieve policy definition."))
policyCmd.AddCommand(mainCmd)
Expand All @@ -52,14 +52,14 @@ func (a *App) installPolicy() {
Use: "applied [USER_NAME]",
Short: gotext.Get("Print last applied GPOs for current or given user/machine"),
Args: cmdhandler.ZeroOrNArgs(1),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
ValidArgsFunction: func(_ *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}

return a.users(true), cobra.ShellCompDirectiveNoFileComp
},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
var target string
if len(args) > 0 {
target = args[0]
Expand Down Expand Up @@ -87,15 +87,15 @@ func (a *App) installPolicy() {
Short: gotext.Get("Write GPO list python embedded script in current directory"),
Args: cobra.NoArgs,
ValidArgsFunction: cmdhandler.NoValidArgs,
RunE: func(cmd *cobra.Command, args []string) error { return a.dumpGPOListScript() },
RunE: func(_ *cobra.Command, _ []string) error { return a.dumpGPOListScript() },
}
debugCmd.AddCommand(gpoListCmd)
certEnrollCmd := &cobra.Command{
Use: "cert-autoenroll-script",
Short: gotext.Get("Write certificate autoenrollment python embedded script in current directory"),
Args: cobra.NoArgs,
ValidArgsFunction: cmdhandler.NoValidArgs,
RunE: func(cmd *cobra.Command, args []string) error { return a.dumpCertEnrollScript() },
RunE: func(_ *cobra.Command, _ []string) error { return a.dumpCertEnrollScript() },
}
debugCmd.AddCommand(certEnrollCmd)
ticketPathCmd := &cobra.Command{
Expand All @@ -120,7 +120,7 @@ The command is a no-op if the ticket is not present on disk or the detect_cached
Use: "update [USER_NAME KERBEROS_TICKET_PATH]",
Short: gotext.Get("Updates/Create a policy for current user or given user with its kerberos ticket"),
Args: cmdhandler.ZeroOrNArgs(2),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
ValidArgsFunction: func(_ *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective) {
// All and machine options don’t take arguments
if *updateAll || *updateMachine {
return nil, cobra.ShellCompDirectiveNoFileComp
Expand All @@ -137,7 +137,7 @@ The command is a no-op if the ticket is not present on disk or the detect_cached
// We already have our 2 args: no more arg completion
return nil, cobra.ShellCompDirectiveNoFileComp
},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
var user, krb5cc string
if len(args) > 0 {
user, krb5cc = args[0], args[1]
Expand All @@ -155,7 +155,7 @@ The command is a no-op if the ticket is not present on disk or the detect_cached
Use: "purge [USER_NAME]",
Short: gotext.Get("Purges policies for the current user or a specified one"),
Args: cmdhandler.ZeroOrNArgs(1),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
ValidArgsFunction: func(_ *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective) {
// All and machine options don’t take arguments
if *purgeAll || *purgeMachine || len(args) != 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
Expand All @@ -164,7 +164,7 @@ The command is a no-op if the ticket is not present on disk or the detect_cached
// Get all users with cached policies
return a.users(false), cobra.ShellCompDirectiveNoFileComp
},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
var user string
if len(args) > 0 {
user = args[0]
Expand Down
6 changes: 3 additions & 3 deletions cmd/adsysd/client/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (a *App) installService() {
Short: gotext.Get("Print service logs"),
Args: cobra.NoArgs,
ValidArgsFunction: cmdhandler.NoValidArgs,
RunE: func(cmd *cobra.Command, args []string) error { return a.serviceCat() },
RunE: func(_ *cobra.Command, _ []string) error { return a.serviceCat() },
}
mainCmd.AddCommand(cmd)

Expand All @@ -37,7 +37,7 @@ func (a *App) installService() {
Short: gotext.Get("Print service status"),
Args: cobra.NoArgs,
ValidArgsFunction: cmdhandler.NoValidArgs,
RunE: func(cmd *cobra.Command, args []string) error { return a.getStatus() },
RunE: func(_ *cobra.Command, _ []string) error { return a.getStatus() },
}
mainCmd.AddCommand(cmd)

Expand All @@ -47,7 +47,7 @@ func (a *App) installService() {
Short: gotext.Get("Requests to stop the service once all connections are done"),
Args: cobra.NoArgs,
ValidArgsFunction: cmdhandler.NoValidArgs,
RunE: func(cmd *cobra.Command, args []string) error { return a.serviceStop(*stopForce) },
RunE: func(_ *cobra.Command, _ []string) error { return a.serviceStop(*stopForce) },
}
stopForce = cmd.Flags().BoolP("force", "f", false, gotext.Get("force will shut it down immediately and drop existing connections."))
mainCmd.AddCommand(cmd)
Expand Down
2 changes: 1 addition & 1 deletion cmd/adsysd/client/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (a *App) installVersion() {
Short: gotext.Get("Returns version of client and service"),
Args: cobra.NoArgs,
ValidArgsFunction: cmdhandler.NoValidArgs,
RunE: func(cmd *cobra.Command, args []string) error { return a.getVersion() },
RunE: func(_ *cobra.Command, _ []string) error { return a.getVersion() },
}
a.rootCmd.AddCommand(cmd)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/adsysd/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func New() *App {
Use: fmt.Sprintf("%s COMMAND", CmdName),
Short: gotext.Get("AD integration daemon"),
Long: gotext.Get(`Active Directory integration bridging toolset daemon.`),
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
PersistentPreRunE: func(_ *cobra.Command, _ []string) error {
// command parsing has been successful. Returns runtime (or configuration) error now and so, don’t print usage.
a.rootCmd.SilenceUsage = true
err := config.Init("adsys", a.rootCmd, a.viper, func(refreshed bool) error {
Expand Down Expand Up @@ -110,7 +110,7 @@ func New() *App {
return err
},

RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
adsys, err := adsysservice.New(context.Background(),
adsysservice.WithCacheDir(a.config.CacheDir),
adsysservice.WithStateDir(a.config.StateDir),
Expand Down
2 changes: 1 addition & 1 deletion cmd/adsysd/daemon/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func (a *App) installMount() {
Short: "Mount the locations listed in the specified file for the current user",
Args: cobra.ExactArgs(1),
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error { return runMounts(args[0]) },
RunE: func(_ *cobra.Command, args []string) error { return runMounts(args[0]) },
}
a.rootCmd.AddCommand(cmd)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/adsysd/daemon/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (a *App) installRunScripts() {
Short: gotext.Get("Runs scripts in the given subdirectory"),
Args: cobra.ExactArgs(1),
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error { return runScripts(args[0], *allowOrderMissing) },
RunE: func(_ *cobra.Command, args []string) error { return runScripts(args[0], *allowOrderMissing) },
}
allowOrderMissing = cmd.Flags().BoolP("allow-order-missing", "", false, gotext.Get("allow ORDER_FILE to be missing once the scripts are ready."))
a.rootCmd.AddCommand(cmd)
Expand Down
2 changes: 1 addition & 1 deletion cmd/adsysd/daemon/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func (a *App) installVersion() {
Use: "version",
Short: gotext.Get("Returns version of service and exits"),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error { return getVersion() },
RunE: func(_ *cobra.Command, _ []string) error { return getVersion() },
}
a.rootCmd.AddCommand(cmd)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/adsysd/integration_tests/adsysctl_doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestDocCompletion(t *testing.T) {
// Ensure that all interesting docs are listed here (and so. linked to their TOC)
var wantNumDocs int
docsDir := filepath.Join(rootProjectDir, "docs")
err = filepath.WalkDir(docsDir, func(path string, d fs.DirEntry, err error) error {
err = filepath.WalkDir(docsDir, func(path string, d fs.DirEntry, _ error) error {
// Ignore directories, every reference doc under reuse, compiled content and any autogenerated policy documentation.
if d.IsDir() ||
strings.HasPrefix(path, filepath.Join(docsDir, "reuse")) ||
Expand Down
4 changes: 2 additions & 2 deletions cmd/adwatchd/commands/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func New(opts ...option) *App {
Short: gotext.Get("AD watch daemon"),
Long: gotext.Get(`Watch directories for changes and bump the relevant GPT.ini versions.`),
Args: cobra.NoArgs,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
// Command parsing has been successful. Returns runtime (or
// configuration) error now and so, don't print usage.
cmd.SilenceUsage = true
Expand Down Expand Up @@ -155,7 +155,7 @@ func New(opts ...option) *App {
return nil
},

RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
var prevConfigFile string

// Check to see if adwatchd is already installed and get its config file.
Expand Down
2 changes: 1 addition & 1 deletion cmd/adwatchd/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The program will monitor the configured directories for changes and bump the app
If a GPT.ini file does not exist for a directory, a warning will be issued and the file will be created. If the GPT.ini file is incompatible or malformed, the program will report an error.
`),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
if len(a.config.Dirs) < 1 {
return errors.New(gotext.Get("run command needs at least one directory to watch either with --dirs or via the configuration file"))
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/adwatchd/commands/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (a *App) serviceStart() *cobra.Command {
Short: gotext.Get("Starts the service"),
Long: gotext.Get("Starts the %s service.", watchdconfig.CmdName),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
return a.service.Start(context.Background())
},
}
Expand All @@ -51,7 +51,7 @@ func (a *App) serviceStop() *cobra.Command {
Short: gotext.Get("Stops the service"),
Long: gotext.Get("Stops the %s service.", watchdconfig.CmdName),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
return a.service.Stop(context.Background())
},
}
Expand All @@ -65,7 +65,7 @@ func (a *App) serviceRestart() *cobra.Command {
Short: gotext.Get("Restarts the service"),
Long: gotext.Get("Restarts the %s service.", watchdconfig.CmdName),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
return a.service.Restart(context.Background())
},
}
Expand All @@ -79,7 +79,7 @@ func (a *App) serviceStatus() *cobra.Command {
Short: gotext.Get("Returns service status"),
Long: gotext.Get("Returns the status of the %s service.", watchdconfig.CmdName),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
status, err := a.service.Status(context.Background())
if err != nil {
return err
Expand All @@ -102,7 +102,7 @@ func (a *App) serviceInstall() *cobra.Command {
The service will be installed as a Windows service.
`, watchdconfig.CmdName),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
return a.service.Install(context.Background())
},
}
Expand All @@ -118,7 +118,7 @@ func (a *App) serviceUninstall() *cobra.Command {
Short: gotext.Get("Uninstalls the service"),
Long: gotext.Get("Uninstalls the %s service.", watchdconfig.CmdName),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
return a.service.Uninstall(context.Background())
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/adwatchd/commands/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func (a *App) installVersion() {
Use: "version",
Short: gotext.Get("Returns version of service and exits"),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error { return getVersion() },
RunE: func(_ *cobra.Command, _ []string) error { return getVersion() },
}
a.rootCmd.AddCommand(cmd)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/ad/registry/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ func FuzzDecodePolicy(f *testing.F) {
f.Add(d)
}

f.Fuzz(func(t *testing.T, d []byte) {
f.Fuzz(func(_ *testing.T, d []byte) {
r := bytes.NewReader(d)
_, _ = registry.DecodePolicy(r)
})
Expand Down
2 changes: 1 addition & 1 deletion internal/adsysservice/adsysservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func TestMain(m *testing.M) {
Value: uint64(1234),
Writable: false,
Emit: prop.EmitTrue,
Callback: func(c *prop.Change) *dbus.Error {
Callback: func(_ *prop.Change) *dbus.Error {
return nil
},
},
Expand Down
2 changes: 1 addition & 1 deletion internal/cmdhandler/cmdhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func NoCmd(_ *cobra.Command, _ []string) error {

// ZeroOrNArgs returns an error if there are not 0 or exactly N arguments for the given command.
func ZeroOrNArgs(n int) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error {
return func(_ *cobra.Command, args []string) error {
if len(args) != 0 && len(args) != n {
return fmt.Errorf("requires either no arguments or exactly %d, only received %d", n, len(args))
}
Expand Down
2 changes: 1 addition & 1 deletion internal/daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func TestSdNotifier(t *testing.T) {

d, err := daemon.New(grpcRegister.registerGRPCServer, "/tmp/this/is/ignored",
daemon.WithSystemdActivationListener(func() ([]net.Listener, error) { return []net.Listener{l}, nil }),
daemon.WithSystemdSdNotifier(func(unsetEnvironment bool, state string) (bool, error) {
daemon.WithSystemdSdNotifier(func(_ bool, _ string) (bool, error) {
if tc.notifierFail {
return false, errors.New("systemd notifier error")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/daemon/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func WithSystemdSdNotifier(f func(unsetEnvironment bool, state string) (bool, er
}

func FailingOption() func(o *options) error {
return func(o *options) error {
return func(_ *options) error {
return errors.New("failing option")
}
}
Loading

0 comments on commit 19cfcf7

Please sign in to comment.