From 11582d35901262597059a7ded3a67661ed2854fb Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sat, 8 Jun 2024 10:29:35 +0200 Subject: [PATCH] Update linter config and apply suggestions - remove copyright years (they are in git) - remove outdated linter bug workarounds - update .golangci.yml to match current schema (as of golangci-lint 1.59.0) --- .golangci.yml | 14 ++++++++------ cmd/boardvoting/config.go | 2 +- cmd/boardvoting/main.go | 2 +- internal/app/app.go | 2 +- internal/forms/forms.go | 2 +- internal/handlers/flashmessage.go | 2 +- internal/handlers/handlers.go | 2 +- internal/handlers/handlers_test.go | 2 +- internal/handlers/middleware.go | 2 +- internal/handlers/middleware_test.go | 11 ++++++----- internal/handlers/templatecache.go | 2 +- internal/jobs/closedecisions.go | 2 +- internal/jobs/doc.go | 2 +- internal/jobs/jobs.go | 2 +- internal/jobs/remindvoters.go | 2 +- internal/jobs/scheduler.go | 2 +- internal/mailtemplates.go | 2 +- internal/migrations.go | 2 +- internal/models/audit.go | 2 +- internal/models/models.go | 2 +- internal/models/motions.go | 8 ++++---- internal/models/motions_test.go | 2 +- internal/models/users.go | 2 +- internal/notifications/mailnotifier.go | 2 +- internal/validator/validator.go | 2 +- ui/efs.go | 2 +- 26 files changed, 41 insertions(+), 38 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 837e5e4..7d73b83 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,7 +1,9 @@ --- run: - go: "1.17" - skip-files: + go: "1.19" + +issues: + exclude-files: - boardvoting/assets.go output: @@ -13,7 +15,7 @@ linters-settings: const: ORGANIZATION: CAcert Inc. template: |- - Copyright {{ YEAR-RANGE }} {{ ORGANIZATION }} + Copyright {{ ORGANIZATION }} SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,8 +29,8 @@ linters-settings: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - gomnd: - ignore-functions: + mnd: + ignored-functions: - 'strconv.*' ignored-numbers: - '-1,0,1,2,8' @@ -57,7 +59,7 @@ linters: - gofmt - goheader - goimports - - gomnd + - mnd - gosec - lll - makezero diff --git a/cmd/boardvoting/config.go b/cmd/boardvoting/config.go index 04b597f..d9da314 100644 --- a/cmd/boardvoting/config.go +++ b/cmd/boardvoting/config.go @@ -1,5 +1,5 @@ /* -Copyright 2017-2022 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/cmd/boardvoting/main.go b/cmd/boardvoting/main.go index 122f3f6..3463f7c 100644 --- a/cmd/boardvoting/main.go +++ b/cmd/boardvoting/main.go @@ -1,5 +1,5 @@ /* -Copyright 2017-2022 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/internal/app/app.go b/internal/app/app.go index b53c3a4..4106479 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -1,5 +1,5 @@ /* -Copyright 2017-2022 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/internal/forms/forms.go b/internal/forms/forms.go index ae693ed..5b023fb 100644 --- a/internal/forms/forms.go +++ b/internal/forms/forms.go @@ -1,5 +1,5 @@ /* -Copyright 2022 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/internal/handlers/flashmessage.go b/internal/handlers/flashmessage.go index dea2971..4b5cf2d 100644 --- a/internal/handlers/flashmessage.go +++ b/internal/handlers/flashmessage.go @@ -1,5 +1,5 @@ /* -Copyright 2017-2022 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index 4160fed..56b74ab 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -1,5 +1,5 @@ /* -Copyright 2017-2022 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/internal/handlers/handlers_test.go b/internal/handlers/handlers_test.go index 3be4cbf..3506536 100644 --- a/internal/handlers/handlers_test.go +++ b/internal/handlers/handlers_test.go @@ -1,5 +1,5 @@ /* -Copyright 2022 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/internal/handlers/middleware.go b/internal/handlers/middleware.go index 3477bb1..ee7cb71 100644 --- a/internal/handlers/middleware.go +++ b/internal/handlers/middleware.go @@ -1,5 +1,5 @@ /* -Copyright 2022 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/internal/handlers/middleware_test.go b/internal/handlers/middleware_test.go index 90e9fb9..dc3b2d8 100644 --- a/internal/handlers/middleware_test.go +++ b/internal/handlers/middleware_test.go @@ -1,5 +1,5 @@ /* -Copyright 2022 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); @@ -62,7 +62,7 @@ func Test_secureHeaders(t *testing.T) { SecureHeaders(next).ServeHTTP(rr, r) - rs := rr.Result() //nolint:bodyclose // linters bug + rs := rr.Result() defer func() { _ = rs.Body.Close() }() @@ -119,7 +119,7 @@ func TestApplication_tryAuthenticate(t *testing.T) { mw.TryAuthenticate(next).ServeHTTP(rr, r) - rs := rr.Result() //nolint:bodyclose // linters bug + rs := rr.Result() defer func() { _ = rs.Body.Close() }() @@ -137,7 +137,7 @@ func TestApplication_tryAuthenticate(t *testing.T) { mw.TryAuthenticate(next).ServeHTTP(rr, r) - rs := rr.Result() //nolint:bodyclose // linters bug + rs := rr.Result() defer func() { _ = rs.Body.Close() }() @@ -158,11 +158,12 @@ func TestApplication_tryAuthenticate(t *testing.T) { mw.TryAuthenticate(next).ServeHTTP(rr, r) - rs := rr.Result() //nolint:bodyclose // linters bug + rs := rr.Result() defer func() { _ = rs.Body.Close() }() assert.Equal(t, http.StatusOK, rs.StatusCode) + user := nextCtx.Value(ctxUser) assert.NotNil(t, user) diff --git a/internal/handlers/templatecache.go b/internal/handlers/templatecache.go index 37d9902..cb96eb1 100644 --- a/internal/handlers/templatecache.go +++ b/internal/handlers/templatecache.go @@ -1,5 +1,5 @@ /* -Copyright 2017-2022 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/internal/jobs/closedecisions.go b/internal/jobs/closedecisions.go index 209fa85..753a86b 100644 --- a/internal/jobs/closedecisions.go +++ b/internal/jobs/closedecisions.go @@ -1,5 +1,5 @@ /* -Copyright 2017-2022 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/internal/jobs/doc.go b/internal/jobs/doc.go index 2868937..2975748 100644 --- a/internal/jobs/doc.go +++ b/internal/jobs/doc.go @@ -1,5 +1,5 @@ /* -Copyright 2017-2022 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/internal/jobs/jobs.go b/internal/jobs/jobs.go index 55acd87..66c91b7 100644 --- a/internal/jobs/jobs.go +++ b/internal/jobs/jobs.go @@ -1,5 +1,5 @@ /* -Copyright 2017-2022 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/internal/jobs/remindvoters.go b/internal/jobs/remindvoters.go index 57b7d95..b26e60e 100644 --- a/internal/jobs/remindvoters.go +++ b/internal/jobs/remindvoters.go @@ -1,5 +1,5 @@ /* -Copyright 2017-2023 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/internal/jobs/scheduler.go b/internal/jobs/scheduler.go index 6f487b5..c5f51cd 100644 --- a/internal/jobs/scheduler.go +++ b/internal/jobs/scheduler.go @@ -1,5 +1,5 @@ /* -Copyright 2017-2022 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/internal/mailtemplates.go b/internal/mailtemplates.go index 9b615cc..ea4db2a 100644 --- a/internal/mailtemplates.go +++ b/internal/mailtemplates.go @@ -1,5 +1,5 @@ /* -Copyright 2022 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/internal/migrations.go b/internal/migrations.go index 8d9c8e3..7fbbd6a 100644 --- a/internal/migrations.go +++ b/internal/migrations.go @@ -1,5 +1,5 @@ /* -Copyright 2017-2022 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/internal/models/audit.go b/internal/models/audit.go index 8216be0..13086a0 100644 --- a/internal/models/audit.go +++ b/internal/models/audit.go @@ -1,5 +1,5 @@ /* -Copyright 2022 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/internal/models/models.go b/internal/models/models.go index 1c1150b..028c237 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -1,5 +1,5 @@ /* -Copyright 2022 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/internal/models/motions.go b/internal/models/motions.go index d72e1b6..1142765 100644 --- a/internal/models/motions.go +++ b/internal/models/motions.go @@ -1,5 +1,5 @@ /* -Copyright 2017-2023 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); @@ -607,12 +607,12 @@ func (m *MotionModel) List(ctx context.Context, options *MotionListOptions) ([]* } func (m *MotionModel) FillVoteSums(ctx context.Context, decisions []*Motion) error { - decisionIds := make([]int64, len(decisions)) + decisionIDs := make([]int64, len(decisions)) decisionMap := make(map[int64]*Motion, len(decisions)) for idx, decision := range decisions { decision.Sums = &VoteSums{} - decisionIds[idx] = decision.ID + decisionIDs[idx] = decision.ID decisionMap[decision.ID] = decision } @@ -621,7 +621,7 @@ func (m *MotionModel) FillVoteSums(ctx context.Context, decisions []*Motion) err FROM votes v WHERE v.decision IN (?) GROUP BY v.decision, v.vote`, - decisionIds, + decisionIDs, ) if err != nil { return fmt.Errorf("could not create IN query: %w", err) diff --git a/internal/models/motions_test.go b/internal/models/motions_test.go index f175b7b..e8af72a 100644 --- a/internal/models/motions_test.go +++ b/internal/models/motions_test.go @@ -1,5 +1,5 @@ /* -Copyright 2022 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/internal/models/users.go b/internal/models/users.go index 28ab131..5c3182e 100644 --- a/internal/models/users.go +++ b/internal/models/users.go @@ -1,5 +1,5 @@ /* -Copyright 2017-2022 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/internal/notifications/mailnotifier.go b/internal/notifications/mailnotifier.go index 6ac3b79..7fbb731 100644 --- a/internal/notifications/mailnotifier.go +++ b/internal/notifications/mailnotifier.go @@ -1,5 +1,5 @@ /* -Copyright 2017-2024 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/internal/validator/validator.go b/internal/validator/validator.go index 83fe252..b471ef2 100644 --- a/internal/validator/validator.go +++ b/internal/validator/validator.go @@ -1,5 +1,5 @@ /* -Copyright 2022 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ui/efs.go b/ui/efs.go index 0cd8254..54672a2 100644 --- a/ui/efs.go +++ b/ui/efs.go @@ -1,5 +1,5 @@ /* -Copyright 2022 CAcert Inc. +Copyright CAcert Inc. SPDX-License-Identifier: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License");