diff --git a/cmd/aoc-cli/handlers.go b/cmd/aoc-cli/handlers.go index 3f1b9056..bcea700a 100644 --- a/cmd/aoc-cli/handlers.go +++ b/cmd/aoc-cli/handlers.go @@ -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)...) diff --git a/internal/command/command.go b/internal/command/command.go index 557a05d3..b16bdc2f 100644 --- a/internal/command/command.go +++ b/internal/command/command.go @@ -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) { diff --git a/internal/command/command_test.go b/internal/command/command_test.go index 3226bbae..4a9959da 100644 --- a/internal/command/command_test.go +++ b/internal/command/command_test.go @@ -122,7 +122,7 @@ func TestRun(t *testing.T) { wantErr assert.ErrorAssertionFunc } - var tests = []struct { + tests := []struct { name string returnParams returnParams expected expected diff --git a/internal/puzzles/common/intcomputer/intcoumputer_test.go b/internal/puzzles/common/intcomputer/intcoumputer_test.go index 546ea3fc..6480ed38 100644 --- a/internal/puzzles/common/intcomputer/intcoumputer_test.go +++ b/internal/puzzles/common/intcomputer/intcoumputer_test.go @@ -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, }, } diff --git a/internal/puzzles/day_string_test.go b/internal/puzzles/day_string_test.go index 117b05a8..bc0d49cd 100644 --- a/internal/puzzles/day_string_test.go +++ b/internal/puzzles/day_string_test.go @@ -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 diff --git a/internal/puzzles/solutions/2015/day02/solution.go b/internal/puzzles/solutions/2015/day02/solution.go index 0930fc39..90ccd48c 100644 --- a/internal/puzzles/solutions/2015/day02/solution.go +++ b/internal/puzzles/solutions/2015/day02/solution.go @@ -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, } diff --git a/internal/puzzles/solutions/2017/day02/solution.go b/internal/puzzles/solutions/2017/day02/solution.go index bd2bce29..0d8118f9 100644 --- a/internal/puzzles/solutions/2017/day02/solution.go +++ b/internal/puzzles/solutions/2017/day02/solution.go @@ -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 diff --git a/internal/puzzles/solutions/2018/day01/solution.go b/internal/puzzles/solutions/2018/day01/solution.go index 412078c4..1197627e 100644 --- a/internal/puzzles/solutions/2018/day01/solution.go +++ b/internal/puzzles/solutions/2018/day01/solution.go @@ -35,9 +35,7 @@ func (s solution) Part2(in io.Reader) (string, error) { return part2(in) } -var ( - re = regexp.MustCompile(`(?s)(?P[+-])(?P\d+)`) -) +var re = regexp.MustCompile(`(?s)(?P[+-])(?P\d+)`) const ( _ = iota diff --git a/internal/puzzles/solutions/2018/day02/solution.go b/internal/puzzles/solutions/2018/day02/solution.go index 1c89ddd6..a365a34a 100644 --- a/internal/puzzles/solutions/2018/day02/solution.go +++ b/internal/puzzles/solutions/2018/day02/solution.go @@ -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] @@ -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++ { diff --git a/internal/puzzles/solutions/2020/day01/solution.go b/internal/puzzles/solutions/2020/day01/solution.go index 64253c07..479ba44f 100644 --- a/internal/puzzles/solutions/2020/day01/solution.go +++ b/internal/puzzles/solutions/2020/day01/solution.go @@ -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()) @@ -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 diff --git a/internal/puzzles/solutions/2020/day02/solution.go b/internal/puzzles/solutions/2020/day02/solution.go index 54ba1ef0..c888fb95 100644 --- a/internal/puzzles/solutions/2020/day02/solution.go +++ b/internal/puzzles/solutions/2020/day02/solution.go @@ -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 @@ -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() diff --git a/internal/puzzles/solutions/2021/day03/solution_test.go b/internal/puzzles/solutions/2021/day03/solution_test.go index da2e4012..310a1873 100644 --- a/internal/puzzles/solutions/2021/day03/solution_test.go +++ b/internal/puzzles/solutions/2021/day03/solution_test.go @@ -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", diff --git a/internal/puzzles/solutions/2021/day05/solution.go b/internal/puzzles/solutions/2021/day05/solution.go index ee24ad97..c4e73d23 100644 --- a/internal/puzzles/solutions/2021/day05/solution.go +++ b/internal/puzzles/solutions/2021/day05/solution.go @@ -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 { diff --git a/internal/puzzles/solutions/2021/day05/solution_test.go b/internal/puzzles/solutions/2021/day05/solution_test.go index 32eca3c3..1dc56ce2 100644 --- a/internal/puzzles/solutions/2021/day05/solution_test.go +++ b/internal/puzzles/solutions/2021/day05/solution_test.go @@ -217,7 +217,7 @@ func Test_getLines(t *testing.T) { input io.Reader } - var tests = []struct { + tests := []struct { name string args args want []line @@ -355,6 +355,7 @@ func getTestLines(tb testing.TB) []line { }, } } + func Test_filterLines(t *testing.T) { type args struct { lines []line diff --git a/internal/puzzles/year_string_test.go b/internal/puzzles/year_string_test.go index 7baaf1a4..4c9b0495 100644 --- a/internal/puzzles/year_string_test.go +++ b/internal/puzzles/year_string_test.go @@ -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 diff --git a/scripts/style/fmt.sh b/scripts/style/fmt.sh index 9c9fb87a..f30f3d5e 100755 --- a/scripts/style/fmt.sh +++ b/scripts/style/fmt.sh @@ -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/*") ) @@ -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."