Skip to content

Commit

Permalink
fix: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
msvticket committed Jan 10, 2025
1 parent 135a1cf commit 34e6dcb
Show file tree
Hide file tree
Showing 18 changed files with 58 additions and 88 deletions.
60 changes: 18 additions & 42 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
linters-settings:
depguard:
list-type: blacklist
packages:
- github.com/jenkins-x/jx/v2/pkg/log/
- github.com/satori/go.uuid
- github.com/pborman/uuid
packages-with-error-message:
- github.com/jenkins-x/jx/v2/pkg/log/: "use jenkins-x/jx-logging instead"
- github.com/satori/go.uuid: "use github.com/google/uuid instead"
- github.com/pborman/uuid: "use github.com/google/uuid instead"
rules:
Main:
list-mode: lax
deny:
- pkg: github.com/jenkins-x/jx/v2/pkg/log/
desc: "use jenkins-x/jx-logging instead"
- pkg: github.com/satori/go.uuid
desc: "use github.com/google/uuid instead"
- pkg: github.com/pborman/uuid
desc: "use github.com/google/uuid instead"
dupl:
threshold: 100
exhaustive:
Expand Down Expand Up @@ -37,17 +38,14 @@ linters-settings:
gocyclo:
min-complexity: 15
goimports: {}
golint:
min-confidence: 0
revive:
confidence: 0
gofmt:
simplify: true
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: [argument, case, condition, return]
mnd:
# don't include the "operation" and "assign"
checks: [argument, case, condition, return]
govet:
check-shadowing: true
settings:
printf:
funcs:
Expand All @@ -58,11 +56,8 @@ linters-settings:
- (github.com/jenkins-x/jx-logging/v3/pkg/log/Logger()).Fatalf
lll:
line-length: 140
maligned:
suggest-new: true
misspell: {}
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
Expand All @@ -73,7 +68,6 @@ linters:
enable:
- asciicheck
- bodyclose
- deadcode
- depguard
- errcheck
- gofmt
Expand All @@ -86,36 +80,18 @@ linters:
- nakedret
- rowserrcheck
- staticcheck
- structcheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- revive
- gocritic
- govet
issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
# - path: _test\.go
# linters:
# - gomnd
# https://github.com/go-critic/go-critic/issues/926
- linters:
- gocritic
text: "unnecessaryDefer:"
exclude:
- 'shadow: declaration of "err" shadows declaration at'
max-same-issues: 0

issues:
exclude-dirs:
- cmd/docs
run:
timeout: 30m
skip-dirs:
- cmd/docs
# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: 1.42.x # use the fixed version to not introduce new linters unexpectedly
prepare:
- echo "here I can run custom commands, but no preparation needed for this repo"
2 changes: 1 addition & 1 deletion cmd/docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func parseArgs() (*options, error) {
return opts, err
}

