Skip to content

Commit 609775c

Browse files
committed
style: fix lint errors
1 parent 9e3aa0e commit 609775c

File tree

8 files changed

+34
-29
lines changed

8 files changed

+34
-29
lines changed

cmd/termsvg/export/export.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package export
33
import (
44
"bytes"
55
"os"
6+
"path/filepath"
67

78
"github.com/mrmarble/termsvg/internal/svg"
89
"github.com/mrmarble/termsvg/pkg/asciicast"
@@ -37,7 +38,7 @@ func (cmd *Cmd) Run() error {
3738
}
3839

3940
func export(input, output string, mini bool, bgColor, textColor string, noWindow bool) error {
40-
inputFile, err := os.ReadFile(input)
41+
inputFile, err := os.ReadFile(filepath.Clean(input))
4142
if err != nil {
4243
return err
4344
}
@@ -47,31 +48,31 @@ func export(input, output string, mini bool, bgColor, textColor string, noWindow
4748
return err
4849
}
4950

50-
outputFile, err := os.Create(output)
51-
if err != nil {
52-
return err
53-
}
54-
defer outputFile.Close()
51+
out := new(bytes.Buffer)
52+
var data []byte
5553

54+
svg.Export(*cast, out, bgColor, textColor, noWindow)
5655
if mini {
57-
out := new(bytes.Buffer)
58-
svg.Export(*cast, out, bgColor, textColor, noWindow)
59-
6056
m := minify.New()
6157
m.AddFunc("image/svg+xml", msvg.Minify)
62-
6358
b, err := m.Bytes("image/svg+xml", out.Bytes())
6459
if err != nil {
6560
return err
6661
}
67-
68-
_, err = outputFile.Write(b)
69-
if err != nil {
70-
return err
71-
}
62+
data = b
7263
} else {
73-
svg.Export(*cast, outputFile, bgColor, textColor, noWindow)
64+
data = out.Bytes()
65+
}
66+
outputFile, err := os.Create(output)
67+
if err != nil {
68+
return err
69+
}
70+
_, err = outputFile.Write(data)
71+
if err != nil {
72+
//nolint:gosec,errcheck
73+
outputFile.Close()
74+
return err
7475
}
7576

76-
return nil
77+
return outputFile.Close()
7778
}

cmd/termsvg/play/play.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package play
33
import (
44
"fmt"
55
"os"
6+
"path/filepath"
67
"time"
78

89
"github.com/mrmarble/termsvg/pkg/asciicast"
@@ -19,7 +20,7 @@ func (cmd *Cmd) Run() error {
1920
}
2021

2122
func play(path string, idleCap, speed float64) error {
22-
file, err := os.ReadFile(path)
23+
file, err := os.ReadFile(filepath.Clean(path))
2324
if err != nil {
2425
return err
2526
}

cmd/termsvg/rec/rec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func rec(file, command string, skipFirstLine bool) error {
6666
return err
6767
}
6868

69-
err = os.WriteFile(file, js, os.ModePerm)
69+
err = os.WriteFile(file, js, 0o600)
7070
if err != nil {
7171
return err
7272
}

internal/svg/svg.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ func createCanvas(svg *svg.SVG, cast asciicast.Cast, noWindow bool) {
6565
} else {
6666
canvas.Rect(0, 0, canvas.paddedWidth(), canvas.paddedHeight(), "fill:"+backgroundColorOverride)
6767
}
68-
//nolint:gomnd
6968
canvas.Group(fmt.Sprintf(`transform="translate(%d,%d)"`, padding, int(padding*1.5)))
7069
}
7170
canvas.addStyles()
@@ -152,7 +151,7 @@ func (c *Canvas) addStyles() {
152151
colors = append(colors, css.Block{Selector: fmt.Sprintf(".%s", class), Rules: css.Rules{"fill": color}})
153152
}
154153

155-
styles := generateKeyframes(c.Cast, int32(c.paddedWidth()))
154+
styles := generateKeyframes(c.Cast, c.paddedWidth())
156155
// If custom colors have been provided, use them instead
157156
if foregroundColorOverride != "" {
158157
styles += fmt.Sprintf(".a{fill:%s}", foregroundColorOverride)
@@ -234,17 +233,17 @@ func (c *Canvas) applyBG(bg vt10x.Color) string {
234233
return ""
235234
}
236235

237-
func generateKeyframes(cast asciicast.Cast, width int32) string {
236+
func generateKeyframes(cast asciicast.Cast, width int) string {
238237
css := "@keyframes k {"
239238
for i, frame := range cast.Events {
240-
css += generateKeyframe(float32(frame.Time*100/cast.Header.Duration), width*int32(i))
239+
css += generateKeyframe(float32(frame.Time*100/cast.Header.Duration), width*i)
241240
}
242241

243242
css += "}"
244243

245244
return css
246245
}
247246

248-
func generateKeyframe(percent float32, translate int32) string {
247+
func generateKeyframe(percent float32, translate int) string {
249248
return fmt.Sprintf("%.3f%%{transform:translateX(-%dpx)}", percent, translate)
250249
}

internal/testutils/testutils.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ func GoldenData(t Helper, identifier string) []byte {
1717

1818
goldenPath := "testdata/" + identifier + ".golden"
1919

20+
//nolint:gosec
2021
f, err := os.Open(goldenPath)
2122
if err != nil {
2223
t.Fatalf("Error opening file %s: %s", goldenPath, err)
2324
}
25+
26+
//nolint:errcheck
2427
defer f.Close()
2528

2629
data, err := io.ReadAll(f)

internal/uniqueid/unique_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ func diff(t *testing.T, x interface{}, y interface{}) {
4747

4848
diff := cmp.Diff(x, y)
4949
if diff != "" {
50-
t.Fatalf(diff)
50+
t.Fatal(diff)
5151
}
5252
}

pkg/asciicast/event_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestJSONMarshal(t *testing.T) {
4040

4141
diff := cmp.Diff(string(output), tc.output)
4242
if diff != "" {
43-
t.Fatalf(diff)
43+
t.Fatal(diff)
4444
}
4545
})
4646
}
@@ -76,7 +76,7 @@ func TestJSONUnmarshal(t *testing.T) {
7676
}
7777
diff := cmp.Diff(output, tc.output)
7878
if diff != "" {
79-
t.Fatalf(diff)
79+
t.Fatal(diff)
8080
}
8181
})
8282
}

pkg/color/color.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ func GetColor(c vt10x.Color) string {
1414
case c >= 1<<24:
1515
return colors[int(vt10x.LightGrey)]
1616
case c >= 1<<8:
17-
rgb := intToRGB(int(c))
17+
rgb := intToRGB(uint32(c))
1818
return fmt.Sprintf("#%02x%02x%02x", rgb.R, rgb.B, rgb.G)
1919
default:
2020
return colors[int(c)]
2121
}
2222
}
2323

24-
func intToRGB(c int) color.RGBA {
24+
func intToRGB(c uint32) color.RGBA {
25+
//nolint:gosec
2526
return color.RGBA{
2627
R: uint8(c >> 16),
2728
G: uint8(c >> 8),

0 commit comments

Comments
 (0)