Skip to content

Commit

Permalink
ci: scan vulns and common errors (#310)
Browse files Browse the repository at this point in the history
* ci: scan vulns and common errors

Signed-off-by: Carlos Alexandro Becker <[email protected]>

* test: use go fuzz

Signed-off-by: Carlos Alexandro Becker <[email protected]>

* fix: using io.WriteString when it makes sense

---------

Signed-off-by: Carlos Alexandro Becker <[email protected]>
  • Loading branch information
caarlos0 authored Jul 9, 2024
1 parent 2878d38 commit 8abcfb0
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 18 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,16 @@ jobs:
- name: Test
run: go test ./...
if: matrix.os != 'windows-latest'

govulncheck:
uses: charmbracelet/meta/.github/workflows/govulncheck.yml@main
with:
go-version: stable

semgrep:
uses: charmbracelet/meta/.github/workflows/semgrep.yml@main

ruleguard:
uses: charmbracelet/meta/.github/workflows/ruleguard.yml@main
with:
go-version: stable
2 changes: 1 addition & 1 deletion ansi/baseelement.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func renderText(w io.Writer, p termenv.Profile, rules StylePrimitive, s string)
out = out.Blink()
}

_, _ = w.Write([]byte(out.String()))
_, _ = io.WriteString(w, out.String())
}

func (e *BaseElement) Render(w io.Writer, ctx RenderContext) error {
Expand Down
3 changes: 1 addition & 2 deletions ansi/blockelement.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ func (e *BlockElement) Finish(w io.Writer, ctx RenderContext) error {
}

if e.Newline {
_, err = mw.Write([]byte("\n"))
if err != nil {
if _, err := io.WriteString(mw, "\n"); err != nil {
return err
}
}
Expand Down
4 changes: 2 additions & 2 deletions ansi/paragraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (e *ParagraphElement) Render(w io.Writer, ctx RenderContext) error {
rules := ctx.options.Styles.Paragraph

if !e.First {
_, _ = w.Write([]byte("\n"))
_, _ = io.WriteString(w, "\n")
}
be := BlockElement{
Block: &bytes.Buffer{},
Expand Down Expand Up @@ -46,7 +46,7 @@ func (e *ParagraphElement) Finish(w io.Writer, ctx RenderContext) error {
if err != nil {
return err
}
_, _ = mw.Write([]byte("\n"))
_, _ = io.WriteString(mw, "\n")
}

renderText(w, ctx.options.ColorProfile, bs.Current().Style.StylePrimitive, rules.Suffix)
Expand Down
5 changes: 3 additions & 2 deletions ansi/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (r *ANSIRenderer) renderNode(w util.BufWriter, source []byte, node ast.Node
writeTo = io.Writer(bs.Current().Block)
}

_, _ = writeTo.Write([]byte(e.Entering))
_, _ = io.WriteString(writeTo, e.Entering)
if e.Renderer != nil {
err := e.Renderer.Render(writeTo, r.context)
if err != nil {
Expand All @@ -128,7 +128,8 @@ func (r *ANSIRenderer) renderNode(w util.BufWriter, source []byte, node ast.Node
return ast.WalkStop, err
}
}
_, _ = bs.Current().Block.Write([]byte(e.Exiting))

_, _ = io.WriteString(bs.Current().Block, e.Exiting)
}

return ast.WalkContinue, nil
Expand Down
12 changes: 12 additions & 0 deletions glamour_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,15 @@ func TestCapitalization(t *testing.T) {
t.Errorf("Rendered output doesn't match!\nExpected: `\n%s`\nGot: `\n%s`\n", td, b)
}
}

func FuzzData(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
func() int {
_, err := RenderBytes(data, DarkStyle)
if err != nil {
return 0
}
return 1
}()
})
}
11 changes: 0 additions & 11 deletions testdata/fuzz/fuzz.go

This file was deleted.

0 comments on commit 8abcfb0

Please sign in to comment.