Skip to content

Commit

Permalink
Merge pull request #31 from csatib02/feat/lint-and-ci
Browse files Browse the repository at this point in the history
Add improved linters
  • Loading branch information
Envoy49 committed Jan 22, 2024
2 parents fcb1aa3 + fcdabbe commit d427091
Show file tree
Hide file tree
Showing 19 changed files with 102 additions and 54 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ jobs:
- name: Build
run: go build -v ./...

lint:
name: Lint
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Setup Go cache
uses: actions/cache@v2
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ github.job }}-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ github.job }}-${{ runner.os }}-go-
- name: Lint
run: make lint

artifacts:
name: Artifacts
uses: ./.github/workflows/artifacts.yaml
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ Thumbs.db
temp.txt


dist/
/dist/
/build/
/bin/
50 changes: 23 additions & 27 deletions golangci.yml → .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,42 +1,34 @@
run:
deadline: 5m # Maximum duration for linting processes
timeout: 5m # Maximum duration for linting processes
modules-download-mode: readonly # Prevents updating the go.mod file during linting for reproducibility

linters:
enable:
- lll # Ensures lines do not exceed a specified length
- errcheck # Checks for unchecked errors in the code
- gofmt # Formats Go code according to standard style guidelines
- govet # Analyzes code for suspicious constructs
- golint # Provides suggestions for Go coding style and documentation
- gocyclo # Measures cyclomatic complexity of functions
- ineffassign # Detects ineffectual assignments in Go code
- structcheck # Identifies unused struct fields
- varcheck # Detects unused global variables and constants
- deadcode # Finds unused code in the program
- unconvert # Identifies unnecessary type conversions
- bodyclose # Ensures HTTP response bodies are closed properly
- dogsled # Checks for excessive use of blank identifiers in assignments
- dupl # Reports duplicated code blocks
- gochecknoglobals # Checks for global variables
- gochecknoinits # Warns about the use of init functions
- goconst # Finds repeated strings that could be replaced by constants
- gocritic # A comprehensive linter with a wide range of checks
- gocyclo # Measures cyclomatic complexity of functions
- gofmt # Formats Go code according to standard style guidelines
- godot # Checks if comments end in a period
- goimports # Formats import lines, adding missing ones and removing unreferenced ones
- gosec # Scans code for security vulnerabilities
- gomnd # Detects magic numbers and suggests naming them
- gomodguard # Manages allowed and blocked Go module dependencies
- gosimple # Simplifies Go code by applying simplifications
- staticcheck # Performs a range of static analysis checks for cleaner, more reliable, and more efficient Go code
- dupl # Reports duplicated code blocks
- nakedret # Identifies naked returns in functions larger than a specified size
- govet # Analyzes code for suspicious constructs
- ineffassign # Detects ineffectual assignments in Go code
- lll # Ensures lines do not exceed a specified length
- misspell # Checks for misspelled words in the code
- nakedret # Identifies naked returns in functions larger than a specified size
- revive # Performs a range of static analysis checks for cleaner, more reliable, and more efficient Go code
- prealloc # Suggests preallocations in loops to improve performance
- gosec # Scans code for security vulnerabilities
- interfacer # Suggests narrower interface types
- unparam # Reports unused function parameters
- funlen # Warns about long functions
- wsl # Enforces consistent whitespace usage
- staticcheck # Performs a range of static analysis checks for cleaner, more reliable, and more efficient Go code
- testpackage # Encourages writing tests in a separate _test package
- bodyclose # Ensures HTTP response bodies are closed properly
- gocritic # A comprehensive linter with a wide range of checks
- gochecknoglobals # Checks for global variables
- gochecknoinits # Warns about the use of init functions
- dogsled # Checks for excessive use of blank identifiers in assignments
- gomnd # Detects magic numbers and suggests naming them
- unconvert # Identifies unnecessary type conversions
- unparam # Reports unused function parameters

linters-settings:
errcheck:
Expand All @@ -47,6 +39,10 @@ linters-settings:
tab-width: 8 # Width of a tab character (for line length calculation)
gocyclo:
min-complexity: 15 # Minimum complexity threshold to trigger a warning or error
misspell:
locale: US
revive:
confidence: 0

# Exclude specific files or paths from linting by certain linters
issues:
Expand Down
22 changes: 20 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export PATH := $(abspath bin/):${PATH}

# Dependency versions
GOLANGCI_VERSION = 1.53.3
GORELEASER_VERSION = 1.18.2

