Add golangci-lint

This commit is contained in:
Peter 2021-12-22 20:27:43 +01:00
parent 3f847e0b8b
commit 33dadaff87
Signed by: prskr
GPG key ID: C1DB5D2E8DB512F9
9 changed files with 176 additions and 43 deletions

121
.golangci.yml Normal file
View 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
View 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

View file

@ -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 {

View file

@ -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

View file

@ -23,6 +23,7 @@ import (
"github.com/baez90/goveal/config"
)
//nolint:lll // explanations are rather long
var (
cfgFile string
rootCmd = &cobra.Command{

View file

@ -1,7 +1,6 @@
package config
var (
defaults = map[string]interface{}{
var defaults = map[string]interface{}{
"mermaid.theme": "forest",
"theme": "beige",
"codeTheme": "monokai",
@ -14,8 +13,7 @@ var (
"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)
}
}

View file

@ -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

View file

@ -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
}

View file

@ -18,8 +18,7 @@ const (
StateTypeNested
)
var (
EventMapping = map[EventType][]byte{
var EventMapping = map[EventType][]byte{
EventTypeHorizontalSplit: []byte(`
</section>
<section>`),
@ -44,8 +43,7 @@ var (
</section>
<section>
<section>`),
}
)
}
func NewStateMachine(verticalSplit, horizontalSplit string) *StateMachine {
return &StateMachine{