fix: align lint config and output handling

This commit is contained in:
Peter Steinberger 2026-01-02 14:07:40 +01:00
parent fe085db706
commit e88584e761
7 changed files with 59 additions and 39 deletions

View File

@ -14,29 +14,27 @@ linters:
- revive
- gocritic
- misspell
settings:
revive:
rules:
- name: blank-imports
- name: empty-lines
- name: error-strings
- name: early-return
- name: increment-decrement
- name: range
- name: receiver-naming
- name: var-declaration
gocritic:
enabled-tags:
- performance
- style
- diagnostic
formatters:
enable:
- gofmt
linters-settings:
revive:
rules:
- name: blank-imports
- name: empty-lines
- name: error-strings
- name: early-return
- name: increment-decrement
- name: range
- name: receiver-naming
- name: var-declaration
gocritic:
enabled-tags:
- performance
- style
- diagnostic
issues:
exclude-use-default: false
max-issues-per-linter: 0
max-same-issues: 0

View File

@ -136,7 +136,7 @@ func run(args []string, stdin io.Reader, stdout, stderr io.Writer) int {
base := strings.TrimSuffix(filepath.Base(input), ext)
output = filepath.Join(filepath.Dir(input), base+"."+format)
}
} else {
} else if output != "-" {
ext := strings.ToLower(filepath.Ext(output))
switch ext {
case ".png":
@ -188,7 +188,7 @@ func run(args []string, stdin io.Reader, stdout, stderr io.Writer) int {
return dieUsage(stderr, ctx, "unknown style")
}
img, err := render.Spectrogram(spec, render.Options{
img, err := render.Spectrogram(&spec, render.Options{
Width: cfg.Width,
Height: cfg.Height,
MinFreq: cfg.MinFreq,

View File

@ -283,6 +283,32 @@ func TestRunOutputStdout(t *testing.T) {
}
}
func TestRunOutputStdoutDefaultFormat(t *testing.T) {
tmp := t.TempDir()
cwd, err := os.Getwd()
if err != nil {
t.Fatalf("Getwd: %v", err)
}
if err := os.Chdir(tmp); err != nil {
t.Fatalf("Chdir: %v", err)
}
t.Cleanup(func() { _ = os.Chdir(cwd) })
wav := makeWAV([]int16{0, 1000, -1000, 0}, 44100, 1)
stdout := &bytes.Buffer{}
stderr := &bytes.Buffer{}
exit := run([]string{"--output", "-", "-"}, bytes.NewReader(wav), stdout, stderr)
if exit != 0 {
t.Fatalf("exit %d stderr=%s", exit, stderr.String())
}
if _, _, err := image.Decode(bytes.NewReader(stdout.Bytes())); err != nil {
t.Fatalf("decode stdout image: %v", err)
}
if _, err := os.Stat(filepath.Join(tmp, "-.jpg")); err == nil {
t.Fatalf("unexpected file created")
}
}
func TestRunOutputAuto(t *testing.T) {
dir := t.TempDir()
input := filepath.Join(dir, "input.wav")
@ -514,7 +540,7 @@ func flatImage(img image.Image) bool {
return maxLum-minLum < 1000
}
func makeWAV(samples []int16, sampleRate int, channels int) []byte {
func makeWAV(samples []int16, sampleRate, channels int) []byte {
if channels < 1 {
channels = 1
}

View File

@ -5,7 +5,7 @@ import (
"encoding/binary"
)
func makeWAV(samples []int16, sampleRate int, channels int) []byte {
func makeWAV(samples []int16, sampleRate, channels int) []byte {
if channels < 1 {
channels = 1
}

View File

@ -51,16 +51,6 @@ func PaletteByName(name string) (Palette, error) {
}), nil
case "gray", "grey":
return gradient([]stop{{0, rgb(0, 0, 0)}, {1, rgb(255, 255, 255)}}), nil
case "clawd":
// 🦞 Lobster from the deep! Ocean depths to coral brightness
return gradient([]stop{
{0.0, rgb(2, 4, 15)}, // Abyss black-blue
{0.2, rgb(11, 38, 74)}, // Deep ocean navy
{0.4, rgb(18, 97, 117)}, // Ocean teal
{0.6, rgb(193, 98, 92)}, // Coral/salmon
{0.8, rgb(205, 55, 40)}, // Lobster red! 🦞
{1.0, rgb(255, 230, 210)}, // Foam/shell highlight
}), nil
default:
return nil, errors.New("unknown palette")
}

View File

@ -23,7 +23,10 @@ type Options struct {
}
// Spectrogram renders a spectrogram into an RGBA image.
func Spectrogram(spec dsp.Spectrogram, opts Options) (*image.RGBA, error) {
func Spectrogram(spec *dsp.Spectrogram, opts Options) (*image.RGBA, error) {
if spec == nil {
return nil, fmt.Errorf("spectrogram required")
}
if opts.Width <= 0 || opts.Height <= 0 {
return nil, fmt.Errorf("invalid output size")
}

View File

@ -28,7 +28,7 @@ func TestRenderSpectrogram(t *testing.T) {
Max: -1,
BinHz: 100,
}
img, err := Spectrogram(spec, Options{
img, err := Spectrogram(&spec, Options{
Width: 4,
Height: 4,
Palette: func(t float64) color.RGBA { return color.RGBA{R: uint8(255 * t), A: 255} },
@ -47,6 +47,9 @@ func TestRenderSpectrogram(t *testing.T) {
}
func TestRenderSpectrogramErrors(t *testing.T) {
if _, err := Spectrogram(nil, Options{Width: 1, Height: 1, Palette: func(float64) color.RGBA { return color.RGBA{} }}); err == nil {
t.Fatalf("expected spec error")
}
spec := dsp.Spectrogram{
Frames: 1,
Bins: 1,
@ -55,10 +58,10 @@ func TestRenderSpectrogramErrors(t *testing.T) {
Max: 1,
BinHz: 100,
}
if _, err := Spectrogram(spec, Options{Width: 0, Height: 1, Palette: func(float64) color.RGBA { return color.RGBA{} }}); err == nil {
if _, err := Spectrogram(&spec, Options{Width: 0, Height: 1, Palette: func(float64) color.RGBA { return color.RGBA{} }}); err == nil {
t.Fatalf("expected size error")
}
if _, err := Spectrogram(spec, Options{Width: 1, Height: 1}); err == nil {
if _, err := Spectrogram(&spec, Options{Width: 1, Height: 1}); err == nil {
t.Fatalf("expected palette error")
}
}
@ -72,7 +75,7 @@ func TestRenderSpectrogramClampAndRange(t *testing.T) {
Max: 0,
BinHz: 100,
}
img, err := Spectrogram(spec, Options{
img, err := Spectrogram(&spec, Options{
Width: 3,
Height: 2,
MinFreq: 50,
@ -119,7 +122,7 @@ func TestRenderSpectrogramSinglePixel(t *testing.T) {
Max: -10,
BinHz: 100,
}
img, err := Spectrogram(spec, Options{
img, err := Spectrogram(&spec, Options{
Width: 1,
Height: 1,
Palette: func(_ float64) color.RGBA { return color.RGBA{G: 200, A: 255} },
@ -141,7 +144,7 @@ func TestRenderSpectrogramRangeReset(t *testing.T) {
Max: -1,
BinHz: 100,
}
_, err := Spectrogram(spec, Options{
_, err := Spectrogram(&spec, Options{
Width: 2,
Height: 2,
MinFreq: 1000,