chore(prj): use golangci-lint

This commit is contained in:
iyear 2023-08-21 13:19:40 +08:00
parent 071180947f
commit 6f61b1cfdb
13 changed files with 58 additions and 32 deletions

30
.golangci.yaml Normal file
View File

@ -0,0 +1,30 @@
output:
sort-results: true
linters:
disable-all: true
enable:
- gci
- gofumpt
- gosimple
- govet
- goconst
- ineffassign
- misspell
- staticcheck
- nakedret
- unconvert
- unused
- usestdlibvars
- exhaustive
linters-settings:
exhaustive:
default-signifies-exhaustive: true
gci:
sections:
- standard
- default
- prefix(github.com/iyear/tdl)
- dot
custom-order: true
nakedret:
max-func-lines: 0 # force to use explicit return

View File

@ -42,7 +42,7 @@ func Recover(ctx context.Context, file string) error {
return errors.Wrap(err, "read all")
}
return os.WriteFile(filepath.Join(consts.DataDir, af.Name()), bytes, 0644)
return os.WriteFile(filepath.Join(consts.DataDir, af.Name()), bytes, 0o644)
}); err != nil {
return err
}

View File

@ -42,11 +42,7 @@ func (i *iter) Next(ctx context.Context) bool {
i.cur++
if i.cur == len(i.files) {
return false
}
return true
return i.cur != len(i.files)
}
func (i *iter) Value(ctx context.Context) (*uploader.Item, error) {

View File

@ -20,15 +20,13 @@ var Apps = map[string]struct {
AppDesktop: {AppID: 2040, AppHash: "b18441a1ff607e10a989891a5462e627"},
}
var (
Device = telegram.DeviceConfig{
DeviceModel: "Desktop",
SystemVersion: "Windows 10",
AppVersion: "4.2.4 x64",
LangCode: "en",
SystemLangCode: "en-US",
LangPack: "tdesktop",
}
)
var Device = telegram.DeviceConfig{
DeviceModel: "Desktop",
SystemVersion: "Windows 10",
AppVersion: "4.2.4 x64",
LangCode: "en",
SystemLangCode: "en-US",
LangPack: "tdesktop",
}
const FileMaxSize = 4000 * 1024 * 1024

View File

@ -132,7 +132,7 @@ func (d *Downloader) download(ctx context.Context, item *Item) error {
path := filepath.Join(d.dir, filename)
// #113. If path contains dirs, create it. So now we support nested dirs.
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
return err
}

View File

@ -21,7 +21,7 @@ func NewFile(path string) (*File, error) {
return nil, err
}
if err = os.WriteFile(path, []byte("{}"), 0644); err != nil {
if err = os.WriteFile(path, []byte("{}"), 0o644); err != nil {
return nil, err
}
@ -91,5 +91,5 @@ func (f *File) write(m map[string][]byte) error {
return err
}
return os.WriteFile(f.path, bytes, 0644)
return os.WriteFile(f.path, bytes, 0o644)
}

View File

@ -11,9 +11,7 @@ import (
"github.com/iyear/tdl/pkg/validator"
)
var (
ErrNotFound = errors.New("key not found")
)
var ErrNotFound = errors.New("key not found")
type KV interface {
Get(key string) ([]byte, error)

View File

@ -99,5 +99,7 @@ func (f *FieldsGetter) walk(v reflect.Type, field *Field, fields *[]*Field) {
f.walk(v.Elem(), field, fields)
case reflect.Pointer:
f.walk(v.Elem(), field, fields)
default:
// do nothing
}
}

View File

@ -8,15 +8,16 @@ import (
)
// https://github.com/telegramdesktop/tdesktop/blob/dev/Telegram/SourceFiles/platform/win/specific_win.cpp#L237-L249
func desktopAppData(_ string) (paths []string) {
func desktopAppData(_ string) []string {
paths := make([]string, 0)
dataDir := os.Getenv("APPDATA")
if dataDir == "" {
return
return paths
}
paths = append(paths,
filepath.Join(dataDir, AppName),
filepath.Join(dataDir, "Telegram Desktop UWP"))
return
return paths
}

View File

@ -31,7 +31,6 @@ type Uploader struct {
partSize int
threads int
iter Iter
remove bool
}
type Options struct {

View File

@ -4,10 +4,10 @@ import (
"encoding/json"
"strings"
"github.com/iyear/tdl/app/chat"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/iyear/tdl/app/chat"
)
var _ = Describe("Test tdl chat ls", FlakeAttempts(3), func() {

View File

@ -9,11 +9,12 @@ import (
"time"
"github.com/fatih/color"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/spf13/cobra"
tcmd "github.com/iyear/tdl/cmd"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
func TestCommand(t *testing.T) {

View File

@ -8,9 +8,10 @@ import (
"strconv"
"github.com/google/uuid"
"github.com/tidwall/gjson"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/tidwall/gjson"
)
var _ = Describe("Test tdl upload", FlakeAttempts(3), func() {
@ -42,7 +43,7 @@ var _ = Describe("Test tdl upload", FlakeAttempts(3), func() {
checkFiles := func(chat string, n int, expected []string) {
By("check if files are uploaded")
var exportFile = filepath.Join(dir, "export.json")
exportFile := filepath.Join(dir, "export.json")
exec(cmd, []string{"chat", "-c", chat, "export", "-T", "last", "-i", strconv.Itoa(n), "-o", exportFile}, true)
exportBytes, err := os.ReadFile(exportFile)