Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
53 changes: 36 additions & 17 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,18 @@ version: "2"
linters:
default: all
disable:
- cyclop
- depguard
- errchkjson
- errorlint
- exhaustruct
- forcetypeassert
- funlen
- gochecknoglobals
- gochecknoinits
- gocognit
- godot
- godox
- gosmopolitan
- inamedparam
- ireturn
- lll
- musttag
- ireturn # we be enabled again with v2
- noinlineerr
- nestif
- nlreturn
- nonamedreturns
- paralleltest
- recvcheck
- testpackage
- thelper
- tparallel
- unparam
- varnamelen
- whitespace
- wrapcheck
Expand All @@ -40,8 +25,32 @@ linters:
goconst:
min-len: 2
min-occurrences: 3
cyclop:
max-complexity: 20
gocyclo:
min-complexity: 55
min-complexity: 20
exhaustive:
default-signifies-exhaustive: true
default-case-required: true
lll:
line-length: 180
thelper:
test:
first: true
name: true
begin: true
benchmark:
first: true
name: true
begin: true
tb:
first: true
name: true
begin: false # disable for testing.TB - asserter callbacks don't need tb.Helper()
fuzz:
first: true
name: true
begin: true
exclusions:
generated: lax
presets:
Expand All @@ -57,9 +66,19 @@ formatters:
enable:
- gofmt
- goimports
- gofumpt
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
issues:
# Maximum issues count per one linter.
# Set to 0 to disable.
# Default: 50
max-issues-per-linter: 0
# Maximum count of issues with the same text.
# Set to 0 to disable.
# Default: 3
max-same-issues: 0
6 changes: 6 additions & 0 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"unicode/utf8"
)

//nolint:gocyclo,cyclop // essential complexity in RFC 3986 character validation, might be refactored in future
func validateUnreservedWithExtra(s string, acceptedRunes []rune) error {
for i := 0; i < len(s); {
r, size := utf8.DecodeRuneInString(s[i:])
Expand Down Expand Up @@ -64,6 +65,7 @@ func validateUnreservedWithExtra(s string, acceptedRunes []rune) error {
return nil
}

//nolint:gocognit // essential complexity in UTF-8 percent-encoding validation, might be refactored in future
func unescapePercentEncoding(s string) (rune, int, error) {
var (
offset int
Expand All @@ -85,6 +87,7 @@ func unescapePercentEncoding(s string) (rune, int, error) {
)

// escaped utf8 sequence
//nolint:nestif // essential complexity in UTF-8 decoding logic, would require major refactoring
if codePoint[0] >= twoBytesUnicodePoint {
// expect another escaped sequence
if offset >= len(s) {
Expand All @@ -96,6 +99,7 @@ func unescapePercentEncoding(s string) (rune, int, error) {
}
offset++

//nolint:gosec // G602: false positive, codePoint is [utf8.UTFMax]byte array (size 4), index 1 is valid
if codePoint[1], err = unescapeSequence(s[offset:]); err != nil {
return utf8.RuneError, 0, err
}
Expand All @@ -114,6 +118,7 @@ func unescapePercentEncoding(s string) (rune, int, error) {
}
offset++

//nolint:gosec // G602: false positive, codePoint is [utf8.UTFMax]byte array (size 4), index 2 is valid
if codePoint[2], err = unescapeSequence(s[offset:]); err != nil {
return utf8.RuneError, 0, err
}
Expand All @@ -131,6 +136,7 @@ func unescapePercentEncoding(s string) (rune, int, error) {
}
offset++

//nolint:gosec // G602: false positive, codePoint is [utf8.UTFMax]byte array (size 4), index 3 is valid
if codePoint[3], err = unescapeSequence(s[offset:]); err != nil {
return utf8.RuneError, 0, err
}
Expand Down
2 changes: 2 additions & 0 deletions default_ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func (u uri) DefaultPort() int {
// * https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml
//
// Also: https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
//
//nolint:gocyclo,cyclop // essential complexity in well-known scheme port mapping, might be refactored in future
func defaultPortForScheme(scheme string) uint64 {
//nolint:mnd // no need to define default ports with additional constants
switch scheme {
Expand Down
2 changes: 2 additions & 0 deletions dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
// in case you need specific schemes to validate the host as a DNS name.
//
// See: https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml
//
//nolint:gocyclo,gochecknoglobals // essential complexity in scheme-specific DNS validation rules, might be refactored in future; public API explicitly designed to be overridable
var UsesDNSHostValidation = func(scheme string) bool {
switch scheme {
// prioritize early exit on most commonly used schemes
Expand Down
8 changes: 4 additions & 4 deletions dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func TestValidateHostForScheme(t *testing.T) {
"a.1b",
"a.b.c.d",
"a-b.c-d",
"www.詹姆斯.org",
"www.詹-姆斯.org",
"www.詹姆斯.org", //nolint:gosmopolitan // legitimate test case for IRI (Internationalized Resource Identifier) support
"www.詹-姆斯.org", //nolint:gosmopolitan // legitimate test case for IRI (Internationalized Resource Identifier) support
fmt.Sprintf("a.%s.c", strings.Repeat("b", 63)),
"a%2Eb%2ec.d",
"a.b.c.d%30",
Expand All @@ -50,8 +50,8 @@ func TestValidateHostForScheme(t *testing.T) {
"a.b.c..",
".",
"",
"www.詹姆斯.org/",
"www.詹{姆}斯.org/",
"www.詹姆斯.org/", //nolint:gosmopolitan // legitimate test case for IRI (Internationalized Resource Identifier) support
"www.詹{姆}斯.org/", //nolint:gosmopolitan // legitimate test case for IRI (Internationalized Resource Identifier) support
fmt.Sprintf("a.%s.c", strings.Repeat("b", 64)),
fmt.Sprintf("a.%sb.c", string([]rune{utf8.RuneError})),
fmt.Sprintf("%sa.b.c", string([]rune{utf8.RuneError})), //nolint:perfsprint // we prefer consistency with the above lines over performance
Expand Down
4 changes: 2 additions & 2 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ var (
ErrInvalidEscaping = Error(newErr("invalid percent-escaping sequence"))
)

// URI-specific errors
// URI-specific errors.
var (
ErrNoSchemeFound = Error(newErr("no scheme found in URI"))
ErrInvalidScheme = Error(newErr("invalid scheme in URI"))
ErrInvalidQuery = Error(newErr("invalid query string in URI"))
ErrInvalidFragment = Error(newErr("invalid fragment in URI"))
)

// Authority-specific errors
// Authority-specific errors.
var (
ErrInvalidPath = Error(newErr("invalid path in URI"))
ErrInvalidHost = Error(newErr("invalid host in URI"))
Expand Down
Loading