Skip to content

Commit 7f47877

Browse files
committed
fix(codacy): address BestPractice, Documentation and CodeStyle issues
- Remove superfluous else blocks in util.go by restructuring if-return chains - Add proper doc comments for all exported vars in util package - Add missing package comments for streaming/benchmark_test and updater - Rename unused mock parameters to _ in discord, providers test files - Fix zero-value initializer in perf.go (var c int64 = 0 → var c int64) - Fix export comment formats in tmdb.go, discord.go, anime.go, api.go
1 parent b0c2e17 commit 7f47877

14 files changed

Lines changed: 190 additions & 172 deletions

File tree

internal/api/anime.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ func enrichAnimeData(anime *models.Anime) error {
164164
return nil
165165
}
166166

167+
// ParseAnimes extracts a list of anime entries from a GoAnime search results page.
167168
func ParseAnimes(doc *goquery.Document) []models.Anime {
168169
var animes []models.Anime
169170

@@ -180,6 +181,7 @@ func ParseAnimes(doc *goquery.Document) []models.Anime {
180181
return animes
181182
}
182183

184+
// FetchAnimeFromAniList queries the AniList GraphQL API by anime name.
183185
func FetchAnimeFromAniList(animeName string) (*models.AniListResponse, error) {
184186
return FetchAnimeFromAniListWithURL(animeName, "")
185187
}
@@ -345,6 +347,7 @@ func generateSearchVariations(cleanedName string) []string {
345347
return variations
346348
}
347349

350+
// CleanTitle removes common suffixes, tags, and source annotations from an anime title.
348351
func CleanTitle(title string) string {
349352
cleaned := title
350353

internal/api/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ func SafeTransport(timeout time.Duration) *http.Transport {
129129

130130
return &http.Transport{
131131
// Custom dial function for regular (non-TLS) connections.
132-
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
132+
DialContext: func(_ context.Context, network, addr string) (net.Conn, error) {
133133
return dialFunc(network, addr, timeout, nil)
134134
},
135135
// Custom dial function for TLS connections, using the specified TLS configuration.
136-
DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
136+
DialTLSContext: func(_ context.Context, network, addr string) (net.Conn, error) {
137137
return dialFunc(network, addr, timeout, tlsConfig)
138138
},
139139
// Set the timeout for the TLS handshake process.

internal/api/movie/tmdb.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import (
1616
)
1717

1818
const (
19-
// TMDB API base URL
19+
// TMDBBaseURL is the TMDB REST API base URL.
2020
TMDBBaseURL = "https://api.themoviedb.org/3"
21-
// TMDB image base URL
21+
// TMDBImageBaseURL is the TMDB image CDN base URL.
2222
TMDBImageBaseURL = "https://image.tmdb.org/t/p"
2323
)
2424

internal/api/providers/goyabu_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type mockUnifiedScraper struct {
5757
streamArg string
5858
}
5959

60-
func (m *mockUnifiedScraper) SearchAnime(query string, options ...any) ([]*models.Anime, error) {
60+
func (m *mockUnifiedScraper) SearchAnime(_ string, _ ...any) ([]*models.Anime, error) {
6161
return nil, nil
6262
}
6363

@@ -66,7 +66,7 @@ func (m *mockUnifiedScraper) GetAnimeEpisodes(animeURL string) ([]models.Episode
6666
return m.episodes, nil
6767
}
6868

69-
func (m *mockUnifiedScraper) GetStreamURL(episodeURL string, options ...any) (string, map[string]string, error) {
69+
func (m *mockUnifiedScraper) GetStreamURL(episodeURL string, _ ...any) (string, map[string]string, error) {
7070
m.streamArg = episodeURL
7171
if m.streamCalls < len(m.streamErrs) {
7272
err := m.streamErrs[m.streamCalls]

internal/api/providers/nineanime_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type nineAnimeMockScraper struct {
2020
streamArg string
2121
}
2222

23-
func (m *nineAnimeMockScraper) SearchAnime(query string, options ...any) ([]*models.Anime, error) {
23+
func (m *nineAnimeMockScraper) SearchAnime(_ string, _ ...any) ([]*models.Anime, error) {
2424
return nil, nil
2525
}
2626

@@ -29,7 +29,7 @@ func (m *nineAnimeMockScraper) GetAnimeEpisodes(animeURL string) ([]models.Episo
2929
return m.episodes, nil
3030
}
3131

32-
func (m *nineAnimeMockScraper) GetStreamURL(episodeURL string, options ...any) (string, map[string]string, error) {
32+
func (m *nineAnimeMockScraper) GetStreamURL(episodeURL string, _ ...any) (string, map[string]string, error) {
3333
m.streamArg = episodeURL
3434
if m.streamErr != nil {
3535
return "", nil, m.streamErr

internal/api/providers/registry_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func (p *testProvider) FetchEpisodes(_ context.Context, anime *models.Anime) ([]
2323
return anime.Episodes, nil
2424
}
2525

26-
func (p *testProvider) FetchStreamURL(_ context.Context, episode *models.Episode, anime *models.Anime, quality string) (string, error) {
26+
func (p *testProvider) FetchStreamURL(_ context.Context, _ *models.Episode, _ *models.Anime, quality string) (string, error) {
2727
return quality, nil
2828
}
2929

@@ -32,7 +32,7 @@ func TestForKindCachesProviderInstances(t *testing.T) {
3232

3333
kind := source.SourceKind("TestCacheProvider")
3434
var calls atomic.Int32
35-
RegisterProvider(kind, func(sm *scraper.ScraperManager) Provider {
35+
RegisterProvider(kind, func(_ *scraper.ScraperManager) Provider {
3636
calls.Add(1)
3737
return &testProvider{kind: kind}
3838
})
@@ -60,7 +60,7 @@ func TestForKindConcurrentFactoryCall(t *testing.T) {
6060

6161
kind := source.SourceKind("TestConcurrentProvider")
6262
var calls atomic.Int32
63-
RegisterProvider(kind, func(sm *scraper.ScraperManager) Provider {
63+
RegisterProvider(kind, func(_ *scraper.ScraperManager) Provider {
6464
calls.Add(1)
6565
return &testProvider{kind: kind}
6666
})
@@ -196,7 +196,7 @@ func TestForKindAndRegisterProviderConcurrentSafe(t *testing.T) {
196196
done := make(chan struct{})
197197
go func() {
198198
defer close(done)
199-
RegisterProvider(kind, func(sm *scraper.ScraperManager) Provider {
199+
RegisterProvider(kind, func(_ *scraper.ScraperManager) Provider {
200200
calls.Add(1)
201201
return &testProvider{kind: kind}
202202
})

internal/discord/discord.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package discord manages Discord Rich Presence integration for GoAnime playback sessions.
12
package discord
23

34
import (

internal/discord/test/discord_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type MockMPVClient struct {
1919

2020
// MockMPVSendCommand é uma implementação mock de mpvSendCommand
2121
// mockMPVSendCommand é uma função mock simples
22-
func mockMPVSendCommand(socketPath string, args []any) (any, error) {
22+
func mockMPVSendCommand(_ string, args []any) (any, error) {
2323
// Simula a resposta do MPV para time-pos
2424
if len(args) >= 2 && args[0] == "get_property" && args[1] == "time-pos" {
2525
return 630.0, nil // 10 minutos e 30 segundos em segundos
@@ -90,7 +90,7 @@ func TestGetCurrentPlaybackPosition(t *testing.T) {
9090

9191
t.Run("Should handle MPV send command error", func(t *testing.T) {
9292
// Arrange
93-
errorMockFunc := func(socketPath string, args []any) (any, error) {
93+
errorMockFunc := func(_ string, _ []any) (any, error) {
9494
return nil, fmt.Errorf("connection failed")
9595
}
9696

@@ -244,7 +244,7 @@ func TestRichPresenceIntegration(t *testing.T) {
244244
func TestFetchDuration(t *testing.T) {
245245
t.Run("Should fetch duration successfully", func(t *testing.T) {
246246
// Arrange
247-
mockFunc := func(socketPath string, args []any) (any, error) {
247+
mockFunc := func(_ string, args []any) (any, error) {
248248
if len(args) >= 2 && args[0] == "get_property" && args[1] == "duration" {
249249
return 1440.0, nil // 24 minutes in seconds
250250
}
@@ -281,7 +281,7 @@ func TestFetchDuration(t *testing.T) {
281281

282282
t.Run("Should handle MPV error gracefully", func(t *testing.T) {
283283
// Arrange
284-
errorMockFunc := func(socketPath string, args []any) (any, error) {
284+
errorMockFunc := func(_ string, _ []any) (any, error) {
285285
return nil, fmt.Errorf("connection failed")
286286
}
287287

@@ -302,7 +302,7 @@ func TestFetchDuration(t *testing.T) {
302302

303303
// Variable to capture the callback result
304304
var callbackCalled bool
305-
callback := func(durSec int) {
305+
callback := func(_ int) {
306306
callbackCalled = true
307307
}
308308

@@ -315,7 +315,7 @@ func TestFetchDuration(t *testing.T) {
315315

316316
t.Run("Should handle nil duration response", func(t *testing.T) {
317317
// Arrange
318-
nilMockFunc := func(socketPath string, args []any) (any, error) {
318+
nilMockFunc := func(_ string, _ []any) (any, error) {
319319
return nil, nil // Simulate nil response
320320
}
321321

@@ -336,7 +336,7 @@ func TestFetchDuration(t *testing.T) {
336336

337337
// Variable to capture the callback result
338338
var callbackCalled bool
339-
callback := func(durSec int) {
339+
callback := func(_ int) {
340340
callbackCalled = true
341341
}
342342

@@ -349,7 +349,7 @@ func TestFetchDuration(t *testing.T) {
349349

350350
t.Run("Should use instance socket path when parameter is empty", func(t *testing.T) {
351351
// Arrange
352-
mockFunc := func(socketPath string, args []any) (any, error) {
352+
mockFunc := func(_ string, args []any) (any, error) {
353353
if len(args) >= 2 && args[0] == "get_property" && args[1] == "duration" {
354354
return 600.0, nil // 10 minutes in seconds
355355
}

internal/discord/test/superflix_discord_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919

2020
// mockMPVFullState provides a complete mock MPV that returns all properties
2121
// needed by getPrecisePlaybackState and updateDiscordPresence
22-
func mockMPVFullState(socketPath string, args []any) (any, error) {
22+
func mockMPVFullState(_ string, args []any) (any, error) {
2323
if len(args) >= 2 && args[0] == "get_property" {
2424
switch args[1] {
2525
case "time-pos":

internal/streaming/benchmark_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package streaming provides URL classification and download strategy helpers.
12
package streaming
23

34
import "testing"

0 commit comments

Comments
 (0)