Skip to content

Commit

Permalink
fix: update linter and fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
DrPsychick committed May 7, 2024
1 parent c07e5e4 commit 83314e8
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 559 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
lint:
runs-on: ubuntu-latest
env:
GOLANGCI_LINT_VERSION: v1.51.2
GOLANGCI_LINT_VERSION: v1.58.0
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
- name: Set up Go
Expand Down
5 changes: 3 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
run:
tests: false
deadline: 5m
timeout: 5m

linters-settings:
cyclop:
Expand Down Expand Up @@ -32,14 +32,15 @@ linters:
- forcetypeassert
- gochecknoglobals
- gochecknoinits
- goerr113
- err113
- gomnd
- nlreturn
- wrapcheck
- wsl
- tagliatelle
- varnamelen
- ireturn
- depguard

issues:
exclude-use-default: false
Expand Down
559 changes: 22 additions & 537 deletions go.sum

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions l10n/l10n.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"math/rand"
"strings"
"time"
)

// Default keys.
Expand Down Expand Up @@ -71,7 +70,6 @@ const (
)

func init() {
rand.Seed(time.Now().UTC().UnixNano())
}

// LocaleError defines the interface for locale errors.
Expand Down Expand Up @@ -217,7 +215,7 @@ func Resolve(name string) (LocaleInstance, error) {
// Register registers a new locale and fails if it already exists.
func (r *Registry) Register(l LocaleInstance, opts ...RegisterFunc) error {
if l.GetName() == "" {
return fmt.Errorf("cannot register locale with no name")
return errors.New("cannot register locale with no name")
}
if _, ok := r.locales[l.GetName()]; ok {
return fmt.Errorf("locale %s already registered", l.GetName())
Expand Down
4 changes: 0 additions & 4 deletions l10n/l10n_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package l10n_test
import (
"github.com/drpsychick/go-alexa-lambda/l10n"
"github.com/stretchr/testify/assert"
"math/rand"
"testing"
"time"
)

const Greeting string = "greeting"
Expand Down Expand Up @@ -185,8 +183,6 @@ func TestLocale_GetAny(t *testing.T) {
// requires registry setup
assert.NotNil(t, registry)

rand.Seed(time.Now().Unix())

l, err := registry.Resolve("de-DE")
assert.NoError(t, err)
assert.Contains(t, deDE.TextSnippets[Greeting], l.GetAny(Greeting))
Expand Down
6 changes: 3 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

// Handler represents an alexa request handler.
type Handler interface {
Serve(*ResponseBuilder, *RequestEnvelope)
Serve(builder *ResponseBuilder, req *RequestEnvelope)
ServeHTTP(w http.ResponseWriter, r *http.Request)
}

Expand Down Expand Up @@ -63,7 +63,7 @@ type Server struct {
}

// Invoke calls the handler, and serializes the response.
func (s *Server) Invoke(ctx context.Context, payload []byte) ([]byte, error) {
func (s *Server) Invoke(_ context.Context, payload []byte) ([]byte, error) {
req := &RequestEnvelope{}
if err := jsoniter.Unmarshal(payload, req); err != nil {
return nil, err
Expand Down Expand Up @@ -183,7 +183,7 @@ func (m *ServeMux) HandleIntentFunc(intent string, handler HandlerFunc) {

// fallbackHandler returns a fatal error card.
func fallbackHandler(err error) HandlerFunc {
return HandlerFunc(func(b *ResponseBuilder, r *RequestEnvelope) {
return HandlerFunc(func(b *ResponseBuilder, _ *RequestEnvelope) {
b.WithSimpleCard("Fatal error", "error: "+err.Error()).
WithShouldEndSession(true)
})
Expand Down
2 changes: 1 addition & 1 deletion skill/model_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func (i *modelIntentBuilder) WithConfirmation(c bool) *modelIntentBuilder {
}

// WithIntentConfirmationPrompt does nothing.
func (i *modelIntentBuilder) WithIntentConfirmationPrompt(prompt string) *modelIntentBuilder {
func (i *modelIntentBuilder) WithIntentConfirmationPrompt(_ string) *modelIntentBuilder {
// TODO: WithIntentConfirmationPrompt
// add a prompt to the model `model.WithIntentConfirmationPrompt(intent, slot)`
// add variations `model.IntentConfirmationPrompt(intent, slot).WithVariation("PlainText")`
Expand Down
17 changes: 9 additions & 8 deletions skill/skill_builder.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package skill

import (
"errors"
"fmt"

"github.com/drpsychick/go-alexa-lambda/l10n"
Expand Down Expand Up @@ -110,7 +111,7 @@ func (s *SkillBuilder) WithDefaultLocale(locale string) *SkillBuilder {
func (s *SkillBuilder) WithDefaultLocaleTestingInstructions(instructions string) *SkillBuilder {
dl := s.registry.GetDefault()
if dl == nil {
s.error = fmt.Errorf("no default locale registered")
s.error = errors.New("no default locale registered")
return s
}
dl.Set(s.instructions, []string{instructions})
Expand Down Expand Up @@ -140,7 +141,7 @@ func (s *SkillBuilder) Locale(locale string) *SkillLocaleBuilder {
// Model returns the corresponding model builder.
func (s *SkillBuilder) Model() *modelBuilder { //nolint:revive
if s.model == nil {
s.error = fmt.Errorf("no model builder registered")
s.error = errors.New("no model builder registered")
return &modelBuilder{}
}
return s.model
Expand All @@ -152,7 +153,7 @@ func (s *SkillBuilder) Build() (*Skill, error) { //nolint:funlen,cyclop
return nil, s.error
}
if s.registry == nil || len(s.registry.GetLocales()) == 0 {
return nil, fmt.Errorf("no locales registered to build")
return nil, errors.New("no locales registered to build")
}
// create SkillLocaleBuilders from registry
if s.locales == nil || len(s.locales) == 0 {
Expand All @@ -165,7 +166,7 @@ func (s *SkillBuilder) Build() (*Skill, error) { //nolint:funlen,cyclop
// get default locale
dl := s.registry.GetDefault()
if dl == nil {
return nil, fmt.Errorf("no default locale defined")
return nil, errors.New("no default locale defined")
}

skill := &Skill{
Expand All @@ -175,7 +176,7 @@ func (s *SkillBuilder) Build() (*Skill, error) { //nolint:funlen,cyclop
},
}
if s.category == "" {
return nil, fmt.Errorf("skill category is required")
return nil, errors.New("skill category is required")
}
skill.Manifest.Publishing.Category = s.category
// TODO: ensure unique occurrence?
Expand Down Expand Up @@ -236,7 +237,7 @@ func (s *SkillBuilder) BuildModels() (map[string]*Model, error) {
return nil, s.error
}
if s.model == nil {
return nil, fmt.Errorf("no model to build")
return nil, errors.New("no model to build")
}
return s.model.Build()
}
Expand Down Expand Up @@ -460,10 +461,10 @@ func (l *SkillLocaleBuilder) BuildPublishingLocale() (LocaleDef, error) {
l.locale,
)
}
if len(loc.GetAll(l.skillExamples)) > 3 {
if len(loc.GetAll(l.skillExamples)) > 3 { //nolint:mnd
return LocaleDef{}, fmt.Errorf("only 3 examplePhrases are allowed (%s)", l.locale)
}
if len(loc.GetAll(l.skillKeywords)) > 3 {
if len(loc.GetAll(l.skillKeywords)) > 3 { //nolint:mnd
return LocaleDef{}, fmt.Errorf("only 3 keywords are allowed (%s)", l.locale)
}
return LocaleDef{
Expand Down

0 comments on commit 83314e8

Please sign in to comment.