Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(go): update to go 1.21 #4

Merged
merged 6 commits into from
Apr 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore(ci): fix lint findings
  • Loading branch information
Zenithar committed Apr 8, 2024
commit cc74458f4bc71d3b77300f9823820af2e85d0dbd
6 changes: 3 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ jobs:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-1.21-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.golang }}-
${{ runner.os }}-go-
- name: Setup gotestsum
uses: autero1/action-gotestsum@v2.0.0
with:
@@ -74,7 +74,7 @@ jobs:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-1.21-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.golang }}-
${{ runner.os }}-go-
- name: Setup gotestsum
uses: autero1/action-gotestsum@v2.0.0
with:
@@ -96,7 +96,7 @@ jobs:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-1.21-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.golang }}-
${{ runner.os }}-go-
- name: Setup gotestsum
uses: autero1/action-gotestsum@v2.0.0
with:
209 changes: 17 additions & 192 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,226 +1,51 @@
run:
# default concurrency is a available CPU number
concurrency: 4
# timeout for analysis, e.g. 30s, 5m, default is 1m
deadline: 20m
# exit code when at least one issue was found, default is 1
issues-exit-code: 1
# include test files or not, default is true
timeout: 5m
tests: false

skip-files:
- ".*\\.pb\\.go$"
- ".*\\.gen\\.go$"
- ".*\\_gen\\.go$"
- "mock_.*\\.go"
- ".*\\.resolvers\\.go$"

# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true

# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
# If invoked with -mod=readonly, the go command is disallowed from the implicit
# automatic updating of go.mod described above. Instead, it fails when any changes
# to go.mod are needed. This setting is most useful to check that go.mod does
# not need updates, such as in a continuous integration and testing system.
# If invoked with -mod=vendor, the go command assumes that the vendor
# directory holds the correct copies of dependencies and ignores
# the dependency descriptions in go.mod.
modules-download-mode: readonly

# Allow multiple parallel golangci-lint instances running.
# If false (default) - golangci-lint acquires file lock on start.
allow-parallel-runners: false

# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions
# default is "colored-line-number"
format: colored-line-number

# print lines of code with issue, default is true
print-issued-lines: true

# print linter name in the end of issue text, default is true
print-linter-name: true

# make issues output unique by line, default is true
uniq-by-line: true

# add a prefix to the output file references; default is no prefix
path-prefix: ""

# sorts results by: filepath, line and column
sort-results: false
- "testing.go"
- ".*\\.pb\\.go"
- ".*\\.gen\\.go"

linters-settings:
dogsled:
# checks assignments with too many blank identifiers; default is 2
max-blank-identifiers: 2
dupl:
# tokens count to trigger issue, 150 by default
threshold: 150
errcheck:
# report about not checking of errors in type assertions: `a := b.(MyStruct)`;
# default is false: such cases aren't reported by default.
check-type-assertions: false

# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
# default is false: such cases aren't reported by default.
check-blank: false

# [deprecated] comma-separated list of pairs of the form pkg:regex
# the regex is used to ignore names within pkg. (default "fmt:.*").
# see https://github.com/kisielk/errcheck#the-deprecated-method for details
ignore: fmt:.*,io/ioutil:^Read.*
exhaustive:
# check switch statements in generated files also
check-generated: false
# indicates that switch statements are to be considered exhaustive if a
# 'default' case is present, even if all enum members aren't listed in the
# switch
default-signifies-exhaustive: false
govet:
# report about shadowed variables
check-shadowing: true
goimports:
local: "zntr.io"
golint:
min-confidence: 0.8
gofmt:
simplify: true
gocyclo:
min-complexity: 15
min-confidence: 0
goconst:
min-len: 5
min-occurrences: 4
misspell:
locale: US
lll:
line-length: 140
tab-width: 1
gci:
# put imports beginning with prefix after 3rd-party packages;
# only support one prefix
# if not set, use goimports.local-prefixes
local-prefixes: zntr.io/solid
gocognit:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 20
goconst:
# minimal length of string constant, 3 by default
min-len: 3
# minimal occurrences count to trigger, 3 by default
min-occurrences: 3
nestif:
# minimal complexity of if statements to report, 5 by default
min-complexity: 4
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: ["argument","case","condition","return"]
unused:
# treat code as a program (not a library) and report unused exported identifiers; default is false.
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
# if it's called for subdir of a project it can't find funcs usages. All text editor integrations
# with golangci-lint call it on a directory with the changed file.
check-exported: false
unparam:
# call graph construction algorithm (cha, rta). In general, use cha for libraries,
# and rta for programs with main packages. Default is cha.
algo: cha

# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
# with golangci-lint call it on a directory with the changed file.
check-exported: false
nakedret:
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
max-func-lines: 30
prealloc:
# Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
# True by default.
simple: true
range-loops: true # Report preallocation suggestions on range loops, true by default
for-loops: false # Report preallocation suggestions on for loops, false by default
funlen:
lines: 100
statements: 50
gomodguard:
blocked:
modules:
- github.com/BurntSushi/toml:
recommandations:
- github.com/pelletier/go-toml
goheader:
template: |-
Licensed to SolID under one or more contributor
license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright
ownership. SolID licenses this file to you under
the Apache License, Version 2.0 (the "License"); you may
not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, 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.

gocritic:
# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks.
# Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags".
enabled-tags:
- diagnostic
- performance
- style
- opinionated
- experimental

