Skip to content
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

build: upgrade go version to 1.22 and make lint happy #1071

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions .github/workflows/test_and_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '1.20'
go-version: '1.22'
cache: false
- run: go get
- run: go generate ./...
Expand All @@ -30,20 +30,18 @@ jobs:
- run: go vet ./...

- name: GolangCI-Lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6
if: github.event.name == 'pull_request'
with:
version: 'v1.55.2'
version: 'v1.60'
args: '--timeout 9999s'
only-new-issues: true
skip-pkg-cache: true
skip-build-cache: true
skip-cache: true

- name: GolangCI-Lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6
if: github.event.name != 'pull_request'
with:
version: 'v1.55.2'
version: 'v1.60'
args: '--timeout 9999s'
skip-pkg-cache: true
skip-build-cache: true
skip-cache: true
217 changes: 150 additions & 67 deletions .golangci.yml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions api/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package api

import (
"bytes"
"fmt"
"errors"
"io"
"io/fs"
"mime/multipart"
Expand Down Expand Up @@ -246,7 +246,7 @@ func ensurePathSafe(path string) error {
if !strings.HasPrefix(abs, imagesPath) &&
!strings.HasPrefix(abs, audiosPath) &&
!strings.HasPrefix(abs, videosPath) {
return fmt.Errorf("invalid path")
return errors.New("invalid path")
}
return nil
}
2 changes: 1 addition & 1 deletion api/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func Int64ToBytes(i int64) []byte {
}

func doAuth(c echo.Context) bool {
token := c.Request().Header.Get("token")
token := c.Request().Header.Get("token") //nolint:canonicalheader // private header
if token == "" {
token = c.QueryParam("token")
}
Expand Down
10 changes: 5 additions & 5 deletions dice/builtin_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ func (d *Dice) registerCoreCommands() {
dm.UpdateCheckRequestChan <- 1

// 等待获取新版本,最多10s
for i := 0; i < 5; i++ {
for range 5 {
time.Sleep(2 * time.Second)
if dm.AppVersionOnline != nil {
break
Expand Down Expand Up @@ -1290,7 +1290,7 @@ func (d *Dice) registerCoreCommands() {
return CmdExecuteResult{Matched: true, Solved: true}
}
var texts []string
for i := 0; i < cmdArgs.SpecialExecuteTimes; i++ {
for range cmdArgs.SpecialExecuteTimes {
ret := rollOne()
if ret != nil {
return *ret
Expand Down Expand Up @@ -1641,7 +1641,7 @@ func (d *Dice) registerCoreCommands() {

var extNames []string
var conflictsAll []string
for index := 0; index < len(cmdArgs.Args); index++ {
for index := range len(cmdArgs.Args) {
extName := strings.ToLower(cmdArgs.Args[index])
if i := d.ExtFind(extName); i != nil {
extNames = append(extNames, extName)
Expand All @@ -1668,7 +1668,7 @@ func (d *Dice) registerCoreCommands() {

var closed []string
var notfound []string
for index := 0; index < len(cmdArgs.Args); index++ {
for index := range len(cmdArgs.Args) {
extName := cmdArgs.Args[index]
extName = d.ExtAliasToName(extName)
ei := ctx.Group.ExtInactiveByName(extName)
Expand Down Expand Up @@ -2277,7 +2277,7 @@ func tryConvertIndex2Name(ctx *MsgContext, name string) string {
idx--
if idx == 0 {
name = k[4:]
return fmt.Errorf("break")
return errors.New("break")
}
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion dice/censor/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (t *trie) Match(text string) (sensitiveWords map[string]Level) {

sensitiveWords = map[string]Level{}
chars := []rune(text)
for i := 0; i < len(chars); i++ {
for i := range len(chars) {
cur := t.root.findChild(chars[i])
if cur == nil {
continue
Expand Down
2 changes: 1 addition & 1 deletion dice/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2130,7 +2130,7 @@ func (d *Dice) loads() {
d.GroupBurst = 3
}

if d.DiceMasters == nil || len(d.DiceMasters) == 0 {
if len(d.DiceMasters) == 0 {
d.DiceMasters = []string{"UI:1001"}
}
var newDiceMasters []string
Expand Down
3 changes: 2 additions & 1 deletion dice/dice_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dice

import (
"encoding/json"
"errors"
"fmt"
"io/fs"
"os"
Expand Down Expand Up @@ -393,7 +394,7 @@ func (dm *DiceManager) BackupClean(fromAuto bool) (err error) {
}

if len(errDel) > 0 {
return fmt.Errorf("error(s) occured when deleting files:\n" + strings.Join(errDel, "\n"))
return errors.New("error(s) occured when deleting files:\n" + strings.Join(errDel, "\n"))
}
return nil
}
3 changes: 2 additions & 1 deletion dice/dice_censor.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dice

import (
"errors"
"fmt"
"io/fs"
"os"
Expand Down Expand Up @@ -78,7 +79,7 @@ func (cm *CensorManager) Load(_ *Dice) {

func (cm *CensorManager) Check(ctx *MsgContext, msg *Message, checkContent string) (*MsgCheckResult, error) {
if cm.IsLoading {
return nil, fmt.Errorf("censor is loading")
return nil, errors.New("censor is loading")
}
res := cm.Censor.Check(checkContent)
if !ctx.Censored && res.HighestLevel > censor.Ignore {
Expand Down
7 changes: 4 additions & 3 deletions dice/dice_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dice

import (
"encoding/json"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -352,7 +353,7 @@ func (m *HelpManager) loadHelpDoc(group string, path string) bool {
continue
}
key := row[0]
for j := 0; j < synonymCount; j++ {
for j := range synonymCount {
if len(row[1+j]) > 0 {
key += "/" + row[1+j]
}
Expand Down Expand Up @@ -382,7 +383,7 @@ func (m *HelpManager) loadHelpDoc(group string, path string) bool {
// validateXlsxHeaders 验证 xlsx 格式 helpdoc 的表头是否是 Key Synonym(可能有多列) Content Description Catalogue Tag
func validateXlsxHeaders(headers []string) (int, error) {
if len(headers) < 3 {
return 0, fmt.Errorf("helpdoc格式错误,缺少必须列 Key Synonym Content")
return 0, errors.New("helpdoc格式错误,缺少必须列 Key Synonym Content")
}

var (
Expand Down Expand Up @@ -566,7 +567,7 @@ func (m *HelpManager) searchBleve(ctx *MsgContext, text string, titleOnly bool,
func (m *HelpManager) Search(ctx *MsgContext, text string, titleOnly bool, pageSize, pageNum int, group string) (res *bleve.SearchResult, total, pageStart, pageEnd int, err error) {
if pageSize <= 0 || pageNum <= 0 {
// 为了使Search的结果完全忠实于分页参数, 而不产生有结果但与分页不相符的情况
return nil, 0, 0, 0, fmt.Errorf("分页参数错误")
return nil, 0, 0, 0, errors.New("分页参数错误")
}

if m.EngineType == 0 {
Expand Down
10 changes: 5 additions & 5 deletions dice/dice_jsvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1125,18 +1125,18 @@ func JsDisable(d *Dice, jsInfoName string) {
func (d *Dice) JsCheckUpdate(jsScriptInfo *JsScriptInfo) (string, string, string, error) {
// FIXME: dirty, copy from check deck update.
if len(jsScriptInfo.UpdateUrls) == 0 {
return "", "", "", fmt.Errorf("插件未提供更新链接")
return "", "", "", errors.New("插件未提供更新链接")
}

statusCode, newData, err := GetCloudContent(jsScriptInfo.UpdateUrls, jsScriptInfo.Etag)
if err != nil {
return "", "", "", err
}
if statusCode == http.StatusNotModified {
return "", "", "", fmt.Errorf("插件没有更新")
return "", "", "", errors.New("插件没有更新")
}
if statusCode != http.StatusOK {
return "", "", "", fmt.Errorf("未获取到插件更新")
return "", "", "", errors.New("未获取到插件更新")
}
oldData, err := os.ReadFile(jsScriptInfo.Filename)
if err != nil {
Expand Down Expand Up @@ -1175,7 +1175,7 @@ func (d *Dice) JsUpdate(jsScriptInfo *JsScriptInfo, tempFileName string) error {
return err
}
if len(newData) == 0 {
return fmt.Errorf("new data is empty")
return errors.New("new data is empty")
}
// 更新插件
err = os.WriteFile(jsScriptInfo.Filename, newData, 0o755)
Expand Down Expand Up @@ -1403,7 +1403,7 @@ func (t *JsScriptTask) reset(expr string) error {
func parseTaskTime(taskTimeStr string) (string, error) {
match := taskTimeRe.MatchString(taskTimeStr)
if !match {
return "", fmt.Errorf("仅接受 24 小时表示的时间作为每天的执行时间,如 0:05 13:30")
return "", errors.New("仅接受 24 小时表示的时间作为每天的执行时间,如 0:05 13:30")
}
time, err := time.Parse("15:04", taskTimeStr)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion dice/dice_jsvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func sameScriptInfos(a []*JsScriptInfo, b []*JsScriptInfo) bool {
if len(a) != len(b) {
return false
}
for i := 0; i < len(a); i++ {
for i := range len(a) {
if !sameScriptInfo(a[i], b[i]) {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion dice/dice_name_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (ng *NamesGenerator) NameGenerate(rule string) string {
length = length2
}

for index := 0; index < length; index++ {
for index := range length {
choices = append(choices, wr.NewChoice(index, uint(weightLst[index])))
}
restText = sp[0]
Expand Down
19 changes: 9 additions & 10 deletions dice/ext_coc7.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ func RegisterBuiltinExtCoc7(self *Dice) {
return CmdExecuteResult{Matched: true, Solved: true}
}
texts := []string{}
for i := 0; i < cmdArgs.SpecialExecuteTimes; i++ {
for range cmdArgs.SpecialExecuteTimes {
ret := rollOne(true)
if ret != nil {
return *ret
Expand Down Expand Up @@ -586,7 +586,7 @@ func RegisterBuiltinExtCoc7(self *Dice) {
ReplyToSender(ctx, msg, text)
case "details":
help := "当前有coc7规则如下:\n"
for i := 0; i < 6; i++ {
for i := range 6 {
basicStr := strings.ReplaceAll(SetCocRuleText[i], "\n", " ")
help += fmt.Sprintf(".setcoc %d // %s\n", i, basicStr)
}
Expand Down Expand Up @@ -894,12 +894,12 @@ func RegisterBuiltinExtCoc7(self *Dice) {
increment int64
newVarValue int64
}
RuleNotMatch := fmt.Errorf("rule not match")
FormatMismatch := fmt.Errorf("format mismatch")
SkillNotEntered := fmt.Errorf("skill not entered")
SkillTypeError := fmt.Errorf("skill value type error")
SuccessExprFormatError := fmt.Errorf("success expr format error")
FailExprFormatError := fmt.Errorf("fail expr format error")
RuleNotMatch := errors.New("rule not match")
FormatMismatch := errors.New("format mismatch")
SkillNotEntered := errors.New("skill not entered")
SkillTypeError := errors.New("skill value type error")
SuccessExprFormatError := errors.New("success expr format error")
FailExprFormatError := errors.New("fail expr format error")
singleRe := regexp.MustCompile(`([a-zA-Z_\p{Han}]+)\s*(\d+)?\s*(\+(([^/]+)/)?\s*(.+))?`)
check := func(skill string) (checkResult enCheckResult) {
checkResult.valid = true
Expand Down Expand Up @@ -1504,10 +1504,9 @@ func RegisterBuiltinExtCoc7(self *Dice) {
if val > ctx.Dice.MaxCocCardGen {
val = ctx.Dice.MaxCocCardGen
}
var i int64

var ss []string
for i = 0; i < val; i++ {
for range val {
result, _, err := self.ExprText(`力量:{$t1=3d6*5} 敏捷:{$t2=3d6*5} 意志:{$t3=3d6*5}\n体质:{$t4=3d6*5} 外貌:{$t5=3d6*5} 教育:{$t6=(2d6+6)*5}\n体型:{$t7=(2d6+6)*5} 智力:{$t8=(2d6+6)*5}\nHP:{($t4+$t7)/10} 幸运:{$t9=3d6*5} [{$t1+$t2+$t3+$t4+$t5+$t6+$t7+$t8}/{$t1+$t2+$t3+$t4+$t5+$t6+$t7+$t8+$t9}]`, ctx)
if err != nil {
break
Expand Down
10 changes: 5 additions & 5 deletions dice/ext_deck.go
Original file line number Diff line number Diff line change
Expand Up @@ -1155,18 +1155,18 @@ func extractExecuteContent(s string) (string, string) {

func (d *Dice) DeckCheckUpdate(deckInfo *DeckInfo) (string, string, string, error) {
if len(deckInfo.UpdateUrls) == 0 {
return "", "", "", fmt.Errorf("牌堆未提供更新链接")
return "", "", "", errors.New("牌堆未提供更新链接")
}

statusCode, newData, err := GetCloudContent(deckInfo.UpdateUrls, deckInfo.Etag)
if err != nil {
return "", "", "", err
}
if statusCode == http.StatusNotModified {
return "", "", "", fmt.Errorf("牌堆没有更新")
return "", "", "", errors.New("牌堆没有更新")
}
if statusCode != http.StatusOK {
return "", "", "", fmt.Errorf("未获取到牌堆更新")
return "", "", "", errors.New("未获取到牌堆更新")
}

oldData, err := os.ReadFile(deckInfo.Filename)
Expand Down Expand Up @@ -1206,13 +1206,13 @@ func (d *Dice) DeckUpdate(deckInfo *DeckInfo, tempFileName string) error {
return err
}
if len(newData) == 0 {
return fmt.Errorf("new data is empty")
return errors.New("new data is empty")
}
// 更新牌堆
ok := parseDeck(d, tempFileName, newData, deckInfo)
if !ok {
d.Logger.Errorf("牌堆“%s”更新失败,无法解析获取到的牌堆数据", deckInfo.Name)
return fmt.Errorf("无法解析获取到的牌堆数据")
return errors.New("无法解析获取到的牌堆数据")
}

err = os.WriteFile(deckInfo.Filename, newData, 0755)
Expand Down
6 changes: 3 additions & 3 deletions dice/ext_fun.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ func RegisterBuiltinExtFun(self *Dice) {
successDegrees := int64(0)
failedCount := int64(0)
var results []string
for i := int64(0); i < num; i++ {
for range num {
v := DiceRoll64(6)
if v >= 5 {
successDegrees++
Expand Down Expand Up @@ -759,7 +759,7 @@ func RegisterBuiltinExtFun(self *Dice) {

successDegrees := int64(0)
var results []string
for i := int64(0); i < diceNum; i++ {
for range diceNum {
v := DiceRoll64(10)
if v <= checkVal {
successDegrees++
Expand Down Expand Up @@ -1247,7 +1247,7 @@ func RegisterBuiltinExtFun(self *Dice) {
for i := range allNum {
allNum[i] = i + 1
}
for idx := 0; idx < roulette.Time; idx++ {
for idx := range roulette.Time {
i := int(roulette.Face) - 1 - idx
j := rand.Intn(i + 1)
allNum[i], allNum[j] = allNum[j], allNum[i]
Expand Down
2 changes: 1 addition & 1 deletion dice/ext_story.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func cmdRandomName(ctx *MsgContext, msg *Message, cmdArgs *CmdArgs, cmdsList [][
}

// 开始抽取
for i := int64(0); i < num; i++ {
for range num {
rule := rules[rand.Int()%len(rules)]
names = append(names, ctx.Dice.Parent.NamesGenerator.NameGenerate(rule))
}
Expand Down
2 changes: 1 addition & 1 deletion dice/im_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ func (s *IMSession) LongTimeQuitInactiveGroup(threshold, hint time.Time, roundIn
// 采用类似分页的手法进行退群
groupCount := len(selectedGroupEndpoints)
rounds := (groupCount + groupsPerRound - 1) / groupsPerRound
for round := 0; round < rounds; round++ {
for round := range rounds {
startIndex := round * groupsPerRound
endIndex := (round + 1) * groupsPerRound
if endIndex > groupCount {
Expand Down
Loading