diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..08a6304 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,121 @@ +linters-settings: + dupl: + threshold: 100 + funlen: + lines: 100 + statements: 50 + gci: + local-prefixes: github.com/baez90/goveal + goconst: + min-len: 2 + min-occurrences: 2 + gocritic: + enabled-tags: + - diagnostic + - opinionated + - performance + disabled-checks: + - ifElseChain + - octalLiteral + - wrapperFunc + settings: + hugeParam: + sizeThreshold: 200 + gocyclo: + min-complexity: 15 + goimports: + local-prefixes: github.com/baez90/goveal + golint: + min-confidence: 0 + gomnd: + settings: + mnd: + # don't include the "operation" and "assign" + checks: + - argument + - case + - condition + - return + govet: + check-shadowing: true + importas: + no-unaliased: true + alias: [] + lll: + line-length: 140 + maligned: + suggest-new: true + misspell: + locale: US + nolintlint: + allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space) + allow-unused: false # report any unused nolint directives + require-explanation: false # don't require an explanation for nolint directives + require-specific: false # don't require nolint directives to be specific about which linter is being skipped + +linters: + # please, do not use `enable-all`: it's deprecated and will be removed soon. + # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint + disable-all: true + enable: + - deadcode + - dogsled + - dupl + - errcheck + - exhaustive + - exportloopref + - funlen + - gocognit + - goconst + - gocritic + - gocyclo + - godox + - gofumpt + - goimports + - gomnd + - gosec + - gosimple + - govet + - importas + - ineffassign + - lll + - misspell + - nakedret + - nestif + - noctx + - nolintlint + - paralleltest + - prealloc + - promlinter + - staticcheck + - structcheck + - stylecheck + - testpackage + - thelper + - typecheck + - unconvert + - unparam + - varcheck + - whitespace + + #- unused + +issues: + # Excluding configuration per-path, per-linter, per-text and per-source + exclude-rules: + - path: _test\.go + linters: + - gomnd + - funlen + +run: + build-tags: + - sudo + skip-dirs: + - internal/mock + skip-files: + - ".*\\.pb\\.go$" + - ".*.mock.\\.go$" + +service: + golangci-lint-version: 1.43.x # use the fixed version to not introduce new linters unexpectedly diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..afc7d0d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,18 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + - repo: https://github.com/tekwizely/pre-commit-golang + rev: v1.0.0-beta.5 + hooks: + - id: go-mod-tidy-repo + - id: go-fumpt + args: + - -w + - id: go-imports + args: + - -local=github.com/baez90/goveal + - -w + - id: golangci-lint-repo-mod + args: + - --fast + - --fix diff --git a/api/config.go b/api/config.go index 5050560..0402047 100644 --- a/api/config.go +++ b/api/config.go @@ -11,9 +11,9 @@ type ConfigAPI struct { } func RegisterConfigAPI(app *fiber.App, cfg *config.Components) { - cfgApi := &ConfigAPI{cfg: cfg} - app.Get("/api/v1/config/reveal", cfgApi.RevealConfig) - app.Get("/api/v1/config/mermaid", cfgApi.MermaidConfig) + cfgAPI := &ConfigAPI{cfg: cfg} + app.Get("/api/v1/config/reveal", cfgAPI.RevealConfig) + app.Get("/api/v1/config/mermaid", cfgAPI.MermaidConfig) } func (a *ConfigAPI) RevealConfig(ctx *fiber.Ctx) error { diff --git a/assets/assets.go b/assets/assets.go index e5a6a07..d36538c 100644 --- a/assets/assets.go +++ b/assets/assets.go @@ -2,7 +2,5 @@ package assets import "embed" -var ( - //go:embed reveal mermaid/mermaid.min.js - Assets embed.FS -) +//go:embed reveal mermaid/mermaid.min.js +var Assets embed.FS diff --git a/cmd/goveal/root.go b/cmd/goveal/root.go index 5439626..6ff78b2 100644 --- a/cmd/goveal/root.go +++ b/cmd/goveal/root.go @@ -23,6 +23,7 @@ import ( "github.com/baez90/goveal/config" ) +//nolint:lll // explanations are rather long var ( cfgFile string rootCmd = &cobra.Command{ diff --git a/config/components.go b/config/components.go index a650f09..b92e3b3 100644 --- a/config/components.go +++ b/config/components.go @@ -1,21 +1,19 @@ package config -var ( - defaults = map[string]interface{}{ - "mermaid.theme": "forest", - "theme": "beige", - "codeTheme": "monokai", - "transition": TransitionNone, - "controlsLayout": ControlsLayoutEdges, - "controls": true, - "progress": true, - "history": true, - "center": true, - "slideNumber": true, - "menu.numbers": true, - "menu.useTextContentForMissingTitles": true, - } -) +var defaults = map[string]interface{}{ + "mermaid.theme": "forest", + "theme": "beige", + "codeTheme": "monokai", + "transition": TransitionNone, + "controlsLayout": ControlsLayoutEdges, + "controls": true, + "progress": true, + "history": true, + "center": true, + "slideNumber": true, + "menu.numbers": true, + "menu.useTextContentForMissingTitles": true, +} const ( TransitionNone Transition = "none" @@ -65,10 +63,5 @@ type ( ) func (t Transition) String() string { - switch t { - case TransitionNone: - return "none" - default: - return string(t) - } + return string(t) } diff --git a/fs/layered.go b/fs/layered.go index 1c37416..554b369 100644 --- a/fs/layered.go +++ b/fs/layered.go @@ -5,8 +5,10 @@ import ( "os" ) -type FS = fs.FS -type File = fs.File +type ( + FS = fs.FS + File = fs.File +) var Dir = os.DirFS diff --git a/rendering/render_to_reveal.go b/rendering/render_to_reveal.go index 83e4259..09b700b 100644 --- a/rendering/render_to_reveal.go +++ b/rendering/render_to_reveal.go @@ -47,6 +47,7 @@ type RevealRenderer struct { hasNotes bool } +//nolint:gocyclo // under construction func (r *RevealRenderer) RenderHook(w io.Writer, node ast.Node, entering bool) (ast.WalkStatus, bool) { switch b := node.(type) { case *ast.Document: @@ -82,7 +83,7 @@ func (r *RevealRenderer) RenderHook(w io.Writer, node ast.Node, entering bool) ( return ast.GoToNext, false case *ast.HorizontalRule: next := peekNextRuler(b) - var input = string(b.Literal) + input := string(b.Literal) if next != nil { input += string(next.Literal) } @@ -185,6 +186,7 @@ func getAttributesFromChildSpan(node ast.Node) []template.HTMLAttr { } func extractElementAttributes(htmlSpan *ast.HTMLSpan) (attrs []template.HTMLAttr) { + const expectedNumberOfMatches = 4 htmlComment := string(htmlSpan.Literal) if htmlComment == "" { return nil @@ -192,7 +194,7 @@ func extractElementAttributes(htmlSpan *ast.HTMLSpan) (attrs []template.HTMLAttr matches := htmlElementAttributesRegexp.FindAllStringSubmatch(htmlComment, -1) attrs = make([]template.HTMLAttr, 0, len(matches)) for idx := range matches { - if len(matches[idx]) != 4 { + if len(matches[idx]) != expectedNumberOfMatches { continue } diff --git a/rendering/state.go b/rendering/state.go index a926b13..010816e 100644 --- a/rendering/state.go +++ b/rendering/state.go @@ -18,34 +18,32 @@ const ( StateTypeNested ) -var ( - EventMapping = map[EventType][]byte{ - EventTypeHorizontalSplit: []byte(` +var EventMapping = map[EventType][]byte{ + EventTypeHorizontalSplit: []byte(`
`), - EventTypeVerticalSplit: []byte(` + EventTypeVerticalSplit: []byte(`
`), - EventTypeHorizontalEnd: []byte(` + EventTypeHorizontalEnd: []byte(`
`), - EventTypeVerticalSplitEnd: []byte(` + EventTypeVerticalSplitEnd: []byte(`
`), - EventTypeVerticalDocumentEnd: []byte(` + EventTypeVerticalDocumentEnd: []byte(`
`), - EventTypeVerticalVerticalSplit: []byte(` + EventTypeVerticalVerticalSplit: []byte(`
`), - } -) +} func NewStateMachine(verticalSplit, horizontalSplit string) *StateMachine { return &StateMachine{