Skip to content

Commit

Permalink
chore: golangci-lint 升级,修复新检查出的错误
Browse files Browse the repository at this point in the history
  • Loading branch information
dzpao committed Oct 17, 2020
1 parent c80bc8d commit 7f53abf
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 15 deletions.
9 changes: 8 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ linters:
disable:
# 因为只有两行语句的 case 语句里面强制要求 return 语句换行会让整个 switch 很分裂。
- wsl
- nlreturn
# 因为连 1 都算 magic number 的话,许多循环就没法写了。
# https://github.com/tommy-muehle/go-mnd/issues/3
- gomnd
Expand All @@ -14,11 +15,17 @@ linters:
# 有些情况下错误不可避免:
# https://github.com/mvdan/unparam/issues/43
- unparam
# 下面这两个 checker 太过激进,并不认同
# 下面这两个 checker 太过激进,并不认同
- gochecknoglobals
- gochecknoinits
# godot 要求注释必须以句号结尾,然而并不支持中文句号,放弃。
- godot

linters-settings:
errcheck:
check-type-assertions: true
ignore: '[FS]?[Pp]rint(|f|ln)|Write'
exhaustive:
default-signifies-exhaustive: true
gci:
local-prefixes: github.com/mudclient/go-mud
4 changes: 3 additions & 1 deletion lua-api/lua.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
lua "github.com/yuin/gopher-lua"
)

var errPanic = errors.New("LUA Panic")

type Config struct {
Enable bool `flag:"|true|是否加载 Lua 机器人"`
Path string `flag:"p|lua|Lua 插件路径 {path}"`
Expand Down Expand Up @@ -91,7 +93,7 @@ func (api *API) Reload() error {
l.SetGlobal("DelMSTimer", l.NewFunction(api.LuaDelTimer))

l.Panic = func(*lua.LState) {
api.Panic(errors.New("LUA Panic"))
api.Panic(errPanic)
}

if err := l.DoFile(mainFile); err != nil {
Expand Down
14 changes: 7 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import (
"strings"
"time"

"github.com/mudclient/go-mud/app"
"github.com/mudclient/go-mud/lua-api"
"github.com/mudclient/go-mud/mud"
"github.com/mudclient/go-mud/ui"

"github.com/flw-cn/go-smartConfig"
"github.com/mattn/go-runewidth"
"github.com/rivo/tview"
"github.com/spf13/cobra"
"golang.org/x/text/width"

"github.com/mudclient/go-mud/app"
"github.com/mudclient/go-mud/lua-api"
"github.com/mudclient/go-mud/mud"
"github.com/mudclient/go-mud/ui"
)

type ClientConfig struct {
Expand Down Expand Up @@ -83,8 +83,8 @@ LOOP:
plainLine := ansiRe.ReplaceAllString(rawLine, "")
if c.debug {
line := showLine
line = strings.Replace(line, "\x1b[", "<OSI>", -1)
line = strings.Replace(line, "\t", "<TAB>", -1)
line = strings.ReplaceAll(line, "\x1b[", "<OSI>")
line = strings.ReplaceAll(line, "\t", "<TAB>")
c.ui.Println(line)
line = tview.TranslateANSI(showLine)
line = tview.Escape(line)
Expand Down
3 changes: 2 additions & 1 deletion mud/iac.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ func (iac IACMessage) String() string {
codeName[iac.Args[0]] != "" {
argName = codeName[iac.Args[0]]
}

return fmt.Sprintf("IAC %s %s", cmdName, argName)
}

Expand All @@ -224,7 +225,7 @@ func (iac IACMessage) Eq(command byte, args ...byte) bool {
return bytes.Equal(iac.Args, args)
}

func (iac *IACMessage) Scan(b byte) bool {
func (iac *IACMessage) Scan(b byte) (completed bool) {
switch iac.state {
case stCmd:
switch b {
Expand Down
1 change: 0 additions & 1 deletion mud/mud.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"time"

"github.com/flw-cn/printer"

"golang.org/x/text/encoding"
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/encoding/traditionalchinese"
Expand Down
5 changes: 4 additions & 1 deletion mud/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ type CSIMessage struct {
}

type Line struct{ *bytes.Buffer }

type IncompleteLine struct{ *bytes.Buffer }

type EOF bool

func (CSIMessage) IsMessage() {}
Expand Down Expand Up @@ -88,6 +90,7 @@ func (s *Scanner) Scan() Message {
default:
line.WriteByte(b)
}

case stIACCommand:
if b == IAC {
return *iacCmd
Expand All @@ -102,7 +105,7 @@ func (s *Scanner) Scan() Message {
// readByte 努力读取一个字节,并返回成功(nil)或两种错误之一:
// timeout: 超时
// io.EOF: 连接已经不可用
// 优先从 s.buf 中读取,如果 s.buf 为空,则从 s.r 中读取
// 优先从 s.buf 中读取,如果 s.buf 为空,则从 s.r 中读取
func (s *Scanner) readByte() (byte, error) {
b, err := s.buf.ReadByte()
if err != io.EOF {
Expand Down
6 changes: 3 additions & 3 deletions ui/readline.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/rivo/tview"
)

const defaultHistorySize = 10000

type Readline struct {
*tview.InputField

Expand All @@ -23,19 +25,17 @@ func NewReadline() *Readline {
InputField: tview.NewInputField(),
history: make([]string, 0, 32),
curSel: 0,
historySize: 10000,
historySize: defaultHistorySize,
}
}

func (r *Readline) SetRepeat(b bool) *Readline {
r.repeat = b

return r
}

func (r *Readline) SetAutoTrim(b bool) *Readline {
r.autoTrim = b

return r
}

Expand Down

0 comments on commit 7f53abf

Please sign in to comment.