##@ General
Expand Down Expand Up @@ -36,11 +37,28 @@ binary-snapshot: ## Build binary snapshot
test: ## Run tests
go test -race -v ./

.PHONY: lint
lint: lint-go
lint: ## Run linters

.PHONY: lint-go
lint-go:
golangci-lint run $(if ${CI},--out-format github-actions,)

.PHONY: fmt
fmt: ## Format code
golangci-lint run --fix

##@ Dependencies

deps: bin/goreleaser
deps: golangci-lint goreleaser
deps: ## Install dependencies

bin/goreleaser:
golangci-lint:
@mkdir -p bin
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- v${GOLANGCI_VERSION}

goreleaser:
@mkdir -p bin
go install github.com/sigstore/cosign/v2/cmd/cosign@latest
curl -sfL https://goreleaser.com/static/run | VERSION=v${GORELEASER_VERSION} bash -s -- --version
2 changes: 1 addition & 1 deletion commands/player/saved.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func SavedCommand(cfg *config.Config) *cobra.Command {
token := server.ReadUserModifyTokenOrFetchFromServer(cfg)
// instead of Calling Play function, we are adding song to the queue and using Next function
// otherwise song playing further nexts is not possible, seems like an API limitation.
//Play(token, result.PlayUrl)
// Play(token, result.PlayUrl)
AddToQueue(cfg, token, result.PlayUrl)
Next(cfg, token, false)
}
Expand Down
5 changes: 3 additions & 2 deletions commands/search/search.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package search

