-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use golangci-lint #1044
Use golangci-lint #1044
Conversation
3833ba1
to
22db848
Compare
0744038
to
a511ff5
Compare
This PR is now rebased, and the issues introduced in the latest contributions to master are fixed. The failure of the labeler seems to be external. |
I rebased and fixed the issues introduced in the latest contributions to master. Since the failing labeler was removed recently, all tests are green now. |
This PR was rebased again and some issues introduced in |
1f6cd54
to
964c294
Compare
5d7f1ff
to
b04f50e
Compare
@jharshman, this is ready. Shall I move the last two commits to new PRs? |
@umarcor yes that would be great. |
b04f50e
to
74a5418
Compare
Done. |
@umarcor can you please squash your commits? |
@jharshman I think that preserving the commits is meaningful in this case, because each of them fixes a different linter warning/error. They could have been multiple PRs. Anyway, GitHub's web UI should allow you to resolve this PR by Merge, Squash or Rebase, as you wish. |
In version 1.1.2 of Cobra has been included a change[0] that changes the behaviour of how custom usage functions are printed. The change prepends "Error: " to the text. This is not desired since the usage text is not an error text. A workaround is to define a template string for the usage instead. The template uses the templating language of Go[1]. See the default template string in version 1.2.1[2]. This change has the positive benefit of getting more helpful usage messages. E.g., for command 'toolbox enter' the usage text is no longer "Run 'toolbox --help' for usage." but "Run 'toolbox enter --help' for usage.". Upstream issue: spf13/cobra#1532 [0] spf13/cobra#1044 [1] https://pkg.go.dev/text/template [2] https://github.com/spf13/cobra/blob/v1.2.1/command.go#L491
In version 1.1.2 of Cobra has been included a change[0] that changes the behaviour of how custom usage functions are printed. The change prepends "Error: " to the text. This is not desired since the usage text is not an error text. Example of the wrong behaviour: $ toolbox --foo Error: unknown flag: --foo Error: Run 'toolbox --help' for usage. Desired behaviour: $ toolbox --foo Error: unknown flag: --foo Run 'toolbox --help' for usage. A workaround is to define a template string for the usage instead. The template uses the templating language of Go[1]. See the default template string in version 1.2.1[2]. Because the template is set only once, the executableBase needs to be set before the template is applied. That required the move of setUpGlobals() into init() of the cmd package. This is a better place for the function call as init() is called earlier than Execute()[3]. Upstream issue: spf13/cobra#1532 [0] spf13/cobra#1044 [1] https://pkg.go.dev/text/template [2] https://github.com/spf13/cobra/blob/v1.2.1/command.go#L491 [3] https://golang.org/doc/effective_go#init
In version 1.1.2 of Cobra has been included a change[0] that changes the behaviour of how custom usage functions are printed. The change prepends "Error: " to the text. This is not desired since the usage text is not an error text. Example of the wrong behaviour: $ toolbox --foo Error: unknown flag: --foo Error: Run 'toolbox --help' for usage. Desired behaviour: $ toolbox --foo Error: unknown flag: --foo Run 'toolbox --help' for usage. A workaround is to define a template string for the usage instead. The template uses the templating language of Go[1]. See the default template string in version 1.2.1[2]. Because the template is set only once, the executableBase needs to be set before the template is applied. That required the move of setUpGlobals() into init() of the cmd package. This is a better place for the function call as init() is called earlier than Execute()[3]. Upstream issue: spf13/cobra#1532 [0] spf13/cobra#1044 [1] https://pkg.go.dev/text/template [2] https://github.com/spf13/cobra/blob/v1.2.1/command.go#L491 [3] https://golang.org/doc/effective_go#init containers#917
In version 1.1.2 of Cobra has been included a change[0] that changes the behaviour of how custom usage functions are printed. The change prepends "Error: " to the text. This is not desired since the usage text is not an error text. Example of the wrong behaviour: $ toolbox --foo Error: unknown flag: --foo Error: Run 'toolbox --help' for usage. Desired behaviour: $ toolbox --foo Error: unknown flag: --foo Run 'toolbox --help' for usage. A workaround is to define a template string for the usage instead. The template uses the templating language of Go[1]. See the default template string in version 1.2.1[2]. Because the template is set only once, the executableBase needs to be set before the template is applied. That required the move of setUpGlobals() into init() of the cmd package. This is a better place for the function call as init() is called earlier than Execute()[3]. Upstream issue: spf13/cobra#1532 [0] spf13/cobra#1044 [1] https://pkg.go.dev/text/template [2] https://github.com/spf13/cobra/blob/v1.2.1/command.go#L491 [3] https://golang.org/doc/effective_go#init containers#917
In version 1.1.2 of Cobra has been included a change[0] that changes the behaviour of how custom usage functions are printed. The change prepends "Error: " to the text. This is not desired since the usage text is not an error text. Example of the wrong behaviour: $ toolbox --foo Error: unknown flag: --foo Error: Run 'toolbox --help' for usage. Desired behaviour: $ toolbox --foo Error: unknown flag: --foo Run 'toolbox --help' for usage. A workaround is to define a template string for the usage instead. The template uses the templating language of Go[1]. See the default template string in version 1.2.1[2]. Because the template is set only once, the executableBase needs to be set before the template is applied. That required the move of setUpGlobals() into init() of the cmd package. This is a better place for the function call as init() is called earlier than Execute()[3]. Upstream issue: spf13/cobra#1532 [0] spf13/cobra#1044 [1] https://pkg.go.dev/text/template [2] https://github.com/spf13/cobra/blob/v1.2.1/command.go#L491 [3] https://golang.org/doc/effective_go#init containers#917
In version 1.1.2 of Cobra has been included a change[0] that changes the behaviour of how custom usage functions are printed. The change prepends "Error: " to the text. This is not desired since the usage text is not an error text. Example of the wrong behaviour: $ toolbox --foo Error: unknown flag: --foo Error: Run 'toolbox --help' for usage. Desired behaviour: $ toolbox --foo Error: unknown flag: --foo Run 'toolbox --help' for usage. A workaround is to define a template string for the usage instead. The template uses the templating language of Go[1]. See the default template string in version 1.2.1[2]. Because the template is set only once, the executableBase needs to be set before the template is applied. That required the move of setUpGlobals() into init() of the cmd package. This is a better place for the function call as init() is called earlier than Execute()[3]. Upstream issue: spf13/cobra#1532 [0] spf13/cobra#1044 [1] https://pkg.go.dev/text/template [2] https://github.com/spf13/cobra/blob/v1.2.1/command.go#L491 [3] https://golang.org/doc/effective_go#init containers#917
In version 1.1.2 of Cobra has been included a change[0] that changes how custom usage functions are handled. Example of the wrong behaviour: $ toolbox --foo Error: unknown flag: --foo Run 'toolbox --help' for usage.Error: Run 'toolbox --help' for usage. Desired behaviour: $ toolbox --foo Error: unknown flag: --foo Run 'toolbox --help' for usage. A workaround is to define a template string for the usage instead. The template uses the templating language of Go[1]. See the default template string in version 1.2.1[2]. Because the template is set only once, the executableBase needs to be set before the template is applied. That required the move of setUpGlobals() into init() of the cmd package. This is a better place for the function call as init() is called earlier than Execute()[3]. Upstream issue: spf13/cobra#1532 [0] spf13/cobra#1044 [1] https://pkg.go.dev/text/template [2] https://github.com/spf13/cobra/blob/v1.2.1/command.go#L491 [3] https://golang.org/doc/effective_go#init containers#917
In version 1.1.2 of Cobra has been included a change[0] that changes how custom usage functions are handled. Example of the wrong behaviour: $ toolbox --foo Error: unknown flag: --foo Run 'toolbox --help' for usage.Error: Run 'toolbox --help' for usage. Desired behaviour: $ toolbox --foo Error: unknown flag: --foo Run 'toolbox --help' for usage. A workaround is to define a template string for the usage instead. The template uses the templating language of Go[1]. See the default template string in version 1.2.1[2]. Because the template is set only once, the executableBase needs to be set before the template is applied. That required the move of setUpGlobals() into init() of the cmd package. This is a better place for the function call as init() is called earlier than Execute()[3]. Upstream issue: spf13/cobra#1532 [0] spf13/cobra#1044 [1] https://pkg.go.dev/text/template [2] https://github.com/spf13/cobra/blob/v1.2.1/command.go#L491 [3] https://golang.org/doc/effective_go#init containers#917
Close #952
Close #968
golangci-lint is added to Travis CI. Then, multiple linting issues are fixed: errors are handled, unused variables/functions are removed, unnecessary types are removed, frequently used strings are defined as constants, etc.
Ref #876