🛠 golangci-lint
This commit is contained in:
parent
8d74dc24e5
commit
7aae44048a
9 changed files with 144 additions and 85 deletions
39
.golangci.yaml
Normal file
39
.golangci.yaml
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
linters:
|
||||
enable:
|
||||
- errcheck
|
||||
- gosimple
|
||||
- govet
|
||||
- ineffassign
|
||||
- staticcheck
|
||||
- unused
|
||||
- copyloopvar
|
||||
- dupl
|
||||
- err113
|
||||
- errname
|
||||
- exptostd
|
||||
- fatcontext
|
||||
- funlen
|
||||
- gocognit
|
||||
- goconst
|
||||
- gocritic
|
||||
- gocyclo
|
||||
- godot
|
||||
- godox
|
||||
- gosec
|
||||
- perfsprint
|
||||
- testifylint
|
||||
|
||||
linters-settings:
|
||||
testifylint:
|
||||
enable-all: true
|
||||
disable:
|
||||
- require-error
|
||||
gocognit:
|
||||
min-complexity: 16
|
||||
gocyclo:
|
||||
min-complexity: 15
|
||||
gocritic:
|
||||
enable-all: true
|
||||
settings:
|
||||
hugeParam:
|
||||
sizeThreshold: 255
|
||||
26
Taskfile.yml
26
Taskfile.yml
|
|
@ -14,7 +14,7 @@ tasks:
|
|||
desc: fmt, vet, and build
|
||||
deps:
|
||||
- fmt
|
||||
- analyze
|
||||
- lint
|
||||
- build-all
|
||||
|
||||
fmt:
|
||||
|
|
@ -24,30 +24,12 @@ tasks:
|
|||
cmds:
|
||||
- go fmt ./...
|
||||
|
||||
vet:
|
||||
desc: Vet go code
|
||||
lint:
|
||||
desc: Statically analyze code
|
||||
sources:
|
||||
- '**/*.go'
|
||||
cmds:
|
||||
- go vet ./...
|
||||
critic:
|
||||
desc: Critique go code
|
||||
sources:
|
||||
- '**/*.go'
|
||||
cmds:
|
||||
- gocritic check ./...
|
||||
staticcheck:
|
||||
desc: Static check go code
|
||||
sources:
|
||||
- '**/*.go'
|
||||
cmds:
|
||||
- staticcheck ./...
|
||||
analyze:
|
||||
desc: Do static analysis
|
||||
deps:
|
||||
- vet
|
||||
- critic
|
||||
- staticcheck
|
||||
- golangci-lint run
|
||||
|
||||
cmd-build:
|
||||
internal: true
|
||||
|
|
|
|||
|
|
@ -42,16 +42,20 @@ func Chill(baseCtx context.Context) context.Context {
|
|||
return ret(ErrChilledOut)
|
||||
}
|
||||
|
||||
go func() {
|
||||
for current >= MaxTemp && err == nil {
|
||||
time.Sleep(Sleep)
|
||||
current, err = getCurrentTemp()
|
||||
}
|
||||
if err == nil {
|
||||
err = ErrChilledOut
|
||||
}
|
||||
cancel(err)
|
||||
}()
|
||||
go runChill(current, cancel)
|
||||
|
||||
return ctx
|
||||
}
|
||||
|
||||
func runChill(current int, cancel context.CancelCauseFunc) {
|
||||
var err error
|
||||
for current >= MaxTemp && err == nil {
|
||||
time.Sleep(Sleep)
|
||||
current, err = getCurrentTemp()
|
||||
}
|
||||
if err == nil {
|
||||
err = ErrChilledOut
|
||||
}
|
||||
cancel(err)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,17 +20,17 @@ type errMsg error
|
|||
|
||||
type textMessage string
|
||||
|
||||
func newModel(text string) model {
|
||||
func newModel(text string) *model {
|
||||
s := spinner.New()
|
||||
s.Spinner = spinner.Dot
|
||||
return model{spinner: s, text: text}
|
||||
return &model{spinner: s, text: text}
|
||||
}
|
||||
|
||||
func (m model) Init() tea.Cmd {
|
||||
func (m *model) Init() tea.Cmd {
|
||||
return m.spinner.Tick
|
||||
}
|
||||
|
||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case errMsg:
|
||||
m.err = msg
|
||||
|
|
@ -47,7 +47,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
}
|
||||
}
|
||||
|
||||
func (m model) View() string {
|
||||
func (m *model) View() string {
|
||||
if m.err != nil {
|
||||
return m.err.Error()
|
||||
}
|
||||
|
|
|
|||
20
cmd/test/main.go
Normal file
20
cmd/test/main.go
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
e "codeberg.org/danjones000/utils/cli/err"
|
||||
cli "codeberg.org/danjones000/utils/internal/cli/convids"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
flags, err := cli.ParseFlags(os.Args[0], os.Args[1:])
|
||||
e.HandleErr(err)
|
||||
if *cli.Help {
|
||||
flags.Usage()
|
||||
}
|
||||
|
||||
fmt.Println("Help", *cli.Help)
|
||||
fmt.Println("Loop", *cli.Loop)
|
||||
fmt.Println("DryRun", *cli.DryRun)
|
||||
}
|
||||
|
|
@ -84,6 +84,35 @@ func processFile(input processInput) (processed bool, processError, cbError erro
|
|||
return
|
||||
}
|
||||
|
||||
func processSource(allFiles ezcache.Cache[string, []os.DirEntry], d *Data, s *Show, source string, stopOnError bool, cb ShowWalker) (count int, err error) {
|
||||
files, filesErr := allFiles.Get(source)
|
||||
if filesErr != nil {
|
||||
return 0, filesErr
|
||||
}
|
||||
for _, file := range files {
|
||||
pIn := processInput{file, source, s, d.Config.extRe, d.Config.Skip, cb}
|
||||
processed, processErr, cbErr := processFile(pIn)
|
||||
if processErr != nil {
|
||||
return 0, processErr
|
||||
}
|
||||
if cbErr != nil && stopOnError {
|
||||
return 0, cbErr
|
||||
}
|
||||
|
||||
if errors.Is(processErr, ErrSkipped) || (!processed && processErr == nil && cbErr == nil) {
|
||||
continue
|
||||
}
|
||||
if cbErr == nil && processed {
|
||||
count++
|
||||
}
|
||||
if cbErr != nil {
|
||||
err = cbErr
|
||||
}
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func WalkFiles(d *Data, stopOnError bool, gp GroupPrinter, cb ShowWalker) (err error) {
|
||||
err = ensureExtRe(d.Config)
|
||||
if err != nil {
|
||||
|
|
@ -98,9 +127,6 @@ func WalkFiles(d *Data, stopOnError bool, gp GroupPrinter, cb ShowWalker) (err e
|
|||
return err
|
||||
}
|
||||
|
||||
var files []os.DirEntry
|
||||
var filesErr error
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
@ -108,35 +134,13 @@ func WalkFiles(d *Data, stopOnError bool, gp GroupPrinter, cb ShowWalker) (err e
|
|||
if len(s.Sources) == 0 {
|
||||
s.Sources = []string{d.Config.Source}
|
||||
}
|
||||
showstart:
|
||||
for _, source := range s.Sources {
|
||||
files, filesErr = allFiles.Get(source)
|
||||
if filesErr != nil {
|
||||
return filesErr
|
||||
}
|
||||
for _, file := range files {
|
||||
pIn := processInput{file, source, s, d.Config.extRe, d.Config.Skip, cb}
|
||||
processed, processErr, cbErr := processFile(pIn)
|
||||
if !processed && processErr == nil && cbErr == nil {
|
||||
continue
|
||||
}
|
||||
if errors.Is(processErr, ErrSkipped) {
|
||||
continue
|
||||
}
|
||||
if processErr != nil {
|
||||
return processErr
|
||||
}
|
||||
if cbErr != nil && stopOnError {
|
||||
return cbErr
|
||||
}
|
||||
if cbErr == nil && processed {
|
||||
count++
|
||||
}
|
||||
if cbErr != nil {
|
||||
err = cbErr
|
||||
}
|
||||
break showstart
|
||||
var c int
|
||||
c, err = processSource(allFiles, d, s, source, stopOnError, cb)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
count += c
|
||||
}
|
||||
}
|
||||
if err == nil && count < 1 {
|
||||
|
|
@ -157,8 +161,9 @@ func GetShow(ctx context.Context) ShowWalker {
|
|||
return GetShowWithIO(ctx, os.Stdin, os.Stdout, os.Stderr)
|
||||
}
|
||||
|
||||
func GetShowWithIO(ctx context.Context, stdin io.Reader, stdout io.Writer, stderr io.Writer) ShowWalker {
|
||||
func GetShowWithIO(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer) ShowWalker {
|
||||
return func(s *Show, path string) error {
|
||||
//nolint:gosec // I don't care if this is using user input
|
||||
cmd := exec.CommandContext(ctx, "get-shows", s.Folder, path)
|
||||
cmd.Stdin = stdin
|
||||
cmd.Stdout = stdout
|
||||
|
|
|
|||
|
|
@ -62,21 +62,28 @@ func (d *Data) AllShows(outputGroup GroupPrinter) iter.Seq[*Show] {
|
|||
return
|
||||
}
|
||||
for _, groupName := range d.Config.Groups {
|
||||
group := (*d.Shows)[groupName]
|
||||
if group == nil || len(*group) < 1 {
|
||||
continue
|
||||
}
|
||||
if outputGroup != nil {
|
||||
outputGroup(groupName, *group)
|
||||
}
|
||||
for sh := range group.All() {
|
||||
if sh == nil {
|
||||
continue
|
||||
}
|
||||
if !yield(sh) {
|
||||
return
|
||||
}
|
||||
if !d.yieldGroup(yield, outputGroup, groupName) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Data) yieldGroup(yield func(*Show) bool, outputGroup GroupPrinter, groupName string) bool {
|
||||
group := (*d.Shows)[groupName]
|
||||
if group == nil || len(*group) < 1 {
|
||||
return true
|
||||
}
|
||||
if outputGroup != nil {
|
||||
outputGroup(groupName, *group)
|
||||
}
|
||||
for sh := range group.All() {
|
||||
if sh == nil {
|
||||
continue
|
||||
}
|
||||
if !yield(sh) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,10 @@ func ParseFlags(name string, args []string) (*pflag.FlagSet, error) {
|
|||
}
|
||||
|
||||
if *DryRun {
|
||||
flags.Set("loop", "false")
|
||||
err := flags.Set("loop", "false")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return flags, nil
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package convids
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"codeberg.org/danjones000/utils/chill"
|
||||
|
|
@ -18,7 +17,7 @@ func GetWalker(ctx context.Context, dryRun bool, in io.Reader, out, errOut io.Wr
|
|||
gs := conutils.GetShowWithIO(ctx, in, out, errOut)
|
||||
return func(s *conutils.Show, path string) error {
|
||||
ct := chill.Chill(ctx)
|
||||
msg := fmt.Sprintf("Waiting for CPU to cool, for %s", path)
|
||||
msg := "Waiting for CPU to cool, for " + path
|
||||
sp := spin.Spin(ct, msg)
|
||||
err := sp.Wait()
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue