chore: update and streamline linting configuration and error formatting

- Update `.golangci.yaml` to version 2 and streamline settings
- Remove specific linters from `.golangci.yaml` configuration
- Add exclusion and formatter settings to `.golangci.yaml`
- Change error message formatting in `plugin.go` to lowercase
- Use `strings.ReplaceAll` instead of `strings.Replace` for better readability and performance in `plugin.go` and `plugin_test.go`

Signed-off-by: appleboy <appleboy.tw@gmail.com>
This commit is contained in:
appleboy 2025-03-29 09:39:55 +08:00
parent 07c75984e5
commit 0ec46c4fd2
No known key found for this signature in database
3 changed files with 45 additions and 33 deletions

View File

@ -1,15 +1,9 @@
run: version: "2"
timeout: 5m
linters: linters:
enable: enable:
- asciicheck - asciicheck
- durationcheck - durationcheck
- errcheck
- errorlint - errorlint
- exportloopref
- gci
- gofmt
- goimports
- gosec - gosec
- misspell - misspell
- nakedret - nakedret
@ -19,24 +13,42 @@ linters:
- revive - revive
- usestdlibvars - usestdlibvars
- wastedassign - wastedassign
settings:
linters-settings: gosec:
gosec: includes:
# To select a subset of rules to run. - G102
# Available rules: https://github.com/securego/gosec#available-rules - G106
# Default: [] - means include all rules - G108
includes: - G109
- G102 - G111
- G106 - G112
- G108 - G201
- G109 - G203
- G111 perfsprint:
- G112 int-conversion: true
- G201 err-error: true
- G203 errorf: true
perfsprint: sprintf1: true
err-error: true strconcat: true
errorf: true exclusions:
int-conversion: true generated: lax
sprintf1: true presets:
strconcat: true - comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gci
- gofmt
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$

View File

@ -14,9 +14,9 @@ import (
) )
var ( var (
errMissingHost = errors.New("Error: missing server host") errMissingHost = errors.New("error: missing server host")
errMissingPasswordOrKey = errors.New("Error: can't connect without a private SSH key or password") errMissingPasswordOrKey = errors.New("error: can't connect without a private SSH key or password")
errCommandTimeOut = errors.New("Error: command timeout") errCommandTimeOut = errors.New("error: command timeout")
envsFormat = "export {NAME}={VALUE}" envsFormat = "export {NAME}={VALUE}"
) )
@ -55,7 +55,7 @@ type (
) )
func escapeArg(arg string) string { func escapeArg(arg string) string {
return "'" + strings.Replace(arg, "'", `'\''`, -1) + "'" return "'" + strings.ReplaceAll(arg, "'", `'\''`) + "'"
} }
func (p Plugin) hostPort(host string) (string, string) { func (p Plugin) hostPort(host string) (string, string) {

View File

@ -638,7 +638,7 @@ func TestEnvOutput(t *testing.T) {
} }
func unindent(text string) string { func unindent(text string) string {
return strings.TrimSpace(strings.Replace(text, "\t", "", -1)) return strings.TrimSpace(strings.ReplaceAll(text, "\t", ""))
} }
func TestPlugin_scriptCommands(t *testing.T) { func TestPlugin_scriptCommands(t *testing.T) {