Skip to content

Commit f215ff7

Browse files
add golangci-lint, run go fix (#22)
apply some fixes, hook up golangci-lint
1 parent 1de564b commit f215ff7

8 files changed

Lines changed: 209 additions & 153 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
golangci:
13+
name: lint
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v5
17+
- uses: actions/setup-go@v6
18+
with:
19+
go-version: 1.24
20+
- name: golangci-lint
21+
uses: golangci/golangci-lint-action@v9
22+
with:
23+
version: v2.6

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ _testmain.go
2222
*.exe
2323
*.test
2424
*.prof
25+
26+
.mise/config.local.toml

.golangci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
version: "2"
2+
3+
linters:
4+
default: "standard"

setup_test.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,19 @@ import (
77
"github.com/stretchr/testify/assert"
88
)
99

10-
func runTestCases(t *testing.T, testCases []testCase) {
10+
func runTestCases(t *testing.T, testCases ...testCase) {
1111
t.Helper()
1212

1313
for _, tc := range testCases {
14-
t.Run(tc.name, func(tt *testing.T) {
15-
runTestCase(tt, tc)
14+
t.Run(tc.name, func(t *testing.T) {
15+
t.Parallel()
16+
result, err := textplain.Convert(tc.body, textplain.DefaultLineLength)
17+
assert.NoError(t, err)
18+
assert.Equal(t, tc.expect, result)
1619
})
1720
}
1821
}
1922

20-
func runTestCase(t *testing.T, tc testCase) {
21-
t.Helper()
22-
23-
result, err := textplain.Convert(tc.body, textplain.DefaultLineLength)
24-
assert.Nil(t, err)
25-
assert.Equal(t, tc.expect, result)
26-
}
27-
2823
const html = `<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><html><head>
2924
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
3025
<style type="text/css">
@@ -53,7 +48,7 @@ const html = `<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "htt
5348

5449
func BenchmarkTree(b *testing.B) {
5550
converter := textplain.NewTreeConverter()
56-
for i := 0; i < b.N; i++ {
51+
for range b.N {
5752
_, _ = converter.Convert(html, textplain.DefaultLineLength)
5853
}
5954
}

textplain.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
package textplain
22

3-
// Defaults
3+
// Defaults.
44
const (
55
DefaultLineLength = 65
66
)
77

8-
98
type Converter interface {
109
Convert(string, int) (string, error)
1110
}
1211

1312
var defaultConverter = NewTreeConverter()
1413

15-
// Convert is a wrapper around the default converter singleton
14+
// Convert is a wrapper around the default converter singleton.
1615
func Convert(document string, lineLength int) (string, error) {
1716
return defaultConverter.Convert(document, lineLength)
1817
}

0 commit comments

Comments
 (0)