Skip to content

Commit

Permalink
chore: Use gofumpt instead of gofmt (#282)
Browse files Browse the repository at this point in the history
* chore: Use gofumpt for format

* chore: Run gofumpt
  • Loading branch information
obalunenko authored Dec 1, 2023
1 parent 9b4ebed commit 969c2ff
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 49 deletions.
1 change: 1 addition & 0 deletions cmd/aoc-cli/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func notFound(ctx context.Context) cli.CommandNotFoundFunc {
}
}
}

func menu(ctx context.Context) cli.ActionFunc {
return func(c *cli.Context) error {
ctx = command.ContextWithOptions(ctx, optionsFromCli(c)...)
Expand Down
6 changes: 2 additions & 4 deletions internal/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import (
"github.com/obalunenko/advent-of-code/internal/puzzles/input"
)

var (
// ErrUnauthorized returns when session is empty or invalid.
ErrUnauthorized = errors.New("unauthorized")
)
// ErrUnauthorized returns when session is empty or invalid.
var ErrUnauthorized = errors.New("unauthorized")

// Run runs puzzle solving for passed year/day date.
func Run(ctx context.Context, year, day string) (puzzles.Result, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestRun(t *testing.T) {
wantErr assert.ErrorAssertionFunc
}

var tests = []struct {
tests := []struct {
name string
returnParams returnParams
expected expected
Expand Down
30 changes: 16 additions & 14 deletions internal/puzzles/common/intcomputer/intcoumputer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,23 @@ func Test_New(t *testing.T) {
args: args{
input: strings.NewReader("1,9,10,3,2,3,11,0,99,30,40,50"),
},
want: IntComputer{memory: map[int]int{
0: 1,
1: 9,
2: 10,
3: 3,
4: 2,
5: 3,
6: 11,
7: 0,
8: 99,
9: 30,
10: 40,
11: 50,
want: IntComputer{
memory: map[int]int{
0: 1,
1: 9,
2: 10,
3: 3,
4: 2,
5: 3,
6: 11,
7: 0,
8: 99,
9: 30,
10: 40,
11: 50,
},
initial: []int{1, 9, 10, 3, 2, 3, 11, 0, 99, 30, 40, 50},
},
initial: []int{1, 9, 10, 3, 2, 3, 11, 0, 99, 30, 40, 50}},
wantErr: false,
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/puzzles/day_string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func TestDay_String(t *testing.T) {
const dayNotExist Day = 99

var tests = []struct {
tests := []struct {
name string
i Day
want string
Expand Down
2 changes: 1 addition & 1 deletion internal/puzzles/solutions/2015/day02/solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (b box) surfaceWithExtra() int {
}

func (b box) wrapRibbon() int {
var sides = []int{
sides := []int{
b.height, b.width, b.length,
}

Expand Down
2 changes: 1 addition & 1 deletion internal/puzzles/solutions/2017/day02/solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (s solution) Part2(input io.Reader) (string, error) {
for j := i + 1; j < len(numbers); j++ {
d2 := numbers[j]

var a, b = d1, d2
a, b := d1, d2

if a < b {
a, b = b, a
Expand Down
4 changes: 1 addition & 3 deletions internal/puzzles/solutions/2018/day01/solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ func (s solution) Part2(in io.Reader) (string, error) {
return part2(in)
}

var (
re = regexp.MustCompile(`(?s)(?P<sign>[+-])(?P<digits>\d+)`)
)
var re = regexp.MustCompile(`(?s)(?P<sign>[+-])(?P<digits>\d+)`)

const (
_ = iota
Expand Down
8 changes: 2 additions & 6 deletions internal/puzzles/solutions/2018/day02/solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ func (s solution) Part1(input io.Reader) (string, error) {
three = 3
)

var (
twoCount, threeCount int
)
var twoCount, threeCount int

for i := range boxes {
box := boxes[i]
Expand Down Expand Up @@ -69,9 +67,7 @@ func (s solution) Part2(input io.Reader) (string, error) {
// find common letters
boxesnum := len(boxes)

var (
box1, box2, common string
)
var box1, box2, common string

loop:
for i := 0; i <= boxesnum; i++ {
Expand Down
6 changes: 2 additions & 4 deletions internal/puzzles/solutions/2020/day01/solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (s solution) Day() string {
func (s solution) Part1(input io.Reader) (string, error) {
scanner := bufio.NewScanner(input)

var expensereport = make(map[int]bool)
expensereport := make(map[int]bool)

for scanner.Scan() {
entry, err := strconv.Atoi(scanner.Text())
Expand All @@ -47,9 +47,7 @@ func (s solution) Part1(input io.Reader) (string, error) {
dest = 2020
)

var (
a, b int
)
var a, b int

for e := range expensereport {
a = e
Expand Down
8 changes: 2 additions & 6 deletions internal/puzzles/solutions/2020/day02/solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ func (s solution) Part2(input io.Reader) (string, error) {
return strconv.Itoa(count), nil
}

var (
pwdRegex = regexp.MustCompile(`(?s)(\d{1,2})-(\d{1,2}) ([a-zA-Z]): (\w+)`)
)
var pwdRegex = regexp.MustCompile(`(?s)(\d{1,2})-(\d{1,2}) ([a-zA-Z]): (\w+)`)

const (
_ int = iota // full match - not needed
Expand Down Expand Up @@ -111,9 +109,7 @@ func pwdCount(input io.Reader, validationFunc pwdValidationFunc) (int, error) {

go validationFunc(inchan, reschan, donechan)

var (
count, operations int
)
var count, operations int

for scanner.Scan() {
line := scanner.Text()
Expand Down
2 changes: 1 addition & 1 deletion internal/puzzles/solutions/2021/day03/solution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func Test_bitrates_consumption(t *testing.T) {
}

func Test_lifeRate(t *testing.T) {
var diagnostic = []string{
diagnostic := []string{
"00100",
"11110",
"10110",
Expand Down
4 changes: 1 addition & 3 deletions internal/puzzles/solutions/2021/day05/solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,7 @@ func drawDiagram(lines []line) diagram {
}

func getBounds(lines []line) position {
var (
maxX, maxY int
)
var maxX, maxY int

for _, l := range lines {
if l.start.x > maxX {
Expand Down
3 changes: 2 additions & 1 deletion internal/puzzles/solutions/2021/day05/solution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func Test_getLines(t *testing.T) {
input io.Reader
}

var tests = []struct {
tests := []struct {
name string
args args
want []line
Expand Down Expand Up @@ -355,6 +355,7 @@ func getTestLines(tb testing.TB) []line {
},
}
}

func Test_filterLines(t *testing.T) {
type args struct {
lines []line
Expand Down
2 changes: 1 addition & 1 deletion internal/puzzles/year_string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func TestYear_String(t *testing.T) {
const yearNotExist Year = 99

var tests = []struct {
tests := []struct {
name string
i Year
want string
Expand Down
4 changes: 2 additions & 2 deletions scripts/style/fmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ source "${SCRIPTS_DIR}/helpers-source.sh"

echo "${SCRIPT_NAME} is running... "

checkInstalled 'gofmt'
checkInstalled 'gofumpt'

echo "Making filelist"
GO_FILES=( $(find . -type f -name "*.go" -not -path "./vendor/*" -not -path "./tools/vendor/*" -not -path "./.git/*") )
Expand All @@ -21,7 +21,7 @@ echo "Local packages prefix: ${LOCAL_PFX}"

for f in "${GO_FILES[@]}"; do
echo "Fixing fmt at ${f}"
gofmt -s -w "$f"
gofumpt -l -w "$f"
done

echo "${SCRIPT_NAME} done."

0 comments on commit 969c2ff

Please sign in to comment.