Skip to content

Commit

Permalink
Apply gofumpt on codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Oct 29, 2023
1 parent 6abc780 commit 80dea09
Show file tree
Hide file tree
Showing 10 changed files with 2,752 additions and 2,757 deletions.
9 changes: 4 additions & 5 deletions encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,19 +277,16 @@ func (d *dataEncoder) optimiseDataModes() error {
}

coalescedLength, err := d.encodedLength(mode, numChars+nextNumChars)

if err != nil {
return err
}

seperateLength1, err := d.encodedLength(mode, numChars)

if err != nil {
return err
}

seperateLength2, err := d.encodedLength(nextMode, nextNumChars)

if err != nil {
return err
}
Expand All @@ -302,8 +299,10 @@ func (d *dataEncoder) optimiseDataModes() error {
}
}

optimised := segment{dataMode: mode,
data: make([]byte, 0, numChars)}
optimised := segment{
dataMode: mode,
data: make([]byte, 0, numChars),
}

for k := i; k < j; k++ {
optimised.data = append(optimised.data, d.actual[k].data...)
Expand Down
20 changes: 8 additions & 12 deletions qrcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func Encode(content string, level RecoveryLevel, size int) ([]byte, error) {
var q *QRCode

q, err := New(content, level)

if err != nil {
return nil, err
}
Expand All @@ -91,7 +90,6 @@ func WriteFile(content string, level RecoveryLevel, size int, filename string) e
var q *QRCode

q, err := New(content, level)

if err != nil {
return err
}
Expand All @@ -106,8 +104,8 @@ func WriteFile(content string, level RecoveryLevel, size int, filename string) e
// a larger image is silently written. Negative values for size cause a variable
// sized image to be written: See the documentation for Image().
func WriteColorFile(content string, level RecoveryLevel, size int, background,
foreground color.Color, filename string) error {

foreground color.Color, filename string,
) error {
var q *QRCode

q, err := New(content, level)
Expand Down Expand Up @@ -153,8 +151,10 @@ type QRCode struct {
//
// An error occurs if the content is too long.
func New(content string, level RecoveryLevel) (*QRCode, error) {
encoders := []dataEncoderType{dataEncoderType1To9, dataEncoderType10To26,
dataEncoderType27To40}
encoders := []dataEncoderType{
dataEncoderType1To9, dataEncoderType10To26,
dataEncoderType27To40,
}

var encoder *dataEncoder
var encoded *bitset.Bitset
Expand Down Expand Up @@ -221,7 +221,6 @@ func NewWithForcedVersion(content string, version int, level RecoveryLevel) (*QR

var encoded *bitset.Bitset
encoded, err := encoder.encode([]byte(content))

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -340,7 +339,6 @@ func (q *QRCode) PNG(size int) ([]byte, error) {

var b bytes.Buffer
err := encoder.Encode(&b, img)

if err != nil {
return nil, err
}
Expand All @@ -357,7 +355,6 @@ func (q *QRCode) Write(size int, out io.Writer) error {
var png []byte

png, err := q.PNG(size)

if err != nil {
return err
}
Expand All @@ -374,12 +371,11 @@ func (q *QRCode) WriteFile(size int, filename string) error {
var png []byte

png, err := q.PNG(size)

if err != nil {
return err
}

return os.WriteFile(filename, png, os.FileMode(0644))
return os.WriteFile(filename, png, os.FileMode(0o644))
}

// encode completes the steps required to encode the QR Code. These include
Expand Down Expand Up @@ -414,7 +410,7 @@ func (q *QRCode) encode() {

p := s.penaltyScore()

//log.Printf("mask=%d p=%3d p1=%3d p2=%3d p3=%3d p4=%d\n", mask, p, s.penalty1(), s.penalty2(), s.penalty3(), s.penalty4())
// log.Printf("mask=%d p=%3d p1=%3d p2=%3d p3=%3d p4=%d\n", mask, p, s.penalty1(), s.penalty2(), s.penalty3(), s.penalty4())

if q.symbol == nil || p < penalty {
q.symbol = s
Expand Down
2 changes: 0 additions & 2 deletions qrcode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func TestQRCodeMaxCapacity(t *testing.T) {

for _, test := range tests {
_, err := New(strings.Repeat(test.string, test.numRepetitions), Low)

if err != nil {
t.Errorf("%d x '%s' got %s expected success", test.numRepetitions,
test.string, err.Error())
Expand Down Expand Up @@ -145,7 +144,6 @@ func TestQRCodeVersionCapacity(t *testing.T) {
func TestQRCodeISOAnnexIExample(t *testing.T) {
var q *QRCode
q, err := New("01234567", Medium)

if err != nil {
t.Fatalf("Error producing ISO Annex I Example: %s, expected success",
err.Error())
Expand Down
6 changes: 4 additions & 2 deletions reedsolomon/gf2_8.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ var (
/* 220 - 229 */ 172, 69, 138, 9, 18, 36, 72, 144, 61, 122,
/* 230 - 239 */ 244, 245, 247, 243, 251, 235, 203, 139, 11, 22,
/* 240 - 249 */ 44, 88, 176, 125, 250, 233, 207, 131, 27, 54,
/* 250 - 255 */ 108, 216, 173, 71, 142, 1}
/* 250 - 255 */ 108, 216, 173, 71, 142, 1,
}

gfLogTable = [256]int{
/* 0 - 9 */ -1, 0, 1, 25, 2, 50, 26, 198, 3, 223,
Expand Down Expand Up @@ -70,7 +71,8 @@ var (
/* 220 - 229 */ 187, 204, 62, 90, 203, 89, 95, 176, 156, 169,
/* 230 - 239 */ 160, 81, 11, 245, 22, 235, 122, 117, 44, 215,
/* 240 - 249 */ 79, 174, 213, 233, 230, 231, 173, 232, 116, 214,
/* 250 - 255 */ 244, 234, 168, 80, 88, 175}
/* 250 - 255 */ 244, 234, 168, 80, 88, 175,
}
)

// gfElement is an element in GF(2^8).
Expand Down
2 changes: 1 addition & 1 deletion reedsolomon/gf2_8_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestGFMultiplicationIdentities(t *testing.T) {

func TestGFMultiplicationAndDivision(t *testing.T) {
// a * b == result
var tests = []struct {
tests := []struct {
a gfElement
b gfElement
result gfElement
Expand Down
8 changes: 4 additions & 4 deletions reedsolomon/gf_poly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "testing"

func TestGFPolyAdd(t *testing.T) {
// a + b == result
var tests = []struct {
tests := []struct {
a gfPoly
b gfPoly
result gfPoly
Expand Down Expand Up @@ -45,7 +45,7 @@ func TestGFPolyAdd(t *testing.T) {

func TestGFPolyequals(t *testing.T) {
// a == b if isEqual
var tests = []struct {
tests := []struct {
a gfPoly
b gfPoly
isEqual bool
Expand Down Expand Up @@ -84,7 +84,7 @@ func TestGFPolyequals(t *testing.T) {

func TestGFPolyMultiply(t *testing.T) {
// a * b == result
var tests = []struct {
tests := []struct {
a gfPoly
b gfPoly
result gfPoly
Expand Down Expand Up @@ -121,7 +121,7 @@ func TestGFPolyMultiply(t *testing.T) {

func TestGFPolyRemainder(t *testing.T) {
// numerator / denominator == quotient + remainder.
var tests = []struct {
tests := []struct {
numerator gfPoly
denominator gfPoly
remainder gfPoly
Expand Down
10 changes: 6 additions & 4 deletions reedsolomon/reed_solomon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestGeneratorPoly(t *testing.T) {
var tests = []struct {
tests := []struct {
degree int
generator gfPoly
}{
Expand All @@ -36,11 +36,13 @@ func TestGeneratorPoly(t *testing.T) {
// + 11x^0 (the longest generator poly)
{
68,
gfPoly{term: []gfElement{11, 99, 29, 32, 8, 204, 149, 34, 12,
gfPoly{term: []gfElement{
11, 99, 29, 32, 8, 204, 149, 34, 12,
235, 11, 119, 7, 255, 239, 211, 157, 80, 4, 199, 36, 63, 88, 158, 51, 212,
219, 20, 245, 226, 175, 14, 20, 144, 225, 230, 246, 71, 107, 38, 107, 182,
170, 224, 172, 145, 112, 185, 20, 109, 167, 174, 34, 107, 85, 119, 142,
157, 230, 223, 94, 60, 182, 18, 39, 9, 115, 131, 1}},
157, 230, 223, 94, 60, 182, 18, 39, 9, 115, 131, 1,
}},
},
}

Expand All @@ -55,7 +57,7 @@ func TestGeneratorPoly(t *testing.T) {
}

func TestEncode(t *testing.T) {
var tests = []struct {
tests := []struct {
numECBytes int
data string
rsCode string
Expand Down
4 changes: 2 additions & 2 deletions regular_symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ var (
)

func buildRegularSymbol(version qrCodeVersion, mask int,
data *bitset.Bitset, includeQuietZone bool) (*symbol, error) {

data *bitset.Bitset, includeQuietZone bool,
) (*symbol, error) {
quietZoneSize := 0
if includeQuietZone {
quietZoneSize = version.quietZoneSize()
Expand Down
2 changes: 1 addition & 1 deletion regular_symbol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestBuildRegularSymbol(t *testing.T) {
fmt.Println(err.Error())
} else {
_ = s
//fmt.Print(m.string())
// fmt.Print(m.string())
}
}
}
Loading

0 comments on commit 80dea09

Please sign in to comment.