Add golangci-lint
This commit is contained in:
parent
3f847e0b8b
commit
33dadaff87
9 changed files with 176 additions and 43 deletions
121
.golangci.yml
Normal file
121
.golangci.yml
Normal file
|
@ -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
|
18
.pre-commit-config.yaml
Normal file
18
.pre-commit-config.yaml
Normal file
|
@ -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
|
|
@ -11,9 +11,9 @@ type ConfigAPI struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterConfigAPI(app *fiber.App, cfg *config.Components) {
|
func RegisterConfigAPI(app *fiber.App, cfg *config.Components) {
|
||||||
cfgApi := &ConfigAPI{cfg: cfg}
|
cfgAPI := &ConfigAPI{cfg: cfg}
|
||||||
app.Get("/api/v1/config/reveal", cfgApi.RevealConfig)
|
app.Get("/api/v1/config/reveal", cfgAPI.RevealConfig)
|
||||||
app.Get("/api/v1/config/mermaid", cfgApi.MermaidConfig)
|
app.Get("/api/v1/config/mermaid", cfgAPI.MermaidConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *ConfigAPI) RevealConfig(ctx *fiber.Ctx) error {
|
func (a *ConfigAPI) RevealConfig(ctx *fiber.Ctx) error {
|
||||||
|
|
|
@ -2,7 +2,5 @@ package assets
|
||||||
|
|
||||||
import "embed"
|
import "embed"
|
||||||
|
|
||||||
var (
|
//go:embed reveal mermaid/mermaid.min.js
|
||||||
//go:embed reveal mermaid/mermaid.min.js
|
var Assets embed.FS
|
||||||
Assets embed.FS
|
|
||||||
)
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"github.com/baez90/goveal/config"
|
"github.com/baez90/goveal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//nolint:lll // explanations are rather long
|
||||||
var (
|
var (
|
||||||
cfgFile string
|
cfgFile string
|
||||||
rootCmd = &cobra.Command{
|
rootCmd = &cobra.Command{
|
||||||
|
|
|
@ -1,21 +1,19 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
var (
|
var defaults = map[string]interface{}{
|
||||||
defaults = map[string]interface{}{
|
"mermaid.theme": "forest",
|
||||||
"mermaid.theme": "forest",
|
"theme": "beige",
|
||||||
"theme": "beige",
|
"codeTheme": "monokai",
|
||||||
"codeTheme": "monokai",
|
"transition": TransitionNone,
|
||||||
"transition": TransitionNone,
|
"controlsLayout": ControlsLayoutEdges,
|
||||||
"controlsLayout": ControlsLayoutEdges,
|
"controls": true,
|
||||||
"controls": true,
|
"progress": true,
|
||||||
"progress": true,
|
"history": true,
|
||||||
"history": true,
|
"center": true,
|
||||||
"center": true,
|
"slideNumber": true,
|
||||||
"slideNumber": true,
|
"menu.numbers": true,
|
||||||
"menu.numbers": true,
|
"menu.useTextContentForMissingTitles": true,
|
||||||
"menu.useTextContentForMissingTitles": true,
|
}
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TransitionNone Transition = "none"
|
TransitionNone Transition = "none"
|
||||||
|
@ -65,10 +63,5 @@ type (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (t Transition) String() string {
|
func (t Transition) String() string {
|
||||||
switch t {
|
return string(t)
|
||||||
case TransitionNone:
|
|
||||||
return "none"
|
|
||||||
default:
|
|
||||||
return string(t)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,10 @@ import (
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FS = fs.FS
|
type (
|
||||||
type File = fs.File
|
FS = fs.FS
|
||||||
|
File = fs.File
|
||||||
|
)
|
||||||
|
|
||||||
var Dir = os.DirFS
|
var Dir = os.DirFS
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ type RevealRenderer struct {
|
||||||
hasNotes bool
|
hasNotes bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//nolint:gocyclo // under construction
|
||||||
func (r *RevealRenderer) RenderHook(w io.Writer, node ast.Node, entering bool) (ast.WalkStatus, bool) {
|
func (r *RevealRenderer) RenderHook(w io.Writer, node ast.Node, entering bool) (ast.WalkStatus, bool) {
|
||||||
switch b := node.(type) {
|
switch b := node.(type) {
|
||||||
case *ast.Document:
|
case *ast.Document:
|
||||||
|
@ -82,7 +83,7 @@ func (r *RevealRenderer) RenderHook(w io.Writer, node ast.Node, entering bool) (
|
||||||
return ast.GoToNext, false
|
return ast.GoToNext, false
|
||||||
case *ast.HorizontalRule:
|
case *ast.HorizontalRule:
|
||||||
next := peekNextRuler(b)
|
next := peekNextRuler(b)
|
||||||
var input = string(b.Literal)
|
input := string(b.Literal)
|
||||||
if next != nil {
|
if next != nil {
|
||||||
input += string(next.Literal)
|
input += string(next.Literal)
|
||||||
}
|
}
|
||||||
|
@ -185,6 +186,7 @@ func getAttributesFromChildSpan(node ast.Node) []template.HTMLAttr {
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractElementAttributes(htmlSpan *ast.HTMLSpan) (attrs []template.HTMLAttr) {
|
func extractElementAttributes(htmlSpan *ast.HTMLSpan) (attrs []template.HTMLAttr) {
|
||||||
|
const expectedNumberOfMatches = 4
|
||||||
htmlComment := string(htmlSpan.Literal)
|
htmlComment := string(htmlSpan.Literal)
|
||||||
if htmlComment == "" {
|
if htmlComment == "" {
|
||||||
return nil
|
return nil
|
||||||
|
@ -192,7 +194,7 @@ func extractElementAttributes(htmlSpan *ast.HTMLSpan) (attrs []template.HTMLAttr
|
||||||
matches := htmlElementAttributesRegexp.FindAllStringSubmatch(htmlComment, -1)
|
matches := htmlElementAttributesRegexp.FindAllStringSubmatch(htmlComment, -1)
|
||||||
attrs = make([]template.HTMLAttr, 0, len(matches))
|
attrs = make([]template.HTMLAttr, 0, len(matches))
|
||||||
for idx := range matches {
|
for idx := range matches {
|
||||||
if len(matches[idx]) != 4 {
|
if len(matches[idx]) != expectedNumberOfMatches {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,34 +18,32 @@ const (
|
||||||
StateTypeNested
|
StateTypeNested
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var EventMapping = map[EventType][]byte{
|
||||||
EventMapping = map[EventType][]byte{
|
EventTypeHorizontalSplit: []byte(`
|
||||||
EventTypeHorizontalSplit: []byte(`
|
|
||||||
</section>
|
</section>
|
||||||
<section>`),
|
<section>`),
|
||||||
EventTypeVerticalSplit: []byte(`
|
EventTypeVerticalSplit: []byte(`
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
<section>
|
<section>
|
||||||
`),
|
`),
|
||||||
EventTypeHorizontalEnd: []byte(`
|
EventTypeHorizontalEnd: []byte(`
|
||||||
</section>
|
</section>
|
||||||
`),
|
`),
|
||||||
EventTypeVerticalSplitEnd: []byte(`
|
EventTypeVerticalSplitEnd: []byte(`
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
<section>`),
|
<section>`),
|
||||||
EventTypeVerticalDocumentEnd: []byte(`
|
EventTypeVerticalDocumentEnd: []byte(`
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
`),
|
`),
|
||||||
EventTypeVerticalVerticalSplit: []byte(`
|
EventTypeVerticalVerticalSplit: []byte(`
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
<section>`),
|
<section>`),
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
func NewStateMachine(verticalSplit, horizontalSplit string) *StateMachine {
|
func NewStateMachine(verticalSplit, horizontalSplit string) *StateMachine {
|
||||||
return &StateMachine{
|
return &StateMachine{
|
||||||
|
|
Loading…
Reference in a new issue