mirror of
https://github.com/appleboy/drone-telegram.git
synced 2026-06-04 10:14:50 +08:00
refactor: refactor code and update linter config
- Add a new `.golangci.yml` configuration file with a list of enabled linters - Exclude `lll` linter for lines starting with `//go:generate` - Replace `strings.Replace` with `strings.ReplaceAll` in `plugin.go` for markdown escaping and error message sanitization - Simplify time addition expressions in `plugin_test.go` by removing unnecessary `time.Duration` conversions Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
linters:
|
||||
disable-all: true
|
||||
enable:
|
||||
- bodyclose
|
||||
- dogsled
|
||||
- errcheck
|
||||
- exportloopref
|
||||
- exhaustive
|
||||
- gochecknoinits
|
||||
- goconst
|
||||
- gocritic
|
||||
- gocyclo
|
||||
- gofmt
|
||||
- goimports
|
||||
- goprintffuncname
|
||||
- gosec
|
||||
- gosimple
|
||||
- govet
|
||||
- ineffassign
|
||||
- misspell
|
||||
- nakedret
|
||||
- noctx
|
||||
- nolintlint
|
||||
- staticcheck
|
||||
- stylecheck
|
||||
- typecheck
|
||||
- unconvert
|
||||
- unparam
|
||||
- unused
|
||||
- whitespace
|
||||
- gofumpt
|
||||
|
||||
issues:
|
||||
exclude-rules:
|
||||
# Exclude `lll` issues for long lines with `go:generate`.
|
||||
- linters:
|
||||
- lll
|
||||
source: "^//go:generate "
|
||||
@@ -146,8 +146,8 @@ func escapeMarkdown(keys []string) []string {
|
||||
}
|
||||
|
||||
func escapeMarkdownOne(str string) string {
|
||||
str = strings.Replace(str, `\_`, `_`, -1)
|
||||
str = strings.Replace(str, `_`, `\_`, -1)
|
||||
str = strings.ReplaceAll(str, `\_`, `_`)
|
||||
str = strings.ReplaceAll(str, `_`, `\_`)
|
||||
|
||||
return str
|
||||
}
|
||||
@@ -188,14 +188,12 @@ func convertLocation(value string) (Location, bool) {
|
||||
}
|
||||
|
||||
latitude, err = strconv.ParseFloat(values[0], 64)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
return Location{}, true
|
||||
}
|
||||
|
||||
longitude, err = strconv.ParseFloat(values[1], 64)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
return Location{}, true
|
||||
@@ -465,7 +463,7 @@ func (p Plugin) Send(bot *tgbotapi.BotAPI, msg tgbotapi.Chattable) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.New(strings.Replace(err.Error(), p.Config.Token, "<token>", -1))
|
||||
return errors.New(strings.ReplaceAll(err.Error(), p.Config.Token, "<token>"))
|
||||
}
|
||||
|
||||
// Message is plugin default message.
|
||||
|
||||
+3
-3
@@ -397,7 +397,7 @@ func TestMessageFile(t *testing.T) {
|
||||
Status: "success",
|
||||
Link: "https://github.com/appleboy/go-hello",
|
||||
Started: time.Now().Unix(),
|
||||
Finished: time.Now().Add(time.Duration(180 * time.Second)).Unix(),
|
||||
Finished: time.Now().Add(180 * time.Second).Unix(),
|
||||
},
|
||||
|
||||
Config: Config{
|
||||
@@ -428,7 +428,7 @@ func TestTemplateVars(t *testing.T) {
|
||||
Status: "success",
|
||||
Link: "https://github.com/appleboy/go-hello",
|
||||
Started: time.Now().Unix(),
|
||||
Finished: time.Now().Add(time.Duration(180 * time.Second)).Unix(),
|
||||
Finished: time.Now().Add(180 * time.Second).Unix(),
|
||||
},
|
||||
|
||||
Config: Config{
|
||||
@@ -521,7 +521,7 @@ func TestBuildTemplate(t *testing.T) {
|
||||
Status: "success",
|
||||
Link: "https://github.com/appleboy/go-hello",
|
||||
Started: time.Now().Unix(),
|
||||
Finished: time.Now().Add(time.Duration(180 * time.Second)).Unix(),
|
||||
Finished: time.Now().Add(180 * time.Second).Unix(),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user