import (
"net/url"

"github.com/envoy49/go-spotify-cli/commands/cmdTypes"
"github.com/envoy49/go-spotify-cli/config"
"net/url"

"github.com/envoy49/go-spotify-cli/commands"
"github.com/envoy49/go-spotify-cli/commands/player"
Expand Down Expand Up @@ -66,7 +67,7 @@ func search(cfg *config.Config, accessToken string, query *cmdTypes.SpotifySearc
if len(result.PlayUrl) > 0 {
// instead of Calling Play function, we are adding song to the queue and using Next function
// otherwise song playing further nexts is not possible
//player.Play(accessToken, playUrl)
// player.Play(accessToken, playUrl)
player.AddToQueue(cfg, accessToken, result.PlayUrl)
player.Next(cfg, accessToken, false)
}
Expand Down
3 changes: 2 additions & 1 deletion commands/search/searchPrompt/createSelectionPrompt.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package searchPrompt

import (
"strings"

"github.com/envoy49/go-spotify-cli/commands/cmdTypes"
"github.com/manifoldco/promptui"
"strings"
)

func CreateSelectionPrompt(config *cmdTypes.SelectionPromptConfig) promptui.Select {
Expand Down
7 changes: 4 additions & 3 deletions commands/search/searchPrompt/searchQueryPrompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package searchPrompt

import (
"fmt"
"github.com/envoy49/go-spotify-cli/commands/cmdTypes"
"github.com/manifoldco/promptui"
"log"
"strconv"
"strings"

"github.com/envoy49/go-spotify-cli/commands/cmdTypes"
"github.com/manifoldco/promptui"
)

// var searchTypes = []string{"Track", "Artist", "Album", "Playlist", "Show", "Episode", "Audiobook"}
// var searchTypes = []string{"Track", "Artist", "Album", "Playlist", "Show", "Episode", "Audiobook"}.
var searchTypes = []string{"Track", "Episode"}

func SpotifySearchQueryPrompt() (error, *cmdTypes.SpotifySearchQuery) {
Expand Down
5 changes: 3 additions & 2 deletions commands/search/searchPrompt/searchResultsAlbumsPrompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package searchPrompt

import (
"fmt"
"strconv"
"strings"

"github.com/envoy49/go-spotify-cli/commands"
"github.com/envoy49/go-spotify-cli/commands/cmdTypes"
"github.com/manifoldco/promptui"
"github.com/sirupsen/logrus"
"strconv"
"strings"
)

func AlbumsResultsPrompt(albums *cmdTypes.Albums) string {
Expand Down
5 changes: 3 additions & 2 deletions commands/search/searchPrompt/searchResultsArtistsPrompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package searchPrompt

import (
"fmt"
"strconv"
"strings"

"github.com/envoy49/go-spotify-cli/commands"
"github.com/envoy49/go-spotify-cli/commands/cmdTypes"
"github.com/manifoldco/promptui"
"github.com/sirupsen/logrus"
"strconv"
"strings"
)

func ArtistsResultsPrompt(artists *cmdTypes.Artists) string {
Expand Down
5 changes: 3 additions & 2 deletions commands/search/searchPrompt/searchResultsAudiobooksPrompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package searchPrompt

import (
"fmt"
"strconv"
"strings"

"github.com/envoy49/go-spotify-cli/commands"
"github.com/envoy49/go-spotify-cli/commands/cmdTypes"
"github.com/manifoldco/promptui"
"github.com/sirupsen/logrus"
"strconv"
"strings"
)

func AudiobooksResultsPrompt(audiobooks *cmdTypes.Audiobooks) string {
Expand Down
5 changes: 3 additions & 2 deletions commands/search/searchPrompt/searchResultsEpisodesPrompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package searchPrompt

import (
"fmt"
"os"
"strconv"

"github.com/envoy49/go-spotify-cli/commands"
"github.com/envoy49/go-spotify-cli/commands/cmdTypes"
"github.com/sirupsen/logrus"
"golang.org/x/term"
"os"
"strconv"
)

func EpisodesResultsPrompt(episodes *cmdTypes.Episodes) *cmdTypes.SearchPromptResults {
Expand Down
3 changes: 2 additions & 1 deletion commands/search/searchPrompt/searchResultsPlaylistsPrompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package searchPrompt

import (
"fmt"
"strings"

"github.com/envoy49/go-spotify-cli/commands"
"github.com/envoy49/go-spotify-cli/commands/cmdTypes"
"github.com/manifoldco/promptui"
"github.com/sirupsen/logrus"
"strings"
)

func PlaylistsResultsPrompt(playlists *cmdTypes.Playlists) string {
Expand Down
5 changes: 3 additions & 2 deletions commands/search/searchPrompt/searchResultsPrompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package searchPrompt

import (
"encoding/json"
"github.com/envoy49/go-spotify-cli/commands/cmdTypes"
"log"

"github.com/envoy49/go-spotify-cli/commands/cmdTypes"
)

func SpotifySearchResultsPrompt(body []byte) *cmdTypes.SearchPromptResults {
Expand All @@ -18,7 +19,7 @@ func SpotifySearchResultsPrompt(body []byte) *cmdTypes.SearchPromptResults {
return TracksResultsPrompt(response.Tracks)
case response.Episodes != nil:
return EpisodesResultsPrompt(response.Episodes)
//case response.Albums != nil:
// case response.Albums != nil:
// return AlbumsResultsPrompt(response.Albums)
//case response.Artists != nil:
// return ArtistsResultsPrompt(response.Artists)
Expand Down
3 changes: 2 additions & 1 deletion commands/search/searchPrompt/searchResultsShowsPrompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package searchPrompt

import (
"fmt"
"strings"

"github.com/envoy49/go-spotify-cli/commands"
"github.com/envoy49/go-spotify-cli/commands/cmdTypes"
"github.com/manifoldco/promptui"
"github.com/sirupsen/logrus"
"strings"
)

func ShowsResultsPrompt(shows *cmdTypes.Shows) string {
Expand Down
5 changes: 3 additions & 2 deletions commands/search/searchPrompt/searchResultsTracksPrompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package searchPrompt

import (
"fmt"
"os"
"strconv"

"github.com/envoy49/go-spotify-cli/commands"
"github.com/envoy49/go-spotify-cli/commands/cmdTypes"
"github.com/sirupsen/logrus"
"golang.org/x/term"
"os"
"strconv"
)

func TracksResultsPrompt(tracks *cmdTypes.Tracks) *cmdTypes.SearchPromptResults {
Expand Down
2 changes: 1 addition & 1 deletion config/writeSecretsToHome.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func WriteSecretsToHomeDirectory(cfg *Config) (*Config, error) { // pass this a
// Marshal the configData into YAML format
data, err := yaml.Marshal(configData)
if err != nil {
logrus.WithError(err).Error("Error marshalling data to YAML")
logrus.WithError(err).Error("Error marshaling data to YAML")
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion config/writeTokenToHome.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func WriteTokenToHomeDirectory(configData *CombinedTokenStructure, initiateChann
// Marshal the updated data
data, err := yaml.Marshal(currentData)
if err != nil {
logrus.WithError(err).Error("Error marshalling data to YAML")
logrus.WithError(err).Error("Error marshaling data to YAML")
return
}

Expand Down
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Server(ctx context.Context, cfg *config.Config) {
}
}()

// Listen for the context being cancelled
// Listen for the context being canceled
<-ctx.Done()

// Create a deadline to wait for
Expand Down

0 comments on commit d427091

Please sign in to comment.