Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Lint

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
cache: true

- name: Install golangci-lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2
Copy link

Copilot AI May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider caching the installed golangci-lint binary in the workflow to reduce setup time during CI runs.

Copilot uses AI. Check for mistakes.

- name: Run golangci-lint
run: golangci-lint run --timeout=5m

- name: Run go vet
run: go vet ./...

- name: Check formatting
run: |
if [ -n "$(gofmt -l .)" ]; then
echo "The following files are not formatted correctly:"
gofmt -l .
exit 1
fi
27 changes: 26 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
vendor/
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
temaster

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
vendor/

# Go workspace file
go.work

# IDE specific files
.idea/
.vscode/
*.swp
*.swo
.DS_Store
36 changes: 36 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
linters:
enable:
- gofmt
- revive
- govet
- errcheck
- staticcheck
- gosimple
- ineffassign
- unused
- misspell
- gosec

run:
timeout: 5m
skip-dirs:
- vendor/

issues:
exclude-rules:
- path: _test\.go
linters:
- errcheck

linters-settings:
govet:
check-shadowing: true
gocyclo:
min-complexity: 15
dupl:
threshold: 100
Copy link

Copilot AI May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Review the duplication threshold value to ensure it aligns with current codebase standards and complexity.

Suggested change
threshold: 100
threshold: 50

Copilot uses AI. Check for mistakes.
goconst:
min-len: 2
min-occurrences: 3
misspell:
locale: US
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.PHONY: build test lint clean

# Build the application
build:
go build -o temaster ./cmd

# Run tests
test:
go test -v ./...

# Run linters
lint:
golangci-lint run

# Clean build artifacts
clean:
rm -f temaster
rm -f *.test
rm -f *.out
Comment on lines +18 to +19
Copy link

Copilot AI May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider refining the clean target by using more specific file patterns to prevent accidentally deleting unintended files.

Suggested change
rm -f *.test
rm -f *.out
rm -f *_test.test
rm -f coverage.out

Copilot uses AI. Check for mistakes.

# Install development tools
tools:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ A command-line tool that turns any [Spotify](https://open.spotify.com/) playlist

### Option 2: Build from source
1. Clone this repository
2. Build the project:
2. Build the project using one of these methods:
```bash
go build -o temaster
# Using go build
go build -o temaster ./cmd
Copy link

Copilot AI May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include a brief note that clarifies the use of './cmd' as the build target to assist new contributors in understanding the project structure.

Copilot uses AI. Check for mistakes.

# Or using make
make build
```
3. Move the executable to your PATH (optional):
```bash
Expand Down
14 changes: 8 additions & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package main

import (
"crypto/rand"
Copy link

Copilot AI May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imports are currently unsorted; please group standard library imports together and alphabetize them (e.g., crypto/rand, fmt, math/big, os, os/exec, runtime, strings), then separate third-party imports with a blank line.

Copilot uses AI. Check for mistakes.
"fmt"
"math/rand"
"math/big"
"os"
"os/exec"
"runtime"
"strings"
"time"

"github.com/meacuna/temaster/internal/spotify"
)
Expand Down Expand Up @@ -63,9 +63,6 @@ func main() {

fmt.Printf("This playlist has %d songs\n", len(tracks))

// Create a new random source with current time
r := rand.New(rand.NewSource(time.Now().UnixNano()))

// Create a map to track played songs
playedTracks := make(map[string]bool)
remainingTracks := len(tracks)
Expand All @@ -89,7 +86,12 @@ func main() {
// Get a random track that hasn't been played yet
var track string
for {
randomIndex := r.Intn(len(tracks))
n, err := rand.Int(rand.Reader, big.NewInt(int64(len(tracks))))
if err != nil {
fmt.Printf("Error generating random number: %v\n", err)
Comment on lines 87 to +91
Copy link

Copilot AI May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If crypto/rand fails, the error is printed and the loop continues, which could lead to an infinite loop if the error persists. Consider adding a fallback mechanism or fail-fast after a certain number of consecutive errors.

Copilot uses AI. Check for mistakes.
os.Exit(1)
}
randomIndex := int(n.Int64())
track = tracks[randomIndex]
if !playedTracks[track] {
playedTracks[track] = true
Expand Down