Skip to content

Commit

Permalink
Fix linter config and lint problems
Browse files Browse the repository at this point in the history
  • Loading branch information
yangtfu committed Jan 7, 2025
1 parent 669d559 commit 5f02b52
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI
on:
push:
branches:
- bilibili
- main
pull_request:
branches:
- main
Expand Down
11 changes: 3 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
linters:
enable:
- structcheck
- varcheck
- staticcheck
- unconvert
- gofmt
- goimports
- golint
- revive
- ineffassign
- vet
- govet
- unused
- misspell
- bodyclose
- interfacer
- unconvert
- maligned
# - depguard
- nakedret
- prealloc
- whitespace
Expand All @@ -24,6 +19,6 @@ linters:

run:
deadline: 3m
skip-dirs:
issues.exclude-dirs:
- bin
- docs
3 changes: 1 addition & 2 deletions cmd/podsync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,8 @@ func main() {
log.Infof("running listener at %s", srv.Addr)
if cfg.Server.TLS {
return srv.ListenAndServeTLS(cfg.Server.CertificatePath, cfg.Server.KeyFilePath)
} else {
return srv.ListenAndServe()
}
return srv.ListenAndServe()
})

group.Go(func() error {
Expand Down
4 changes: 2 additions & 2 deletions pkg/builder/bilibili.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (b *BilibiliBuilder) queryFeed(feed *model.Feed, info *model.Info) error {
switch info.LinkType {
case model.TypeChannel:
//TODO channel surpport
return errors.New("Bilibili channel not supported.")
return errors.New("bilibili channel not supported")
case model.TypeUser:
// query user info
mid, err := strconv.Atoi(info.ItemID)
Expand Down Expand Up @@ -69,7 +69,7 @@ func (b *BilibiliBuilder) queryFeed(feed *model.Feed, info *model.Info) error {
}
}

func (b *BilibiliBuilder) Build(ctx context.Context, cfg *feed.Config) (*model.Feed, error) {
func (b *BilibiliBuilder) Build(_ context.Context, cfg *feed.Config) (*model.Feed, error) {
info, err := ParseURL(cfg.URL)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/builder/soundcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type SoundCloudBuilder struct {
client *soundcloudapi.API
}

func (s *SoundCloudBuilder) Build(_ctx context.Context, cfg *feed.Config) (*model.Feed, error) {
func (s *SoundCloudBuilder) Build(_ context.Context, cfg *feed.Config) (*model.Feed, error) {
info, err := ParseURL(cfg.URL)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/builder/vimeo.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (v *VimeoBuilder) queryVideos(getVideos getVideosFunc, feed *model.Feed) er
}
}

func (v *VimeoBuilder) Build(ctx context.Context, cfg *feed.Config) (*model.Feed, error) {
func (v *VimeoBuilder) Build(_ context.Context, cfg *feed.Config) (*model.Feed, error) {
info, err := ParseURL(cfg.URL)
if err != nil {
return nil, err
Expand Down
10 changes: 3 additions & 7 deletions pkg/db/badger.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ func (b *Badger) AddFeed(_ context.Context, feedID string, feed *model.Feed) err
for _, episode := range feed.Episodes {
episodeKey := b.getKey(episodePath, feedID, episode.ID)
err := b.setObj(txn, episodeKey, episode, false)
if err == nil || err == model.ErrAlreadyExists {
// Do nothing
} else {
if !(err == nil || err == model.ErrAlreadyExists) {
return errors.Wrapf(err, "failed to save episode %q", feedID)
}
}
Expand Down Expand Up @@ -226,7 +224,7 @@ func (b *Badger) DeleteEpisode(feedID, episodeID string) error {
})
}

func (b *Badger) WalkEpisodes(ctx context.Context, feedID string, cb func(episode *model.Episode) error) error {
func (b *Badger) WalkEpisodes(_ context.Context, feedID string, cb func(episode *model.Episode) error) error {
return b.db.View(func(txn *badger.Txn) error {
return b.walkEpisodes(txn, feedID, cb)
})
Expand Down Expand Up @@ -274,9 +272,7 @@ func (b *Badger) setObj(txn *badger.Txn, key []byte, obj interface{}, overwrite
_, err := txn.Get(key)
if err == nil {
return model.ErrAlreadyExists
} else if err == badger.ErrKeyNotFound {
// Key not found, do nothing
} else {
} else if err != badger.ErrKeyNotFound {
return errors.Wrap(err, "failed to check whether key exists")
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/db/badger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestBadger_DeleteFeed(t *testing.T) {
assert.NoError(t, err)

called := 0
err = db.WalkFeeds(testCtx, func(feed *model.Feed) error {
err = db.WalkFeeds(testCtx, func(_ *model.Feed) error {
called++
return nil
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/feed/xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (p timeSlice) Swap(i, j int) {
p[i], p[j] = p[j], p[i]
}

func Build(_ctx context.Context, feed *model.Feed, cfg *Config, hostname string) (*itunes.Podcast, error) {
func Build(_ context.Context, feed *model.Feed, cfg *Config, hostname string) (*itunes.Podcast, error) {
const (
podsyncGenerator = "Podsync generator (support us at https://github.com/mxpv/podsync)"
defaultCategory = "TV & Film"
Expand Down
6 changes: 3 additions & 3 deletions pkg/fs/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ func (l *Local) Open(name string) (http.File, error) {
return os.Open(path)
}

func (l *Local) Delete(_ctx context.Context, name string) error {
func (l *Local) Delete(_ context.Context, name string) error {
path := filepath.Join(l.rootDir, name)
return os.Remove(path)
}

func (l *Local) Create(_ctx context.Context, name string, reader io.Reader) (int64, error) {
func (l *Local) Create(_ context.Context, name string, reader io.Reader) (int64, error) {
var (
logger = log.WithField("name", name)
path = filepath.Join(l.rootDir, name)
Expand Down Expand Up @@ -71,7 +71,7 @@ func (l *Local) copyFile(source io.Reader, destinationPath string) (int64, error
return written, nil
}

func (l *Local) Size(_ctx context.Context, name string) (int64, error) {
func (l *Local) Size(_ context.Context, name string) (int64, error) {
file, err := l.Open(name)
if err != nil {
return 0, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/fs/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func NewS3(c S3Config) (*S3, error) {
}, nil
}

func (s *S3) Open(_name string) (http.File, error) {
func (s *S3) Open(_ string) (http.File, error) {
return nil, errors.New("serving files from S3 is not supported")
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/fs/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ func (m *mockS3API) PutObjectRequest(input *s3.PutObjectInput) (*request.Request
return req, &s3.PutObjectOutput{}
}

func (m *mockS3API) HeadObjectWithContext(ctx aws.Context, input *s3.HeadObjectInput, opts ...request.Option) (*s3.HeadObjectOutput, error) {
func (m *mockS3API) HeadObjectWithContext(_ aws.Context, input *s3.HeadObjectInput, _ ...request.Option) (*s3.HeadObjectOutput, error) {
if _, ok := m.files[*input.Key]; ok {
return &s3.HeadObjectOutput{ContentLength: aws.Int64(int64(len(m.files[*input.Key])))}, nil
}
return nil, awserr.New("NotFound", "", nil)
}

func (m *mockS3API) DeleteObjectWithContext(ctx aws.Context, input *s3.DeleteObjectInput, opts ...request.Option) (*s3.DeleteObjectOutput, error) {
func (m *mockS3API) DeleteObjectWithContext(_ aws.Context, input *s3.DeleteObjectInput, _ ...request.Option) (*s3.DeleteObjectOutput, error) {
if _, ok := m.files[*input.Key]; ok {
delete(m.files, *input.Key)
return &s3.DeleteObjectOutput{}, nil
Expand Down
4 changes: 1 addition & 3 deletions services/update/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,7 @@ func (u *Manager) downloadEpisodes(ctx context.Context, feedConfig *feed.Config)
}

continue
} else if os.IsNotExist(err) {
// Will download, do nothing here
} else {
} else if !os.IsNotExist(err) {
logger.WithError(err).Error("failed to stat file")
return err
}
Expand Down

0 comments on commit 5f02b52

Please sign in to comment.