Skip to content

Commit

Permalink
enhancement: add Revive Linter, Resolve Linting Concerns, and Add Com…
Browse files Browse the repository at this point in the history
…ments to Exported Methods, Types, and Constants
  • Loading branch information
pratikjagrut authored and andylibrian committed Sep 22, 2023
1 parent 0eb3467 commit f8a98bf
Show file tree
Hide file tree
Showing 62 changed files with 1,291 additions and 174 deletions.
34 changes: 31 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ run:
skip-files:
- pkg/nodeagent/ebpf/exec.go

concurrency: 4

linters:
disable-all: true
enable:
Expand All @@ -18,15 +16,45 @@ linters:
- misspell
- dupl
- stylecheck
- revive

linters-settings:
gofmt:
simplify: true
dupl:
threshold: 400
revive:
ignoreGeneratedHeader: false
severity: "warning"
confidence: 0.8
errorCode: 1
warningCode: 1
rules:
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
- name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: exported

issues:
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0
max-same-issues: 0
include:
- EXC0012 # EXC0012 revive: issue about not having a comment.
- EXC0014 # EXC0014 revive: issue about not having a comment.
1 change: 1 addition & 0 deletions cmd/tarian-cluster-agent/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func buildRootCommand(logger *logrus.Logger) *cobra.Command {
return rootCmd
}