func parseMDContent(mdString string) (description string, examples string) {
func parseMDContent(mdString string) (description, examples string) {
parsedContent := strings.Split(mdString, "\n## ")
for _, s := range parsedContent {
if strings.Index(s, "Description") == 0 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/importcmd/buildpacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (o *ImportOptions) InvokeDraftPack(i *InvokeDraftPack) (string, error) {
envChart := filepath.Join(dir, "env", "Chart.yaml")
lpack := ""

if len(customDraftPack) > 0 {
if customDraftPack != "" {
log.Logger().Infof("trying to use draft pack: %s", customDraftPack)
lpack = filepath.Join(packsDir, customDraftPack)
f, err := files.DirExists(lpack)
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/importcmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func NewCmdImportAndOptions() (*cobra.Command, *ImportOptions) {
Short: "Imports a local project or Git repository into Jenkins",
Long: importLong,
Example: fmt.Sprintf(importExample, common.BinaryName, common.BinaryName, common.BinaryName, common.BinaryName, common.BinaryName, common.BinaryName),
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
err := opts.Run()
helper.CheckErr(err)
},
Expand Down Expand Up @@ -400,7 +400,7 @@ func (o *ImportOptions) Run() error {

if jenkinsfile != "" {
// let's pick the import destination for the jenkinsfile
o.Destination, err = o.PickImportDestination(devEnvCloneDir, jenkinsfile)
o.Destination, err = o.PickImportDestination(devEnvCloneDir)
if err != nil {
return err
}
Expand Down Expand Up @@ -853,7 +853,7 @@ func (o *ImportOptions) ReplacePlaceholders(gitServerName, dockerRegistryOrg str
constants.PlaceHolderDockerRegistryOrg, strings.ToLower(dockerRegistryOrg))

pathsToRename := []string{} // Renaming must be done post-Walk
if err := filepath.Walk(o.Dir, func(f string, fi os.FileInfo, err error) error {
if err := filepath.Walk(o.Dir, func(f string, fi os.FileInfo, _ error) error {
if skip, err := o.skipPathForReplacement(f, fi, ignore); skip {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/importcmd/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func SaveDir(c *chart.Chart, dest, packName string) error {
}

// Save values.yaml
if c.Values != nil && len(c.Values) > 0 {
if len(c.Values) > 0 {
// let's find the raw file for values.yaml and use to that to preserve comments
data := ""
for _, f := range c.Raw {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/importcmd/pick_destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const (
)

// PickImportDestination picks where to import the project to
func (o *ImportOptions) PickImportDestination(devEnvCloneDir, jenkinsfile string) (ImportDestination, error) {
func (o *ImportOptions) PickImportDestination(devEnvCloneDir string) (ImportDestination, error) {
sourceConfig, err := sourceconfigs.LoadSourceConfig(devEnvCloneDir, true)
if err != nil {
return o.Destination, errors.Wrapf(err, "failed to load the source config")
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/root/enable/enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func NewCmdPipelineEnable() (*cobra.Command, *Options) {
Long: cmdLong,
Example: cmdExample,
Aliases: []string{"dump"},
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
err := o.Run()
helper.CheckErr(err)
},
Expand Down
6 changes: 2 additions & 4 deletions pkg/cmd/root/mlquickstart.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ type CreateMLQuickstartOptions struct {
Filter quickstarts.QuickstartFilter
GitHost string
QuickstartAuth string
IgnoreTeam bool
}

type projectset struct {
Expand All @@ -72,7 +71,7 @@ func NewCmdCreateMLQuickstart() (*cobra.Command, *CreateMLQuickstartOptions) {
Long: createMLQuickstartLong,
Example: createMLQuickstartExample,
Aliases: []string{"arch"},
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
options.Args = args
err := options.Run()
helper.CheckErr(err)
Expand Down Expand Up @@ -151,7 +150,7 @@ func (o *CreateMLQuickstartOptions) Run() error {
}

log.Logger().Debugf("About to LoadMLProjectSetsModel...\n")
model, err := qo.LoadMLProjectSetsModel(o.GitHubOrganisations, o.IgnoreTeam)
model, err := qo.LoadMLProjectSetsModel(o.GitHubOrganisations)
if err != nil {
return fmt.Errorf("failed to load mlprojectsets: %s", err)
}
Expand Down Expand Up @@ -192,7 +191,6 @@ func (o *CreateMLQuickstartOptions) Run() error {
w.Filter.Text = q.Quickstart.Name
w.QuickstartAuth = o.QuickstartAuth
w.GitHost = o.GitHost
w.IgnoreTeam = o.IgnoreTeam

// Switch to BatchMode from here on
o.BatchMode = true
Expand Down
1 change: 0 additions & 1 deletion pkg/cmd/root/mlquickstart_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func TestCreateMLQuickstartProjects(t *testing.T) {
o.Dir = testDir
o.OutDir = testDir
o.DisableMaven = true
o.IgnoreTeam = true
o.Repository = appName
o.WaitForSourceRepositoryPullRequest = false

Expand Down
24 changes: 12 additions & 12 deletions pkg/cmd/root/pullrequest/create_pullrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,31 @@ type CreatePullRequestOptions struct {

// NewCmdCreatePullRequest creates a command object for the "create" command
func NewCmdCreatePullRequest() *cobra.Command {
options := &CreatePullRequestOptions{}
o := &CreatePullRequestOptions{}

cmd := &cobra.Command{
Use: "pullrequest",
Short: "Create a Pull Request on the git project for the current directory",
Aliases: []string{"pr", "pull request"},
Long: createPullRequestLong,
Example: createPullRequestExample,
Run: func(cmd *cobra.Command, args []string) {
err := options.Run()
Run: func(_ *cobra.Command, _ []string) {
err := o.Run()
helper.CheckErr(err)
},
}

cmd.Flags().StringVarP(&options.Title, optionTitle, "t", "", "The title of the pullrequest to create")
cmd.Flags().StringVarP(&options.Body, "body", "", "", "The body of the pullrequest")
cmd.Flags().StringVarP(&options.Base, "base", "", "", "The base branch to create the pull request into, instead of the default branch")
cmd.Flags().StringArrayVarP(&options.Labels, "label", "l", []string{}, "The labels to add to the pullrequest")
cmd.Flags().BoolVarP(&options.Push, "push", "", false, "If true the contents of the source directory will be committed, pushed, and used to create the pull request")
cmd.Flags().BoolVarP(&options.Fork, "fork", "", false, "If true, and the username configured to push the repo is different from the org name a PR is being created against, assume that this is a fork")
cmd.Flags().StringVarP(&o.Title, optionTitle, "t", "", "The title of the pullrequest to create")
cmd.Flags().StringVarP(&o.Body, "body", "", "", "The body of the pullrequest")
cmd.Flags().StringVarP(&o.Base, "base", "", "", "The base branch to create the pull request into, instead of the default branch")
cmd.Flags().StringArrayVarP(&o.Labels, "label", "l", []string{}, "The labels to add to the pullrequest")
cmd.Flags().BoolVarP(&o.Push, "push", "", false, "If true the contents of the source directory will be committed, pushed, and used to create the pull request")
cmd.Flags().BoolVarP(&o.Fork, "fork", "", false, "If true, and the username configured to push the repo is different from the org name a PR is being created against, assume that this is a fork")

cmd.Flags().BoolVarP(&options.BatchMode, "batch-mode", "b", false, "Enables batch mode which avoids prompting for user input")
cmd.Flags().BoolVarP(&o.BatchMode, "batch-mode", "b", false, "Enables batch mode which avoids prompting for user input")

options.Options.DiscoverFromGit = true
options.Options.AddFlags(cmd)
o.Options.DiscoverFromGit = true
o.Options.AddFlags(cmd)
return cmd
}

Expand Down
5 changes: 2 additions & 3 deletions pkg/cmd/root/quickstart.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ type CreateQuickstartOptions struct {
Filter quickstarts.QuickstartFilter
GitHost string
QuickstartAuth string
IgnoreTeam bool
}

// NewCmdCreateQuickstart creates a command object for the "create" command
Expand All @@ -66,7 +65,7 @@ func NewCmdCreateQuickstart() (*cobra.Command, *CreateQuickstartOptions) {
Long: createQuickstartLong,
Example: fmt.Sprintf(createQuickstartExample, common.BinaryName, common.BinaryName),
Aliases: []string{"arch"},
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
o.Args = args
err := o.Run()
helper.CheckErr(err)
Expand Down Expand Up @@ -119,7 +118,7 @@ func (o *CreateQuickstartOptions) Run() error {
JXClient: o.JXClient,
ScmClient: o.ScmFactory.ScmClient,
}
model, err := qo.LoadQuickStartsModel(o.GitHubOrganisations, o.IgnoreTeam)
model, err := qo.LoadQuickStartsModel(o.GitHubOrganisations)
if err != nil {
return fmt.Errorf("failed to load quickstarts: %s", err)
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/cmd/root/quickstart_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func TestCreateQuickstartProjects(t *testing.T) {
o.Dir = testDir
o.OutDir = testDir
o.DisableMaven = true
o.IgnoreTeam = true
o.Repository = appName
o.WaitForSourceRepositoryPullRequest = false

Expand Down Expand Up @@ -54,7 +53,6 @@ func TestCreateQuickstartProjectWithChart(t *testing.T) {
o.Dir = testDir
o.OutDir = testDir
o.DisableMaven = true
o.IgnoreTeam = true
o.Repository = appName
o.WaitForSourceRepositoryPullRequest = false

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func NewCmdMain() (*cobra.Command, *WizardOptions) {
Short: "Create a new project by importing code, creating a quickstart or custom wizard for spring",
Long: createProjectLong,
Example: fmt.Sprintf(createProjectExample, common.BinaryName),
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
setLoggingLevel(cmd)
err := options.Run()
helper.CheckErr(err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/root/spring.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func NewCmdCreateSpring() *cobra.Command {
Short: "Create a new Spring Boot application and import the generated code into Git and Jenkins for CI/CD",
Long: createSpringLong,
Example: fmt.Sprintf(createSpringExample, common.BinaryName, common.BinaryName, common.BinaryName, common.BinaryName),
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
options.Args = args
err := options.Run()
helper.CheckErr(err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/root/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewCmdVersion() (*cobra.Command, *Options) {
cmd := &cobra.Command{
Use: "version",
Short: "Displays the version of this command",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
err := o.Run()
helper.CheckErr(err)
},
Expand Down
18 changes: 9 additions & 9 deletions pkg/maven/archetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type ArtifactData struct {
}

type ArchetypeFilter struct {
GroupIds []string
GroupIDs []string
GroupIDFilter string
ArtifactIDFilter string
Version string
Expand Down Expand Up @@ -144,9 +144,9 @@ func (m *ArchetypeModel) AddArtifact(a *ArtifactData) *ArtifactVersions {
}

func (m *ArchetypeModel) CreateSurvey(data *ArchetypeFilter, pickVersion bool, form *ArchetypeForm, i input.Interface) error {
groupIds := data.GroupIds
groupIDs := data.GroupIDs
var err error
if len(data.GroupIds) == 0 {
if len(data.GroupIDs) == 0 {
filteredGroups := m.GroupIDs(data.GroupIDFilter)
if len(filteredGroups) == 0 {
return options.InvalidOption("group-filter", data.GroupIDFilter, m.GroupIDs(""))
Expand All @@ -163,7 +163,7 @@ func (m *ArchetypeModel) CreateSurvey(data *ArchetypeFilter, pickVersion bool, f
}
} else {
// TODO for now lets just support a single group ID being passed in
form.ArchetypeGroupID = groupIds[0]
form.ArchetypeGroupID = groupIDs[0]

artifactsWithoutFilter := m.ArtifactIDs(form.ArchetypeGroupID, "")
if len(artifactsWithoutFilter) == 0 {
Expand All @@ -174,16 +174,16 @@ func (m *ArchetypeModel) CreateSurvey(data *ArchetypeFilter, pickVersion bool, f
return fmt.Errorf("no archetype groupId selected")
}

artifactIds := m.ArtifactIDs(form.ArchetypeGroupID, data.ArtifactIDFilter)
if len(artifactIds) == 0 {
artifactIDs := m.ArtifactIDs(form.ArchetypeGroupID, data.ArtifactIDFilter)
if len(artifactIDs) == 0 {
artifactsWithoutFilter := m.ArtifactIDs(form.ArchetypeGroupID, "")
return options.InvalidOption("artifact", data.ArtifactIDFilter, artifactsWithoutFilter)
}

if len(artifactIds) == 1 {
form.ArchetypeArtifactID = artifactIds[0]
if len(artifactIDs) == 1 {
form.ArchetypeArtifactID = artifactIDs[0]
} else {
form.ArchetypeArtifactID, err = i.PickNameWithDefault(artifactIds, "Artifact ID:", form.ArchetypeArtifactID, "please pick the maven Artifact ID")
form.ArchetypeArtifactID, err = i.PickNameWithDefault(artifactIDs, "Artifact ID:", form.ArchetypeArtifactID, "please pick the maven Artifact ID")
if err != nil {
return errors.Wrapf(err, "failed to pick Artifact ID")
}
Expand Down
Loading

0 comments on commit 34e6dcb

Please sign in to comment.