Skip to content

Commit

Permalink
fix: fixes for test and lint
Browse files Browse the repository at this point in the history
Test was slow because we were deep-comparing lexers. This is
unnecessary as we can just shallow compare.
  • Loading branch information
alecthomas committed Dec 8, 2023
1 parent 31981be commit 22b7cbf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ linters:
- nosnakecase
- testableexamples
- musttag
- depguard
- goconst

linters-settings:
govet:
Expand Down
9 changes: 5 additions & 4 deletions formatters/html/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"html"
"io"
"sort"
"strconv"
"strings"

"github.com/alecthomas/chroma/v2"
Expand Down Expand Up @@ -243,15 +244,15 @@ func (f *Formatter) writeHTML(w io.Writer, style *chroma.Style, tokens []chroma.
wrapInTable := f.lineNumbers && f.lineNumbersInTable

lines := chroma.SplitTokensIntoLines(tokens)
lineDigits := len(fmt.Sprintf("%d", f.baseLineNumber+len(lines)-1))
lineDigits := len(strconv.Itoa(f.baseLineNumber + len(lines) - 1))
highlightIndex := 0

if wrapInTable {
// List line numbers in its own <td>
fmt.Fprintf(w, "<div%s>\n", f.styleAttr(css, chroma.PreWrapper))
fmt.Fprintf(w, "<table%s><tr>", f.styleAttr(css, chroma.LineTable))
fmt.Fprintf(w, "<td%s>\n", f.styleAttr(css, chroma.LineTableTD))
fmt.Fprintf(w, f.preWrapper.Start(false, f.styleAttr(css, chroma.PreWrapper)))
fmt.Fprintf(w, "%s", f.preWrapper.Start(false, f.styleAttr(css, chroma.PreWrapper)))
for index := range lines {
line := f.baseLineNumber + index
highlight, next := f.shouldHighlight(highlightIndex, line)
Expand All @@ -273,7 +274,7 @@ func (f *Formatter) writeHTML(w io.Writer, style *chroma.Style, tokens []chroma.
fmt.Fprintf(w, "<td%s>\n", f.styleAttr(css, chroma.LineTableTD, "width:100%"))
}

fmt.Fprintf(w, f.preWrapper.Start(true, f.styleAttr(css, chroma.PreWrapper)))
fmt.Fprintf(w, "%s", f.preWrapper.Start(true, f.styleAttr(css, chroma.PreWrapper)))

highlightIndex = 0
for index, tokens := range lines {
Expand Down Expand Up @@ -323,7 +324,7 @@ func (f *Formatter) writeHTML(w io.Writer, style *chroma.Style, tokens []chroma.
fmt.Fprint(w, `</span>`) // End of Line
}
}
fmt.Fprintf(w, f.preWrapper.End(true))
fmt.Fprintf(w, "%s", f.preWrapper.End(true))

if wrapInTable {
fmt.Fprint(w, "</td></tr></table>\n")
Expand Down
4 changes: 2 additions & 2 deletions lexers/lexers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ func TestCompileAllRegexes(t *testing.T) {

func TestGet(t *testing.T) {
t.Run("ByName", func(t *testing.T) {
assert.Equal(t, lexers.Get("xml"), lexers.GlobalLexerRegistry.Get("XML"))
assert.True(t, lexers.Get("xml") == lexers.GlobalLexerRegistry.Get("XML"))
})
t.Run("ByAlias", func(t *testing.T) {
assert.Equal(t, lexers.Get("as"), lexers.GlobalLexerRegistry.Get("Actionscript"))
assert.True(t, lexers.Get("as") == lexers.GlobalLexerRegistry.Get("Actionscript"))
})
t.Run("ViaFilename", func(t *testing.T) {
expected := lexers.Get("XML")
Expand Down
25 changes: 16 additions & 9 deletions renovate.json5
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
{
$schema: "https://docs.renovatebot.com/renovate-schema.json",
extends: [
"config:recommended",
":semanticCommits",
":semanticCommitTypeAll(chore)",
":semanticCommitScope(deps)",
"group:allNonMajor",
"schedule:earlyMondays", // Run once a week.
],
$schema: "https://docs.renovatebot.com/renovate-schema.json",
extends: [
"config:recommended",
":semanticCommits",
":semanticCommitTypeAll(chore)",
":semanticCommitScope(deps)",
"group:allNonMajor",
"schedule:earlyMondays", // Run once a week.
],
packageRules: [
{
matchPackageNames: ["golangci-lint"],
matchManagers: ["hermit"],
enabled: false,
},
],
}

0 comments on commit 22b7cbf

Please sign in to comment.