From 63fe4e8e6f8c9499b79a85508c56bcef3390482d Mon Sep 17 00:00:00 2001 From: Oleg Balunenko Date: Mon, 25 Nov 2024 22:00:18 +0400 Subject: [PATCH] fix: Linters --- .golangci.yml | 4 ++-- cmd/aoc-cli/handlers.go | 2 +- internal/command/command_test.go | 8 ++++---- .../common/intcomputer/intcoumputer_test.go | 10 ---------- internal/puzzles/input/content_test.go | 8 ++++---- internal/puzzles/name_test.go | 4 ++-- .../solutions/2015/day01/solution_test.go | 4 ---- .../solutions/2015/day02/solution_test.go | 4 ---- .../solutions/2016/day01/solution_test.go | 4 ---- .../puzzles/solutions/2016/day02/solution.go | 2 +- .../puzzles/solutions/2017/day01/solution.go | 2 +- .../solutions/2017/day01/solution_test.go | 4 ---- .../solutions/2018/day01/solution_test.go | 4 ---- .../puzzles/solutions/2019/day01/solution.go | 1 + .../solutions/2019/day01/solution_test.go | 8 -------- .../solutions/2019/day02/solution_test.go | 4 ---- .../puzzles/solutions/2019/day03/solution.go | 2 -- .../solutions/2019/day03/solution_test.go | 6 ------ .../puzzles/solutions/2019/day04/solution.go | 7 +++---- .../solutions/2019/day04/solution_test.go | 16 ---------------- .../puzzles/solutions/2020/day01/solution.go | 1 + .../solutions/2020/day01/solution_test.go | 4 ---- .../solutions/2020/day02/solution_test.go | 4 ---- .../solutions/2021/day03/solution_test.go | 1 + .../puzzles/solutions/2021/day04/solution.go | 2 +- .../solutions/2021/day05/solution_test.go | 2 ++ .../puzzles/solutions/2021/day07/solution.go | 19 ++++++++++--------- .../puzzles/solutions/2022/day01/solution.go | 12 ++++++------ .../puzzles/solutions/2023/day01/solution.go | 1 + internal/puzzles/solver_test.go | 2 -- 30 files changed, 41 insertions(+), 111 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index bb59cb6b..33784656 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -98,6 +98,8 @@ linters-settings: # ). # Run `GL_DEBUG=govet golangci-lint run --enable=govet` to see default, all available analyzers, and enabled analyzers. # Default: [] + disable: + - fieldalignment enable: # Check for missing values after append. - appends @@ -127,8 +129,6 @@ linters-settings: - directive # Report passing non-pointer or non-error values to errors.As. - errorsas - # Find structs that would use less memory if their fields were sorted. - - fieldalignment # Find calls to a particular function. - findcall # Report assembly that clobbers the frame pointer before saving it. diff --git a/cmd/aoc-cli/handlers.go b/cmd/aoc-cli/handlers.go index bcea700a..2e1fd6da 100644 --- a/cmd/aoc-cli/handlers.go +++ b/cmd/aoc-cli/handlers.go @@ -21,7 +21,7 @@ import ( ) func onExit(_ context.Context) cli.AfterFunc { - return func(c *cli.Context) error { + return func(_ *cli.Context) error { fmt.Println("Exit...") return nil diff --git a/internal/command/command_test.go b/internal/command/command_test.go index 4a9959da..bdebb60c 100644 --- a/internal/command/command_test.go +++ b/internal/command/command_test.go @@ -34,10 +34,10 @@ func newMockHTTPClient(p returnParams) *mockHTTPClient { return &http.Response{ Status: http.StatusText(p.status), StatusCode: p.status, - Proto: "HTTP/1.0", - ProtoMajor: 1, - ProtoMinor: 0, - Header: nil, + Proto: req.Proto, + ProtoMajor: req.ProtoMajor, + ProtoMinor: req.ProtoMinor, + Header: req.Header, Body: p.body, ContentLength: 0, TransferEncoding: nil, diff --git a/internal/puzzles/common/intcomputer/intcoumputer_test.go b/internal/puzzles/common/intcomputer/intcoumputer_test.go index 6480ed38..3e9ecf9f 100644 --- a/internal/puzzles/common/intcomputer/intcoumputer_test.go +++ b/internal/puzzles/common/intcomputer/intcoumputer_test.go @@ -47,8 +47,6 @@ func Test_New(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got, err := New(tt.args.input) if tt.wantErr { @@ -116,8 +114,6 @@ func Test_computer_add(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { err := tt.c.add(tt.args.aPos, tt.args.bPos, tt.args.resPos) require.NoError(t, err) @@ -163,8 +159,6 @@ func Test_computer_mult(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { err := tt.c.mult(tt.args.aPos, tt.args.bPos, tt.args.resPos) require.NoError(t, err) @@ -195,8 +189,6 @@ func Test_computer_Execute(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { comp := tt.c got, err := comp.Execute() @@ -233,8 +225,6 @@ func Test_computer_Input(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { comp := tt.c comp.Input(tt.args.noun, tt.args.verb) diff --git a/internal/puzzles/input/content_test.go b/internal/puzzles/input/content_test.go index c16f58f0..a9cd2e07 100644 --- a/internal/puzzles/input/content_test.go +++ b/internal/puzzles/input/content_test.go @@ -34,10 +34,10 @@ func newMockHTTPClient(p returnParams) *mockHTTPClient { return &http.Response{ Status: http.StatusText(p.status), StatusCode: p.status, - Proto: "HTTP/1.0", + Proto: req.Proto, ProtoMajor: 1, - ProtoMinor: 0, - Header: nil, + ProtoMinor: req.ProtoMinor, + Header: req.Header, Body: p.body, ContentLength: 0, TransferEncoding: nil, @@ -173,7 +173,7 @@ func TestGet(t *testing.T) { name: "", client: client{ IHTTPClient: &mockHTTPClient{ - MockDo: func(req *http.Request) (*http.Response, error) { + MockDo: func(_ *http.Request) (*http.Response, error) { return &http.Response{}, errors.New("error in test") }, }, diff --git a/internal/puzzles/name_test.go b/internal/puzzles/name_test.go index d4e057c8..cd554e6c 100644 --- a/internal/puzzles/name_test.go +++ b/internal/puzzles/name_test.go @@ -49,8 +49,6 @@ func TestMakeName(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got, err := MakeName(tt.args.year, tt.args.puzzle) if tt.wantErr { @@ -58,7 +56,9 @@ func TestMakeName(t *testing.T) { return } + assert.NoError(t, err) + assert.Equal(t, tt.want, got) }) } diff --git a/internal/puzzles/solutions/2015/day01/solution_test.go b/internal/puzzles/solutions/2015/day01/solution_test.go index c33d19e5..038ac55d 100644 --- a/internal/puzzles/solutions/2015/day01/solution_test.go +++ b/internal/puzzles/solutions/2015/day01/solution_test.go @@ -124,8 +124,6 @@ func Test_solution_Part1(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got, err := s.Part1(tt.args.input) if tt.wantErr { @@ -180,8 +178,6 @@ func Test_solution_Part2(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got, err := s.Part2(tt.args.input) if tt.wantErr { diff --git a/internal/puzzles/solutions/2015/day02/solution_test.go b/internal/puzzles/solutions/2015/day02/solution_test.go index 2949470b..0793b9cd 100644 --- a/internal/puzzles/solutions/2015/day02/solution_test.go +++ b/internal/puzzles/solutions/2015/day02/solution_test.go @@ -68,8 +68,6 @@ func Test_solution_Part1(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got, err := s.Part1(tt.args.input) if tt.wantErr { @@ -124,8 +122,6 @@ func Test_solution_Part2(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got, err := s.Part2(tt.args.input) if tt.wantErr { diff --git a/internal/puzzles/solutions/2016/day01/solution_test.go b/internal/puzzles/solutions/2016/day01/solution_test.go index 1c2d949d..ead14d37 100644 --- a/internal/puzzles/solutions/2016/day01/solution_test.go +++ b/internal/puzzles/solutions/2016/day01/solution_test.go @@ -76,8 +76,6 @@ func Test_solution_Part1(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got, err := s.Part1(tt.args.input) if tt.wantErr { @@ -124,8 +122,6 @@ func Test_solution_Part2(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got, err := s.Part2(tt.args.input) if tt.wantErr { diff --git a/internal/puzzles/solutions/2016/day02/solution.go b/internal/puzzles/solutions/2016/day02/solution.go index a5b0e916..7dccf6bc 100644 --- a/internal/puzzles/solutions/2016/day02/solution.go +++ b/internal/puzzles/solutions/2016/day02/solution.go @@ -119,7 +119,7 @@ let's predict that this is a 2 dimension matrix and '5' is 0,2m func loadKeypadPart2() keypad { start := keypadPos{ x: 0, - y: 2, + y: 2, //nolint:mnd // False positive. } g := [][]string{ diff --git a/internal/puzzles/solutions/2017/day01/solution.go b/internal/puzzles/solutions/2017/day01/solution.go index 22761772..2ac9c01b 100644 --- a/internal/puzzles/solutions/2017/day01/solution.go +++ b/internal/puzzles/solutions/2017/day01/solution.go @@ -54,7 +54,7 @@ func part2(in io.Reader) (string, error) { return "", fmt.Errorf("make list: %w", err) } - shift := len(list) / 2 + shift := len(list) / 2 //nolint:mnd // False positive. itr := newIterator(list, shift, true) diff --git a/internal/puzzles/solutions/2017/day01/solution_test.go b/internal/puzzles/solutions/2017/day01/solution_test.go index 99057edd..33dfe23c 100644 --- a/internal/puzzles/solutions/2017/day01/solution_test.go +++ b/internal/puzzles/solutions/2017/day01/solution_test.go @@ -85,8 +85,6 @@ func Test_solution_Part1(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got, err := s.Part1(tt.args.input) if tt.wantErr { @@ -174,8 +172,6 @@ func Test_solution_Part2(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got, err := s.Part2(tt.args.input) if tt.wantErr { diff --git a/internal/puzzles/solutions/2018/day01/solution_test.go b/internal/puzzles/solutions/2018/day01/solution_test.go index 407b86c3..39876c26 100644 --- a/internal/puzzles/solutions/2018/day01/solution_test.go +++ b/internal/puzzles/solutions/2018/day01/solution_test.go @@ -84,8 +84,6 @@ func Test_solution_Part1(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got, err := s.Part1(tt.args.input) if tt.wantErr { @@ -164,8 +162,6 @@ func Test_solution_Part2(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got, err := s.Part2(tt.args.input) if tt.wantErr { diff --git a/internal/puzzles/solutions/2019/day01/solution.go b/internal/puzzles/solutions/2019/day01/solution.go index 285dbbb5..d5784051 100644 --- a/internal/puzzles/solutions/2019/day01/solution.go +++ b/internal/puzzles/solutions/2019/day01/solution.go @@ -81,6 +81,7 @@ func calc(input io.Reader, calcFn calcFunc) (string, error) { in <- module{ mass: mass, } + lines++ } diff --git a/internal/puzzles/solutions/2019/day01/solution_test.go b/internal/puzzles/solutions/2019/day01/solution_test.go index e9c43f7c..e199eaed 100644 --- a/internal/puzzles/solutions/2019/day01/solution_test.go +++ b/internal/puzzles/solutions/2019/day01/solution_test.go @@ -68,8 +68,6 @@ func Test_module_fuel(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { m := module{ mass: tt.fields.mass, @@ -116,8 +114,6 @@ func Test_calcPart1(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { in <- module{mass: tt.input} @@ -175,8 +171,6 @@ func Test_calcPart2(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { in <- module{mass: tt.input} @@ -232,8 +226,6 @@ func Test_calc(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { input := utils.ReaderFromFile(t, tt.args.inputPath) got, err := calc(input, tt.args.calcFn) diff --git a/internal/puzzles/solutions/2019/day02/solution_test.go b/internal/puzzles/solutions/2019/day02/solution_test.go index 3a4d3619..e330dc4d 100644 --- a/internal/puzzles/solutions/2019/day02/solution_test.go +++ b/internal/puzzles/solutions/2019/day02/solution_test.go @@ -50,8 +50,6 @@ func Test_nounVerb(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got := nounVerb(tt.args.noun, tt.args.verb) assert.Equal(t, tt.want, got) @@ -91,8 +89,6 @@ func Test_solution_Part1(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got, err := s.Part1(tt.args.input) if tt.wantErr { diff --git a/internal/puzzles/solutions/2019/day03/solution.go b/internal/puzzles/solutions/2019/day03/solution.go index 15f0d02f..22d6f9b5 100644 --- a/internal/puzzles/solutions/2019/day03/solution.go +++ b/internal/puzzles/solutions/2019/day03/solution.go @@ -185,8 +185,6 @@ func findCross(wm1, wm2 map[pos]int) []pos { res := make([]pos, 0, len(wm1)) for p := range wm1 { - p := p - if _, exist := wm2[p]; exist { res = append(res, p) } diff --git a/internal/puzzles/solutions/2019/day03/solution_test.go b/internal/puzzles/solutions/2019/day03/solution_test.go index 9acf1c85..2f4b253c 100644 --- a/internal/puzzles/solutions/2019/day03/solution_test.go +++ b/internal/puzzles/solutions/2019/day03/solution_test.go @@ -79,8 +79,6 @@ func Test_solution_Part1(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got, err := s.Part1(tt.args.input) if tt.wantErr { @@ -131,8 +129,6 @@ func Test_findCross(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got := findCross(tt.args.wm1, tt.args.wm2) assert.ElementsMatch(t, tt.want, got) @@ -182,8 +178,6 @@ func Test_solution_Part2(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got, err := s.Part2(tt.args.input) if tt.wantErr { diff --git a/internal/puzzles/solutions/2019/day04/solution.go b/internal/puzzles/solutions/2019/day04/solution.go index ded564a6..ecf341e1 100644 --- a/internal/puzzles/solutions/2019/day04/solution.go +++ b/internal/puzzles/solutions/2019/day04/solution.go @@ -96,15 +96,13 @@ func isIncreasing(n int) bool { func hasRepeated(n int) bool { nmbs := intToSlice(n) - var hasRepeated bool - for i := 1; i <= len(nmbs)-1; i++ { if nmbs[i] == nmbs[i-1] { - hasRepeated = true + return true } } - return hasRepeated + return false } func hasRepeatedWithDouble(n int) bool { @@ -143,6 +141,7 @@ func isPasswordPart2(n int) bool { return isIncreasing(n) && hasRepeatedWithDouble(n) } +//nolint:mnd // False positive. func intToSlice(n int) [6]int { return [6]int{ (n % 1000000) / 100000, diff --git a/internal/puzzles/solutions/2019/day04/solution_test.go b/internal/puzzles/solutions/2019/day04/solution_test.go index 73572e06..55d29086 100644 --- a/internal/puzzles/solutions/2019/day04/solution_test.go +++ b/internal/puzzles/solutions/2019/day04/solution_test.go @@ -60,8 +60,6 @@ func Test_solution_Part1(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got, err := s.Part1(tt.args.input) if tt.wantErr { @@ -100,8 +98,6 @@ func Test_findPasswords(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got, err := findPasswords(tt.args.low, tt.args.high, isPasswordPart1) if tt.wantErr { @@ -150,8 +146,6 @@ func Test_isIncreasing(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got := isIncreasing(tt.args.n) assert.Equal(t, tt.want, got) @@ -179,8 +173,6 @@ func Test_intToSlice(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got := intToSlice(tt.args.n) assert.Equal(t, tt.want, got) @@ -215,8 +207,6 @@ func Test_hasRepeated(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got := hasRepeated(tt.args.n) assert.Equal(t, tt.want, got) @@ -258,8 +248,6 @@ func Test_isPassword(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got := isPasswordPart1(tt.args.n) assert.Equal(t, tt.want, got) @@ -302,8 +290,6 @@ func Test_isPasswordPart2(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got := isPasswordPart2(tt.args.n) assert.Equal(t, tt.want, got) @@ -351,8 +337,6 @@ func Test_solution_Part2(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got, err := s.Part2(tt.args.input) if tt.wantErr { diff --git a/internal/puzzles/solutions/2020/day01/solution.go b/internal/puzzles/solutions/2020/day01/solution.go index 479ba44f..5bcff8d5 100644 --- a/internal/puzzles/solutions/2020/day01/solution.go +++ b/internal/puzzles/solutions/2020/day01/solution.go @@ -93,6 +93,7 @@ func (s solution) Part2(input io.Reader) (string, error) { return strconv.Itoa(res), nil } +//nolint:mnd // False positive due to magic numbers. func foundEntries(expensereport []int) (a, b, c int, err error) { const ( dest = 2020 diff --git a/internal/puzzles/solutions/2020/day01/solution_test.go b/internal/puzzles/solutions/2020/day01/solution_test.go index 7358c047..ca86e681 100644 --- a/internal/puzzles/solutions/2020/day01/solution_test.go +++ b/internal/puzzles/solutions/2020/day01/solution_test.go @@ -60,8 +60,6 @@ func Test_solution_Part1(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got, err := s.Part1(tt.args.input) if tt.wantErr { @@ -108,8 +106,6 @@ func Test_solution_Part2(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got, err := s.Part2(tt.args.input) if tt.wantErr { diff --git a/internal/puzzles/solutions/2020/day02/solution_test.go b/internal/puzzles/solutions/2020/day02/solution_test.go index 595506b4..5c1db630 100644 --- a/internal/puzzles/solutions/2020/day02/solution_test.go +++ b/internal/puzzles/solutions/2020/day02/solution_test.go @@ -60,8 +60,6 @@ func Test_solution_Part1(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got, err := s.Part1(tt.args.input) if tt.wantErr { @@ -108,8 +106,6 @@ func Test_solution_Part2(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got, err := s.Part2(tt.args.input) if tt.wantErr { diff --git a/internal/puzzles/solutions/2021/day03/solution_test.go b/internal/puzzles/solutions/2021/day03/solution_test.go index 310a1873..160d18e7 100644 --- a/internal/puzzles/solutions/2021/day03/solution_test.go +++ b/internal/puzzles/solutions/2021/day03/solution_test.go @@ -185,6 +185,7 @@ func Test_bitrates_consumption(t *testing.T) { first: tt.fields.gamma, second: tt.fields.epsilon, } + got, err := b.consumption() if !tt.wantErr(t, err, "consumption()") { return diff --git a/internal/puzzles/solutions/2021/day04/solution.go b/internal/puzzles/solutions/2021/day04/solution.go index 06ff77a0..7dbbb051 100644 --- a/internal/puzzles/solutions/2021/day04/solution.go +++ b/internal/puzzles/solutions/2021/day04/solution.go @@ -60,7 +60,7 @@ func (s solution) Part2(input io.Reader) (string, error) { func rule(boardsNum int) winRule { var count int - return func(w winner) bool { + return func(_ winner) bool { count++ return count == boardsNum diff --git a/internal/puzzles/solutions/2021/day05/solution_test.go b/internal/puzzles/solutions/2021/day05/solution_test.go index 1dc56ce2..0c6bf15a 100644 --- a/internal/puzzles/solutions/2021/day05/solution_test.go +++ b/internal/puzzles/solutions/2021/day05/solution_test.go @@ -207,6 +207,7 @@ func Test_parseCoordinates(t *testing.T) { if !tt.wantErr(t, err, fmt.Sprintf("parseCoordinates(%v)", tt.args.s)) { return } + assert.Equalf(t, tt.want, got, "parseCoordinates(%v)", tt.args.s) }) } @@ -247,6 +248,7 @@ func Test_getLines(t *testing.T) { if !tt.wantErr(t, err, fmt.Sprintf("getLines(%v)", tt.args.input)) { return } + assert.Equalf(t, tt.want, got, "getLines(%v)", tt.args.input) }) } diff --git a/internal/puzzles/solutions/2021/day07/solution.go b/internal/puzzles/solutions/2021/day07/solution.go index f1f28f16..b1faed8a 100644 --- a/internal/puzzles/solutions/2021/day07/solution.go +++ b/internal/puzzles/solutions/2021/day07/solution.go @@ -77,19 +77,19 @@ func makeMatrix(crabs []int) [][]int { cnum := len(crabs) - max := crabs[cnum-1] + maxC := crabs[cnum-1] matrix := make([][]int, cnum+header) // matrix[i][j]. - // i - crabs; j - all positions from 0 to max + // i - crabs; j - all positions from 0 to maxC for i := 0; i < cnum+header; i++ { - matrix[i] = make([]int, max+header+1) + matrix[i] = make([]int, maxC+header+1) if i == 0 { matrix[i][0] = undef - for j := 1; j <= max+header; j++ { + for j := 1; j <= maxC+header; j++ { matrix[i][j] = j - 1 } @@ -136,6 +136,7 @@ func part1Cost(p int) int { return p } +//nolint:mnd // Formula is not a magic number. func part2Cost(p int) int { // formula a_{n}=a_{1}+(n-1)d an := 1 + 1*(p-1) @@ -164,7 +165,7 @@ func (s swarm) minDistanceCost() int { } func minDistanceCost(matrix [][]int) int { - var min int + var minC int ilen := len(matrix) jlen := len(matrix[0]) @@ -177,13 +178,13 @@ func minDistanceCost(matrix [][]int) int { } if j == 1 { - min = f + minC = f } - if f < min { - min = f + if f < minC { + minC = f } } - return min + return minC } diff --git a/internal/puzzles/solutions/2022/day01/solution.go b/internal/puzzles/solutions/2022/day01/solution.go index 20ae4fce..e14bb677 100644 --- a/internal/puzzles/solutions/2022/day01/solution.go +++ b/internal/puzzles/solutions/2022/day01/solution.go @@ -130,23 +130,23 @@ func (e elves) String() string { } func (e elves) maxTotalCalories() int { - var max int + var maxC int for _, el := range e { - if max == 0 { - max = el.totalCalories() + if maxC == 0 { + maxC = el.totalCalories() continue } c := el.totalCalories() - if c > max { - max = c + if c > maxC { + maxC = c } } - return max + return maxC } func (e elves) backupSnackCalc() int { diff --git a/internal/puzzles/solutions/2023/day01/solution.go b/internal/puzzles/solutions/2023/day01/solution.go index 52405f94..669e31c0 100644 --- a/internal/puzzles/solutions/2023/day01/solution.go +++ b/internal/puzzles/solutions/2023/day01/solution.go @@ -56,6 +56,7 @@ const ( nine = "nine" ) +//nolint:mnd // False positive. var digitsDict = map[string]int{ one: 1, two: 2, diff --git a/internal/puzzles/solver_test.go b/internal/puzzles/solver_test.go index 0f9b0db8..a02c9eb1 100644 --- a/internal/puzzles/solver_test.go +++ b/internal/puzzles/solver_test.go @@ -195,8 +195,6 @@ func TestRun(t *testing.T) { } for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { got, err := puzzles.Solve(tt.args.solver, tt.args.input) if tt.wantErr {