Skip to content

Commit

Permalink
Lint fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengarrett committed Jan 9, 2024
1 parent 151195a commit 745d7d7
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 19 deletions.
37 changes: 37 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# gci write ./..
# gofumpt -w .
# golangci-lint run

linters:
enable-all: true
disable:
# deprecated
- ifshort
- interfacer
- structcheck
- nosnakecase
- deadcode
- exhaustivestruct
- golint
- scopelint
- maligned
- varcheck
# opinionated
- depguard
- nlreturn
- paralleltest
- varnamelen
- wrapcheck
- wsl

linters-settings:
cyclop:
max-complexity: 15

issues:
exclude-rules:
# all test files
- path: '(.+)_test\.go'
linters:
- exhaustruct
- lll
3 changes: 1 addition & 2 deletions bbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,8 @@ func (b BBS) Remove(dst *bytes.Buffer, src []byte) error {
return remove(dst, src, WWIVHashRe)
case WWIVHeart:
return remove(dst, src, WWIVHeartRe)
default:
return ErrNone
}
return ErrNone
}

func remove(dst *bytes.Buffer, src []byte, expr string) error {
Expand Down
9 changes: 6 additions & 3 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ func Example() {

s, b, err := bbs.Fields(file)
if err != nil {
log.Fatal(err)
log.Print(err)
return
}
fmt.Printf("Found %d %s color controls.\n\n", len(s), b)

// reopen the file
file, err = static.Open("static/examples/hello.pcb")
if err != nil {
log.Fatal(err)
log.Print(err)
return
}
defer file.Close()

Expand All @@ -42,7 +44,8 @@ func Example() {
// create the HTML equivalent of BBS color codes
var buf bytes.Buffer
if _, err := bbs.HTML(&buf, reader); err != nil {
log.Fatal(err)
log.Print(err)
return
}
fmt.Print(buf.String())

Expand Down
4 changes: 2 additions & 2 deletions examplebbs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ func ExampleBBS_CSS() {
//
// /* PCBoard and WildCat! BBS colours */
//
//i.PF0 {
// i.PF0 {
// color: var(--black);
//}
// }
}

func ExampleBBS_HTML() {
Expand Down
27 changes: 18 additions & 9 deletions internal/split/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import (
"strings"
)

var (
ErrBuff = errors.New("bytes buffer cannot be nil")
)
var ErrBuff = errors.New("bytes buffer cannot be nil")

// colorInt template data for integer based color codes.
type colorInt struct {
Expand Down Expand Up @@ -75,7 +73,11 @@ func VBarsHTML(dst *bytes.Buffer, src []byte) error {
return err
}

d := colorInt{}
d := colorInt{
Foreground: -1,
Background: -1,
Content: "",
}
bars := VBars(src)
if len(bars) == 0 {
_, err := dst.Write(src)
Expand All @@ -102,20 +104,22 @@ func VBarsHTML(dst *bytes.Buffer, src []byte) error {
}

func barBackground(n int) bool {
if n < 16 {
const first, last = 16, 23
if n < first {
return false
}
if n > 23 {
if n > last {
return false
}
return true
}

func barForeground(n int) bool {
if n < 0 {
const first, last = 0, 15
if n < first {
return false
}
if n > 15 {
if n > last {
return false
}
return true
Expand Down Expand Up @@ -162,6 +166,7 @@ func CelerityHTML(dst *bytes.Buffer, src []byte) error {
d := colorStr{
Foreground: "w",
Background: "k",
Content: "",
}

bars := Celerity(src)
Expand Down Expand Up @@ -224,7 +229,11 @@ func PCBoardHTML(dst *bytes.Buffer, src []byte) error {
return err
}

d := colorStr{}
d := colorStr{
Foreground: "",
Background: "",
Content: "",
}
xcodes := PCBoard(src)
if len(xcodes) == 0 {
_, err := dst.Write(src)
Expand Down
7 changes: 4 additions & 3 deletions internal/split/split_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package split_test
import (
"bytes"
"fmt"
"os"
"testing"

"github.com/bengarrett/bbs/internal/split"
Expand All @@ -27,7 +28,7 @@ func Test_VBars(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := len(split.VBars([]byte(tt.args.s))); got != tt.want {
fmt.Println(split.VBars([]byte(tt.args.s)))
fmt.Fprintln(os.Stderr, split.VBars([]byte(tt.args.s)))
t.Errorf("VBars() = %v, want %v", got, tt.want)
}
})
Expand All @@ -54,7 +55,7 @@ func Test_Celerity(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := len(split.Celerity([]byte(tt.args.s))); got != tt.want {
fmt.Println(split.Celerity([]byte(tt.args.s)))
fmt.Fprintln(os.Stderr, split.Celerity([]byte(tt.args.s)))
t.Errorf("Celerity() = %v, want %v", got, tt.want)
}
})
Expand All @@ -80,7 +81,7 @@ func Test_PCBoard(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := len(split.PCBoard([]byte(tt.args.s))); got != tt.want {
fmt.Println(split.PCBoard([]byte(tt.args.s)))
fmt.Fprintln(os.Stderr, split.PCBoard([]byte(tt.args.s)))
t.Errorf("PCBoard() = %v, want %v", got, tt.want)
}
})
Expand Down

0 comments on commit 745d7d7

Please sign in to comment.