diff --git a/.golangci.yml b/.golangci.yml index 61c0492..d72b95c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,21 +1,8 @@ linters-settings: govet: check-shadowing: true - golint: - min-confidence: 0.8 - gocyclo: - min-complexity: 15 - maligned: - suggest-new: true - dupl: - threshold: 100 - goconst: - min-len: 2 - min-occurrences: 2 misspell: locale: US - lll: - line-length: 140 gocritic: enabled-tags: - performance @@ -34,7 +21,6 @@ linters: - revive - govet - unconvert - - megacheck - unused - gas - misspell diff --git a/app/api/server.go b/app/api/server.go index 0e404e7..42c69f0 100644 --- a/app/api/server.go +++ b/app/api/server.go @@ -135,7 +135,7 @@ func (s *Server) router() *chi.Mux { rrss.Get("/feeds", s.getFeedsPageCtrl) }) - router.Get("/config", func(w http.ResponseWriter, r *http.Request) { rest.RenderJSON(w, s.Conf) }) + router.Get("/config", func(w http.ResponseWriter, _ *http.Request) { rest.RenderJSON(w, s.Conf) }) router.Route("/yt", func(r chi.Router) { diff --git a/app/api/server_test.go b/app/api/server_test.go index 3f6bd75..75c536d 100644 --- a/app/api/server_test.go +++ b/app/api/server_test.go @@ -43,7 +43,7 @@ func TestServer_Run(t *testing.T) { func TestServer_getFeedCtrl(t *testing.T) { store := &mocks.StoreMock{ - LoadFunc: func(fmFeed string, max int, skipJunk bool) ([]feed.Item, error) { + LoadFunc: func(string, int, bool) ([]feed.Item, error) { return []feed.Item{ { GUID: "guid1", @@ -126,7 +126,7 @@ func TestServer_getFeedCtrl(t *testing.T) { func TestServer_getFeedCtrlExtendDateTitle(t *testing.T) { store := &mocks.StoreMock{ - LoadFunc: func(fmFeed string, max int, skipJunk bool) ([]feed.Item, error) { + LoadFunc: func(string, int, bool) ([]feed.Item, error) { return []feed.Item{ { GUID: "guid1", @@ -198,7 +198,7 @@ func TestServer_getFeedCtrlExtendDateTitle(t *testing.T) { func TestServer_getFeedCtrlFeedImage(t *testing.T) { store := &mocks.StoreMock{ - LoadFunc: func(fmFeed string, max int, skipJunk bool) ([]feed.Item, error) { + LoadFunc: func(string, int, bool) ([]feed.Item, error) { return []feed.Item{ { GUID: "guid1", @@ -272,10 +272,10 @@ func TestServer_getFeedCtrlFeedImage(t *testing.T) { func TestServer_regenerateRSSCtrl(t *testing.T) { yt := &mocks.YoutubeSvcMock{ - RSSFeedFunc: func(cinfo youtube.FeedInfo) (string, error) { + RSSFeedFunc: func(youtube.FeedInfo) (string, error) { return "blah", nil }, - StoreRSSFunc: func(chanID string, rss string) error { + StoreRSSFunc: func(string, string) error { return nil }, } @@ -324,7 +324,7 @@ func TestServer_regenerateRSSCtrl(t *testing.T) { func TestServer_removeEntryCtrl(t *testing.T) { yt := &mocks.YoutubeSvcMock{ - RemoveEntryFunc: func(entry ytfeed.Entry) error { + RemoveEntryFunc: func(ytfeed.Entry) error { return nil }, } diff --git a/app/feed/item_test.go b/app/feed/item_test.go index a24f28b..f35e8c3 100644 --- a/app/feed/item_test.go +++ b/app/feed/item_test.go @@ -35,7 +35,7 @@ func TestGetFilename(t *testing.T) { func TestDownloadAudioIfRequestError(t *testing.T) { var ts *httptest.Server - ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ts = httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) { ts.CloseClientConnections() })) @@ -49,7 +49,7 @@ func TestDownloadAudioIfRequestError(t *testing.T) { } func TestDownloadAudio(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) w.Header().Set("Content-Length", "4") fmt.Fprint(w, "abcd") diff --git a/app/feed/parser_test.go b/app/feed/parser_test.go index 9ef6c00..320ce64 100644 --- a/app/feed/parser_test.go +++ b/app/feed/parser_test.go @@ -71,7 +71,7 @@ func TestFeedParse(t *testing.T) { Umputun, Bobuk, Gray, Ksenks, Alek.sysnonadultЕженедельные импровизации на хай–тек темы ` - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) _, err := w.Write([]byte(testFeed)) assert.NoError(t, err) @@ -84,7 +84,7 @@ func TestFeedParse(t *testing.T) { } func TestFeedParseBadBody(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) _, err := w.Write([]byte("bad")) assert.NoError(t, err) @@ -96,7 +96,7 @@ func TestFeedParseBadBody(t *testing.T) { func TestFeedParseHttpError(t *testing.T) { var ts *httptest.Server - ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ts = httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) { ts.CloseClientConnections() })) diff --git a/app/proc/processor_test.go b/app/proc/processor_test.go index ab4a99f..076767f 100644 --- a/app/proc/processor_test.go +++ b/app/proc/processor_test.go @@ -23,11 +23,11 @@ import ( func TestProcessor_DoRemoveOldItems(t *testing.T) { lgr.Setup(lgr.Debug) - tgNotif := &mocks.TelegramNotifMock{SendFunc: func(chanID string, item feed.Item) error { + tgNotif := &mocks.TelegramNotifMock{SendFunc: func(string, feed.Item) error { return nil }} - twitterNotif := &mocks.TwitterNotifMock{SendFunc: func(item feed.Item) error { + twitterNotif := &mocks.TwitterNotifMock{SendFunc: func(feed.Item) error { return nil }} @@ -41,7 +41,7 @@ func TestProcessor_DoRemoveOldItems(t *testing.T) { testFeed, err := os.ReadFile("./testdata/rss1.xml") require.NoError(t, err) - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) w.Header().Set("Content-Length", strconv.Itoa(len(testFeed))) _, e := w.Write(testFeed) @@ -159,11 +159,11 @@ func TestProcessor_DoRemoveOldItems(t *testing.T) { func TestProcessor_DoLoadMaxItems(t *testing.T) { - tgNotif := &mocks.TelegramNotifMock{SendFunc: func(chanID string, item feed.Item) error { + tgNotif := &mocks.TelegramNotifMock{SendFunc: func(string, feed.Item) error { return nil }} - twitterNotif := &mocks.TwitterNotifMock{SendFunc: func(item feed.Item) error { + twitterNotif := &mocks.TwitterNotifMock{SendFunc: func(feed.Item) error { return nil }} @@ -177,7 +177,7 @@ func TestProcessor_DoLoadMaxItems(t *testing.T) { testFeed, err := os.ReadFile("./testdata/rss2.xml") require.NoError(t, err) - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) w.Header().Set("Content-Length", strconv.Itoa(len(testFeed))) _, e := w.Write(testFeed) @@ -255,11 +255,11 @@ func TestProcessor_DoLoadMaxItems(t *testing.T) { func TestProcessor_DoSkipItems(t *testing.T) { - tgNotif := &mocks.TelegramNotifMock{SendFunc: func(chanID string, item feed.Item) error { + tgNotif := &mocks.TelegramNotifMock{SendFunc: func(string, feed.Item) error { return nil }} - twitterNotif := &mocks.TwitterNotifMock{SendFunc: func(item feed.Item) error { + twitterNotif := &mocks.TwitterNotifMock{SendFunc: func(feed.Item) error { return nil }} @@ -273,7 +273,7 @@ func TestProcessor_DoSkipItems(t *testing.T) { testFeed, err := os.ReadFile("./testdata/rss1.xml") require.NoError(t, err) - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) w.Header().Set("Content-Length", strconv.Itoa(len(testFeed))) _, e := w.Write(testFeed) diff --git a/app/proc/telegram_test.go b/app/proc/telegram_test.go index cdb5994..f1771f5 100644 --- a/app/proc/telegram_test.go +++ b/app/proc/telegram_test.go @@ -204,13 +204,13 @@ func TestTelegramClient_sendAudio(t *testing.T) { defer ts.Close() dur := &mocks.DurationServiceMock{ - FileFunc: func(fname string) int { + FileFunc: func(string) int { return 12345 }, } snd := &mocks.TelegramSenderMock{ - SendFunc: func(audio tb.Audio, bot *tb.Bot, recipient tb.Recipient, sendOptions *tb.SendOptions) (*tb.Message, error) { + SendFunc: func(tb.Audio, *tb.Bot, tb.Recipient, *tb.SendOptions) (*tb.Message, error) { return nil, nil }, } @@ -235,13 +235,13 @@ func TestSendIfSendAudioFailed(t *testing.T) { defer ts.Close() dur := &mocks.DurationServiceMock{ - FileFunc: func(fname string) int { + FileFunc: func(string) int { return 12345 }, } snd := &mocks.TelegramSenderMock{ - SendFunc: func(audio tb.Audio, bot *tb.Bot, recipient tb.Recipient, sendOptions *tb.SendOptions) (*tb.Message, error) { + SendFunc: func(tb.Audio, *tb.Bot, tb.Recipient, *tb.SendOptions) (*tb.Message, error) { return nil, errors.New("error while sending audio") }, } @@ -263,13 +263,13 @@ func TestSend(t *testing.T) { defer ts.Close() dur := &mocks.DurationServiceMock{ - FileFunc: func(fname string) int { + FileFunc: func(string) int { return 12345 }, } snd := &mocks.TelegramSenderMock{ - SendFunc: func(audio tb.Audio, bot *tb.Bot, recipient tb.Recipient, sendOptions *tb.SendOptions) (*tb.Message, error) { + SendFunc: func(tb.Audio, *tb.Bot, tb.Recipient, *tb.SendOptions) (*tb.Message, error) { return &tb.Message{Text: "Some test message"}, nil }, } @@ -296,13 +296,13 @@ func TestSendTextIfAudioLarge(t *testing.T) { defer ts.Close() dur := &mocks.DurationServiceMock{ - FileFunc: func(fname string) int { + FileFunc: func(string) int { return 12345 }, } snd := &mocks.TelegramSenderMock{ - SendFunc: func(audio tb.Audio, bot *tb.Bot, recipient tb.Recipient, sendOptions *tb.SendOptions) (*tb.Message, error) { + SendFunc: func(tb.Audio, *tb.Bot, tb.Recipient, *tb.SendOptions) (*tb.Message, error) { return nil, errors.New("Request Entity Too Large") }, } @@ -369,18 +369,18 @@ func mockTelegramServer(h http.HandlerFunc) *httptest.Server { _, _ = w.Write([]byte(getMeResp)) }) - router.Get("/download/some.mp3", func(w http.ResponseWriter, r *http.Request) { + router.Get("/download/some.mp3", func(w http.ResponseWriter, _ *http.Request) { // taken from https://github.com/mathiasbynens/small/blob/master/mp3.mp3 smallMP3File := []byte{54, 53, 53, 48, 55, 54, 51, 52, 48, 48, 51, 49, 56, 52, 51, 50, 48, 55, 54, 49, 54, 55, 49, 55, 49, 55, 55, 49, 53, 49, 49, 56, 51, 51, 49, 52, 51, 56, 50, 49, 50, 56, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48} _, _ = w.Write(smallMP3File) }) - router.Post("/bottest-token/sendMessage", func(w http.ResponseWriter, r *http.Request) { + router.Post("/bottest-token/sendMessage", func(w http.ResponseWriter, _ *http.Request) { _, _ = w.Write([]byte(`{"ok": true, "result": {"text": "Some test message"}}`)) }) - router.Post("/bot/sendAudio", func(w http.ResponseWriter, r *http.Request) { + router.Post("/bot/sendAudio", func(w http.ResponseWriter, _ *http.Request) { _, _ = w.Write([]byte(`{"ok": true, "result": {"id": 1}}`)) }) diff --git a/app/proc/twitter_test.go b/app/proc/twitter_test.go index cb1e858..85e3daf 100644 --- a/app/proc/twitter_test.go +++ b/app/proc/twitter_test.go @@ -21,7 +21,7 @@ func TestNewTwitterClient(t *testing.T) { AccessSecret: "d", } - client := NewTwitterClient(twiAuth, func(item feed.Item) string { + client := NewTwitterClient(twiAuth, func(feed.Item) string { return "" }, nil) @@ -49,7 +49,7 @@ func TestTwitterSendIfFieldsTwitterAuthEmpty(t *testing.T) { AccessSecret: tt.accessSecret, } - twitterFmtFn := func(item feed.Item) string { + twitterFmtFn := func(feed.Item) string { return "" } @@ -83,10 +83,10 @@ func TestCleanText(t *testing.T) { } func TestTwitterSend(t *testing.T) { - twitPoster := &mocks.TweetPosterMock{PostTweetFunc: func(msg string, v url.Values) (anaconda.Tweet, error) { + twitPoster := &mocks.TweetPosterMock{PostTweetFunc: func(string, url.Values) (anaconda.Tweet, error) { return anaconda.Tweet{}, nil }} - formatter := func(item feed.Item) string { + formatter := func(feed.Item) string { return "formatted text" } diff --git a/app/youtube/service_test.go b/app/youtube/service_test.go index f93fc8b..797fb60 100644 --- a/app/youtube/service_test.go +++ b/app/youtube/service_test.go @@ -23,7 +23,7 @@ func TestService_Do(t *testing.T) { tempDir := t.TempDir() shortVideo := filepath.Join(tempDir, "122b672d10e77708b51c041f852615dc0eedf354.mp3") chans := &mocks.ChannelServiceMock{ - GetFunc: func(ctx context.Context, chanID string, feedType ytfeed.Type) ([]ytfeed.Entry, error) { + GetFunc: func(_ context.Context, chanID string, _ ytfeed.Type) ([]ytfeed.Entry, error) { return []ytfeed.Entry{ {ChannelID: chanID, VideoID: "vid1", Title: "title1", Published: time.Now()}, {ChannelID: chanID, VideoID: "vid2", Title: "title2", Published: time.Now()}, @@ -33,7 +33,7 @@ func TestService_Do(t *testing.T) { }, } downloader := &mocks.DownloaderServiceMock{ - GetFunc: func(ctx context.Context, id string, fname string) (string, error) { + GetFunc: func(_ context.Context, _ string, fname string) (string, error) { fpath := filepath.Join(tempDir, fname+".mp3") _, err := os.Create(fpath) // nolint require.NoError(t, err) @@ -131,7 +131,7 @@ func TestService_Do(t *testing.T) { func TestService_DoIsAllowedFilter(t *testing.T) { chans := &mocks.ChannelServiceMock{ - GetFunc: func(ctx context.Context, chanID string, feedType ytfeed.Type) ([]ytfeed.Entry, error) { + GetFunc: func(_ context.Context, chanID string, _ ytfeed.Type) ([]ytfeed.Entry, error) { return []ytfeed.Entry{ {ChannelID: chanID, VideoID: "vid1", Title: "Prefix1: title1", Published: time.Now()}, {ChannelID: chanID, VideoID: "vid2", Title: "Prefix2: title2", Published: time.Now()}, @@ -140,13 +140,13 @@ func TestService_DoIsAllowedFilter(t *testing.T) { }, } downloader := &mocks.DownloaderServiceMock{ - GetFunc: func(ctx context.Context, id string, fname string) (string, error) { + GetFunc: func(_ context.Context, _ string, fname string) (string, error) { return "/tmp/" + fname + ".mp3", nil }, } duration := &mocks.DurationServiceMock{ - FileFunc: func(fname string) int { + FileFunc: func(string) int { return 1234 }, } @@ -224,7 +224,7 @@ func TestService_DoIsAllowedFilter(t *testing.T) { // nolint:dupl // test if very similar to TestService_RSSFeed func TestService_RSSFeed(t *testing.T) { storeSvc := &mocks.StoreServiceMock{ - LoadFunc: func(channelID string, max int) ([]ytfeed.Entry, error) { + LoadFunc: func(string, int) ([]ytfeed.Entry, error) { res := []ytfeed.Entry{ {ChannelID: "channel1", VideoID: "vid1", Title: "title1", File: "/tmp/file1.mp3"}, {ChannelID: "channel1", VideoID: "vid2", Title: "title2", File: "/tmp/file2.mp3"}, @@ -269,7 +269,7 @@ func TestService_RSSFeed(t *testing.T) { // nolint:dupl // test if very similar to TestService_RSSFeed func TestService_RSSFeedPlayList(t *testing.T) { storeSvc := &mocks.StoreServiceMock{ - LoadFunc: func(channelID string, max int) ([]ytfeed.Entry, error) { + LoadFunc: func(string, int) ([]ytfeed.Entry, error) { res := []ytfeed.Entry{ {ChannelID: "channel1", VideoID: "vid1", Title: "title1", File: "/tmp/file1.mp3"}, {ChannelID: "channel1", VideoID: "vid2", Title: "title2", File: "/tmp/file2.mp3"}, @@ -344,7 +344,7 @@ func TestService_makeFileName(t *testing.T) { func TestService_update(t *testing.T) { duration := &mocks.DurationServiceMock{ - FileFunc: func(fname string) int { + FileFunc: func(string) int { return 1234 }, } @@ -400,7 +400,7 @@ func TestService_totalEntriesToKeep(t *testing.T) { func TestService_countAllEntries(t *testing.T) { storeSvc := &mocks.StoreServiceMock{ - LoadFunc: func(channelID string, max int) ([]ytfeed.Entry, error) { + LoadFunc: func(channelID string, _ int) ([]ytfeed.Entry, error) { switch channelID { case "channel1": return []ytfeed.Entry{{}, {}, {}}, nil @@ -431,7 +431,7 @@ func TestService_countAllEntries(t *testing.T) { func TestService_oldestEntry(t *testing.T) { dt := time.Date(2022, 4, 11, 11, 35, 17, 0, time.UTC) storeSvc := &mocks.StoreServiceMock{ - LoadFunc: func(channelID string, max int) ([]ytfeed.Entry, error) { + LoadFunc: func(channelID string, _ int) ([]ytfeed.Entry, error) { switch channelID { case "channel1": return []ytfeed.Entry{ @@ -475,7 +475,7 @@ func TestService_oldestEntry(t *testing.T) { func TestService_newestEntry(t *testing.T) { dt := time.Date(2022, 4, 11, 11, 35, 17, 0, time.UTC) storeSvc := &mocks.StoreServiceMock{ - LoadFunc: func(channelID string, max int) ([]ytfeed.Entry, error) { + LoadFunc: func(channelID string, _ int) ([]ytfeed.Entry, error) { switch channelID { case "channel1": return []ytfeed.Entry{