1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-07-15 01:14:21 +02:00

Add golangci-lint and fix all lint issues.

This commit is contained in:
Alec Thomas
2018-12-31 22:44:27 +11:00
parent e27f19c12f
commit da5ac60d8c
18 changed files with 118 additions and 45 deletions

View File

@ -113,7 +113,10 @@ func (f *Formatter) writeHTML(w io.Writer, style *chroma.Style, tokens []chroma.
fmt.Fprint(w, "<html>\n")
if f.Classes {
fmt.Fprint(w, "<style type=\"text/css\">\n")
f.WriteCSS(w, style)
err = f.WriteCSS(w, style)
if err != nil {
return err
}
fmt.Fprintf(w, "body { %s; }\n", css[chroma.Background])
fmt.Fprint(w, "</style>")
}
@ -243,7 +246,7 @@ func (f *Formatter) styleAttr(styles map[chroma.TokenType]string, tt chroma.Toke
if cls == "" {
return ""
}
return string(fmt.Sprintf(` class="%s"`, cls))
return fmt.Sprintf(` class="%s"`, cls)
}
if _, ok := styles[tt]; !ok {
tt = tt.SubCategory()

View File

@ -8,6 +8,7 @@ import (
"testing"
"github.com/alecthomas/assert"
"github.com/alecthomas/chroma"
"github.com/alecthomas/chroma/lexers"
"github.com/alecthomas/chroma/styles"
@ -89,7 +90,8 @@ func TestClassPrefix(t *testing.T) {
}
var styleBuf bytes.Buffer
withPrefix.WriteCSS(&styleBuf, styles.Fallback)
err := withPrefix.WriteCSS(&styleBuf, styles.Fallback)
assert.NoError(t, err)
if !strings.Contains(styleBuf.String(), ".some-prefix-chroma ") {
t.Error("Stylesheets should have a class prefix")
}