Go

Go

Made by DeepSource
Found for loop instead of append SCC-S1011
Anti-pattern
Major
Autofix

There is no need to range over the slice and append elements one by one; instead, use append because it's clear, simple, and idiomatic.

Found time.Now().Sub(t) instead of time.Since(t) SCC-S1012
Anti-pattern
Major
Autofix

The time.Since(t) helper has the same effect as using time.Now().Sub(t).

Found manually copying of struct fields SCC-S1016
Anti-pattern
Major
Autofix

Two struct types with identical fields can be converted, and hence a manual copy of struct fields could be avoided with the help of type conversion.

Found manual trimming of string SCC-S1017
Anti-pattern
Major
Autofix

Instead of using strings.HasPrefix and manual slicing, use the strings.TrimPrefix function. The original string will be returned if the string doesn't start with the prefix.

Use copy() for sliding elements SCC-S1018
Anti-pattern
Major
Autofix

copy() permits using the same source and destination slice, even with overlapping ranges. This makes it ideal for sliding elements in a slice.

Simplify make call by omitting redundant arguments SCC-S1019
Anti-pattern
Major
Autofix

The make function has default values for the length and capacity arguments.

  • For channels and maps, the length defaults to zero.
  • For slices the capacity defaults to the length.
Found redundant nil check in type assertion SCC-S1020
Anti-pattern
Major
Autofix

There is no need to check for nil when performing type assertion as it is implicitly handled. When false, the second value returned confirms that the value of the asserted type is nil.

Found variable declaration and assignment separately SCC-S1021
Anti-pattern
Major
Autofix

Variable declaration and assignment can be merged, simplifying the code.

Found redundant control flow SCC-S1023
Anti-pattern
Major
Autofix

Omit redundant control flow in your Go code.

Found x.Sub(time.Now()) instead of time.Until(x) SCC-S1024
Anti-pattern
Major
Autofix

The time.Until helper has the same effect as using x.Sub(time.Now()). The former is easier to read.

Don't use fmt.Sprintf("%s", x) unnecessarily SCC-S1025
Anti-pattern
Major
Autofix

There are more accessible and efficient ways of getting a value's string representation in many instances. Whenever a value's underlying type is a string already, or the type has a String() method, they should be used directly.

Omit redundant nil check around loop SCC-S1031
Anti-pattern
Major
Autofix

When using range on nil slices and maps, the loop will never execute, as the length of the iterable will be regarded as zero. This makes an additional nil check around the loop unnecessary.

Use sort.Ints(x), sort.Float64s(x), and sort.Strings(x) SCC-S1032
Anti-pattern
Major
Autofix

The sort.Ints, sort.Float64s and sort.Strings functions are shorthands and are easier to read than sort.Sort(sort.IntSlice(x)), sort.Sort(sort.Float64Slice(x)) and sort.Sort(sort.StringSlice(x))

Found unnecessary guard around call to delete SCC-S1033
Anti-pattern
Major
Autofix

Calling delete on a nil map does not do anything (no-op), and it can be safely removed, or there is a potential bug introduced with a typo.

Found unnecessary multiple type assertion SCC-S1034
Anti-pattern
Major
Autofix

Instead of asserting the type every time in a switch statement, assign the result of type assertion to a variable and use it.

Redundant call to net/http.CanonicalHeaderKey in method call on net/http.Header SCC-S1035
Anti-pattern
Major
Autofix

The methods on net/http.Header, namely Add, Del, Get and Set, already canonicalize the given header name. Hence, there is no need to call the http.CanonicalHeaderKey function for these headers.

Found trapping a signal that cannot be trapped SCC-SA1016
Anti-pattern
Major
Autofix

A process cannot intercept all signals. Specifically, on UNIX-like systems, the syscall.SIGKILL and syscall.SIGSTOP signals cannot be captured by the process but handled directly by the kernel. It is, therefore, pointless to try and handle these signals.

Unnecessary block CRT-A0008
Anti-pattern
Minor
Autofix

It is not recommended to use unnecessary blocks.

Pure function's return value is discarded, making the call pointless SCC-SA4017
Anti-pattern
Major
Autofix

Return value of a pure function the value should always be handled else, calling the function is pointless. If the return value is not required, it is recommended to remove the function call.

Duplicate build constraints SCC-SA4019
Anti-pattern
Major
Autofix

Multiple, identical build constraints in the same file.