// Execute executes the root command.
func Execute() {
logger := log.GetLogger()
rootCmd := buildRootCommand(logger)
Expand Down
6 changes: 3 additions & 3 deletions cmd/tarian-cluster-agent/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func newRunCommand(globalFlags *flags.GlobalFlags) *cobra.Command {
return runCmd
}

func (c *runCommand) run(cmd *cobra.Command, args []string) error {
func (c *runCommand) run(_ *cobra.Command, args []string) error {
addr := c.host + ":" + c.port
listener, err := net.Listen("tcp", addr)
if err != nil {
Expand Down Expand Up @@ -112,7 +112,7 @@ func (c *runCommand) run(cmd *cobra.Command, args []string) error {
return nil
}

func (c *runCommand) newClusterAgentConfigFromCliContext() (*clusteragent.ClusterAgentConfig, error) {
func (c *runCommand) newClusterAgentConfigFromCliContext() (*clusteragent.Config, error) {
dialOpts := []grpc.DialOption{}

if c.serverTLSEnabled {
Expand Down Expand Up @@ -143,7 +143,7 @@ func (c *runCommand) newClusterAgentConfigFromCliContext() (*clusteragent.Cluste
dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
}

config := &clusteragent.ClusterAgentConfig{
config := &clusteragent.Config{
ServerAddress: c.serverAddress,
ServerGrpcDialOptions: dialOpts,
EnableAddConstraint: c.enableAddConstraint,
Expand Down
2 changes: 1 addition & 1 deletion cmd/tarian-cluster-agent/cmd/runWebhookServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func newWebhookServerCommand(globalFlags *flags.GlobalFlags) *cobra.Command {
return runWebhookServerCmd
}

func (c *runWebhookServerCommand) run(cmd *cobra.Command, args []string) error {
func (c *runWebhookServerCommand) run(_ *cobra.Command, args []string) error {
podAgentContainerConfig := webhookserver.PodAgentContainerConfig{
Name: c.podAgentContainerName,
Image: c.podAgentContainerImage,
Expand Down
1 change: 1 addition & 0 deletions cmd/tarian-node-agent/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func buildRootCommand(logger *logrus.Logger) *cobra.Command {
return rootCmd
}

// Execute executes the root command.
func Execute() {
logger := log.GetLogger()
rootCmd := buildRootCommand(logger)
Expand Down
2 changes: 1 addition & 1 deletion cmd/tarian-node-agent/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func newRunCommand(globalFlags *flags.GlobalFlags) *cobra.Command {
return runCmd
}

func (c *runCommand) run(cmd *cobra.Command, args []string) error {
func (c *runCommand) run(_ *cobra.Command, args []string) error {
if !isDebugFsMounted() {
c.logger.Info("debugfs is not mounted, will try to mount")

Expand Down
1 change: 1 addition & 0 deletions cmd/tarian-pod-agent/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func buildRootCommand(logger *logrus.Logger) *cobra.Command {
return rootCmd
}

// Execute executes the root command.
func Execute() {
logger := log.GetLogger()
rootCmd := buildRootCommand(logger)
Expand Down
2 changes: 1 addition & 1 deletion cmd/tarian-pod-agent/cmd/threat_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func newThreatScanCommand(globalFlag *flags.GlobalFlags) *cobra.Command {
return threatScanCmd
}

func (c *threatScanCommand) run(cmd *cobra.Command, args []string) error {
func (c *threatScanCommand) run(_ *cobra.Command, args []string) error {
c.logger.Info("tarian-pod-agent is running in threat-scan mode")
addr := c.host + ":" + c.port
agent := podagent.NewPodAgent(c.logger, addr)
Expand Down
6 changes: 3 additions & 3 deletions cmd/tarian-server/cmd/dgraph/applySchema.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func newApplySchemaCommand(globalFlags *flags.GlobalFlags) *cobra.Command {
return applySchemaCmd
}

func (o *applySchemaCommand) run(cmd *cobra.Command, args []string) error {
func (o *applySchemaCommand) run(_ *cobra.Command, args []string) error {
var cfg dgraphstore.DgraphConfig
err := envconfig.Process("Dgraph", &cfg)
if err != nil {
Expand All @@ -69,13 +69,13 @@ func (o *applySchemaCommand) run(cmd *cobra.Command, args []string) error {

if err != nil {
return fmt.Errorf("apply-schema: failed to apply schema: %w", err)
} else {
o.logger.Info("successfully applied schema")
}

o.logger.Info("successfully applied schema")
return nil
}

// BuildDgraphDialOpts builds the dial options for Dgraph client
func BuildDgraphDialOpts(dgraphCfg dgraphstore.DgraphConfig, logger *logrus.Logger) ([]grpc.DialOption, error) {
dialOpts := []grpc.DialOption{}
if dgraphCfg.TLSCertFile == "" {
Expand Down
1 change: 1 addition & 0 deletions cmd/tarian-server/cmd/dgraph/dgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/spf13/cobra"
)

// NewDgraphCommand creates a new `dgraph` command
func NewDgraphCommand(globalFlags *flags.GlobalFlags) *cobra.Command {
dgraphCmd := &cobra.Command{
Use: "dgraph",
Expand Down
1 change: 1 addition & 0 deletions cmd/tarian-server/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func buildRootCommand(logger *logrus.Logger) *cobra.Command {
return rootCmd
}

// Execute executes the root command.
func Execute() {
logger := log.GetLogger()
rootCmd := buildRootCommand(logger)
Expand Down
4 changes: 2 additions & 2 deletions cmd/tarian-server/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ func (o *runCommand) addFlags(cmd *cobra.Command) {
cmd.Flags().DurationVar(&o.natsStreamConfigDuplicates, "nats-stream-config-duplicates", 1*time.Minute, "")
}

func (o *runCommand) run(cmd *cobra.Command, args []string) error {
func (o *runCommand) run(_ *cobra.Command, args []string) error {
// Create server
host := o.host
port := o.port

dgraphAddress := os.Getenv("DGRAPH_ADDRESS")
storeSet := store.StoreSet{}
storeSet := store.Set{}
cfg := dgraphstore.DgraphConfig{Address: dgraphAddress}

err := envconfig.Process("Dgraph", &cfg)
Expand Down
2 changes: 1 addition & 1 deletion cmd/tarianctl/cmd/add/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func newAddActionCommand(globalFlags *flags.GlobalFlags) *cobra.Command {
return actionsCmd
}

func (c *actionCommand) run(cmd *cobra.Command, args []string) error {
func (c *actionCommand) run(_ *cobra.Command, args []string) error {
opts, err := util.ClientOptionsFromCliContext(c.logger, c.globalFlags)
if err != nil {
return fmt.Errorf("add action: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/tarianctl/cmd/add/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/spf13/cobra"
)

// addCmd represents the add command
// NewAddCommand creates a new `add` command
func NewAddCommand(globalFlags *flags.GlobalFlags) *cobra.Command {
addCmd := &cobra.Command{
Use: "add",
Expand Down
1 change: 1 addition & 0 deletions cmd/tarianctl/cmd/flags/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (globalFlags *GlobalFlags) ValidateGlobalFlags() error {
return nil
}

// GetFlagValuesFromEnvVar reads the environment variables for the global flags.
func (globalFlags *GlobalFlags) GetFlagValuesFromEnvVar() {
// Read environment variable for "server-address" flag
if serverAddressEnv := os.Getenv("TARIAN_SERVER_ADDRESS"); serverAddressEnv != "" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/tarianctl/cmd/get/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ tctl get a -o yaml
return actionsCmd
}

func (c *actionCommand) run(cmd *cobra.Command, args []string) error {
func (c *actionCommand) run(_ *cobra.Command, args []string) error {
opts, err := util.ClientOptionsFromCliContext(c.logger, c.globalFlags)
if err != nil {
return fmt.Errorf("get actions: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/tarianctl/cmd/get/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func newGetEventsCommand(globalFlags *flags.GlobalFlags) *cobra.Command {
return eventsCmd
}

func (c *eventsCommand) run(cmd *cobra.Command, args []string) error {
func (c *eventsCommand) run(_ *cobra.Command, args []string) error {
opts, err := util.ClientOptionsFromCliContext(c.logger, c.globalFlags)
if err != nil {
return fmt.Errorf("get events: %w", err)
Expand Down
1 change: 1 addition & 0 deletions cmd/tarianctl/cmd/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/spf13/cobra"
)

// NewGetCommand creates a new `get` command
func NewGetCommand(globalFlags *flags.GlobalFlags) *cobra.Command {
getCmd := &cobra.Command{
Use: "get",
Expand Down
4 changes: 2 additions & 2 deletions cmd/tarianctl/cmd/import/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type importCommand struct {
logger *logrus.Logger
}

// importCmd represents the import command
// NewImportCommand creates a new `import` command
func NewImportCommand(globalFlags *flags.GlobalFlags) *cobra.Command {
cmd := &importCommand{
globalFlags: globalFlags,
Expand All @@ -39,7 +39,7 @@ func NewImportCommand(globalFlags *flags.GlobalFlags) *cobra.Command {
return importCmd
}

func (c *importCommand) run(cmd *cobra.Command, args []string) error {
func (c *importCommand) run(_ *cobra.Command, args []string) error {
if len(args) == 0 {
err := errors.New("specify file paths to import")
return fmt.Errorf("import: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/tarianctl/cmd/remove/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func newRemoveActionsCommand(globalFlags *flags.GlobalFlags) *cobra.Command {
return actionsCmd
}

func (c *removeActionsCmd) run(cmd *cobra.Command, args []string) error {
func (c *removeActionsCmd) run(_ *cobra.Command, args []string) error {
if len(args) == 0 {
err := errors.New("please specify the name of the action to be removed")
return fmt.Errorf("remove action: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/tarianctl/cmd/remove/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func newRemoveConstraintsCommand(globalFlags *flags.GlobalFlags) *cobra.Command
return constraintsCmd
}

func (c *removeConstraintsCmd) run(cmd *cobra.Command, args []string) error {
func (c *removeConstraintsCmd) run(_ *cobra.Command, args []string) error {
if len(args) == 0 {
err := errors.New("please specify the names of the constraint to be removed")
return fmt.Errorf("remove constraint: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/tarianctl/cmd/remove/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/spf13/cobra"
)

// removeCmd represents the remove command
// NewRemoveCommand creates a new `remove` command
func NewRemoveCommand(globalFlags *flags.GlobalFlags) *cobra.Command {
removeCmd := &cobra.Command{
Use: "remove",
Expand Down
1 change: 1 addition & 0 deletions cmd/tarianctl/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func buildRootCommand(logger *logrus.Logger) *cobra.Command {
return rootCmd
}

// Execute executes the root command
func Execute() {
logger := log.GetLogger()
rootCmd := buildRootCommand(logger)
Expand Down
1 change: 1 addition & 0 deletions cmd/tarianctl/util/client_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"google.golang.org/grpc/credentials/insecure"
)

// ClientOptionsFromCliContext returns grpc dial options from cli context
func ClientOptionsFromCliContext(logger *logrus.Logger, globalFlags *flags.GlobalFlags) ([]grpc.DialOption, error) {
o := []grpc.DialOption{}

Expand Down
2 changes: 2 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package version

var versionStr string

// SetVersion sets the version string
func SetVersion(ver string) {
versionStr = ver
}

// GetVersion returns the version string
func GetVersion() string {
return versionStr
}
Loading

0 comments on commit f8a98bf

Please sign in to comment.