Skip to content

Commit

Permalink
fix: Linters
Browse files Browse the repository at this point in the history
  • Loading branch information
obalunenko committed Nov 25, 2024
1 parent 8b814e8 commit 63fe4e8
Show file tree
Hide file tree
Showing 30 changed files with 41 additions and 111 deletions.
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion cmd/aoc-cli/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions internal/command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 0 additions & 10 deletions internal/puzzles/common/intcomputer/intcoumputer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions internal/puzzles/input/content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
},
},
Expand Down
4 changes: 2 additions & 2 deletions internal/puzzles/name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ 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 {
assert.Error(t, err)

return
}

assert.NoError(t, err)

assert.Equal(t, tt.want, got)
})
}
Expand Down
4 changes: 0 additions & 4 deletions internal/puzzles/solutions/2015/day01/solution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions internal/puzzles/solutions/2015/day02/solution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions internal/puzzles/solutions/2016/day01/solution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/puzzles/solutions/2016/day02/solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion internal/puzzles/solutions/2017/day01/solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 0 additions & 4 deletions internal/puzzles/solutions/2017/day01/solution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions internal/puzzles/solutions/2018/day01/solution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions internal/puzzles/solutions/2019/day01/solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func calc(input io.Reader, calcFn calcFunc) (string, error) {
in <- module{
mass: mass,
}

lines++
}

Expand Down
8 changes: 0 additions & 8 deletions internal/puzzles/solutions/2019/day01/solution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}

Expand Down Expand Up @@ -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}

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions internal/puzzles/solutions/2019/day02/solution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions internal/puzzles/solutions/2019/day03/solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 0 additions & 6 deletions internal/puzzles/solutions/2019/day03/solution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions internal/puzzles/solutions/2019/day04/solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 63fe4e8

Please sign in to comment.