linters:
disable-all: true
enable:
- asciicheck
- bodyclose
- deadcode
- depguard
- dogsled
# - dupl
- errcheck
- errorlint
- exportloopref
- exhaustive
# - forbidigo
- funlen
# - gochecknoinits
- exportloopref
- goconst
- gocritic
- gocyclo
- godot
- gofmt
- goheader
- gofumpt
- goimports
# - golint
# - gomnd
- goprintffuncname
- gomodguard
- gosec
- gosimple
- govet
- ineffassign
# - lll
- misspell
- nakedret
- noctx
- nolintlint
- rowserrcheck
- revive
- prealloc
- exportloopref
- staticcheck
- structcheck
- unused
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace
4 changes: 2 additions & 2 deletions v3/helpers.go
Original file line number Diff line number Diff line change
@@ -61,9 +61,9 @@
return ek, n2, ak, nil
}

func mac(ak, h, n, c, f, i []byte) ([]byte, error) {
func mac(ak, h, n, c, f, i []byte) ([]byte) {

Check failure on line 64 in v3/helpers.go

GitHub Actions / golangci-lint

File is not `gofmt`-ed with `-s` (gofmt)
// Compute pre-authentication message
preAuth := common.PreAuthenticationEncoding([]byte(h), n, c, f, i)

Check failure on line 66 in v3/helpers.go

GitHub Actions / golangci-lint

unnecessary conversion (unconvert)

// Compute MAC
mac := hmac.New(sha512.New384, ak)
@@ -72,5 +72,5 @@
mac.Write(preAuth)

// No error
return mac.Sum(nil), nil
return mac.Sum(nil)
}
12 changes: 3 additions & 9 deletions v3/local.go
Original file line number Diff line number Diff line change
@@ -90,10 +90,7 @@
ciph.XORKeyStream(body[nonceLength:], m)

// Compute MAC
t, err := mac(ak, []byte(LocalPrefix), body[:nonceLength], body[nonceLength:], f, i)
if err != nil {
return "", fmt.Errorf("paseto: unable to compute MAC: %w", err)
}
t := mac(ak, []byte(LocalPrefix), body[:nonceLength], body[nonceLength:], f, i)

// Serialize final token
// h || base64url(n || c || t)
@@ -107,14 +104,14 @@
}

final := make([]byte, 9+tokenLen)
copy(final, []byte(LocalPrefix))
copy(final, LocalPrefix)
base64.RawURLEncoding.Encode(final[9:], body)

// Assemble final token
if len(f) > 0 {
final[9+tokenLen-footerLen] = '.'
// Encode footer as RawURLBase64
base64.RawURLEncoding.Encode(final[9+tokenLen-footerLen+1:], []byte(f))

Check failure on line 114 in v3/local.go

GitHub Actions / golangci-lint

unnecessary conversion (unconvert)
}

// No error
@@ -186,10 +183,7 @@
}

// Compute MAC
t2, err := mac(ak, []byte(LocalPrefix), n, c, f, i)
if err != nil {
return nil, fmt.Errorf("paseto: unable to compute MAC: %w", err)
}
t2 := mac(ak, []byte(LocalPrefix), n, c, f, i)

// Time-constant compare MAC
if subtle.ConstantTimeCompare(t, t2) == 0 {
4 changes: 2 additions & 2 deletions v3/public.go
Original file line number Diff line number Diff line change
@@ -67,14 +67,14 @@ func Sign(m []byte, sk *ecdsa.PrivateKey, f, i []byte) (string, error) {
}

final := make([]byte, 10+tokenLen)
copy(final, []byte(PublicPrefix))
copy(final, PublicPrefix)
base64.RawURLEncoding.Encode(final[10:], body)

// Assemble final token
if len(f) > 0 {
final[10+tokenLen-footerLen] = '.'
// Encode footer as RawURLBase64
base64.RawURLEncoding.Encode(final[10+tokenLen-footerLen+1:], []byte(f))
base64.RawURLEncoding.Encode(final[10+tokenLen-footerLen+1:], f)
}

// No error
2 changes: 1 addition & 1 deletion v4/local.go
Original file line number Diff line number Diff line change
@@ -116,7 +116,7 @@ func Encrypt(r io.Reader, key *LocalKey, m, f, i []byte) (string, error) {
if len(f) > 0 {
final[9+tokenLen-footerLen] = '.'
// Encode footer as RawURLBase64
base64.RawURLEncoding.Encode(final[9+tokenLen-footerLen+1:], []byte(f))
base64.RawURLEncoding.Encode(final[9+tokenLen-footerLen+1:], f)
}

// No error
4 changes: 2 additions & 2 deletions v4/public.go
Original file line number Diff line number Diff line change
@@ -51,14 +51,14 @@ func Sign(m []byte, sk ed25519.PrivateKey, f, i []byte) (string, error) {
}

final := make([]byte, tokenLen+len(PublicPrefix))
copy(final, []byte(PublicPrefix))
copy(final, PublicPrefix)
base64.RawURLEncoding.Encode(final[10:], body)

// Assemble final token
if len(f) > 0 {
final[10+tokenLen-footerLen] = '.'
// Encode footer as RawURLBase64
base64.RawURLEncoding.Encode(final[10+tokenLen-footerLen+1:], []byte(f))
base64.RawURLEncoding.Encode(final[10+tokenLen-footerLen+1:], f)
}

// No error
Loading