Showing 9 of 9 total issues
Function decodeInfoStrings
has a Cognitive Complexity of 40 (exceeds 20 allowed). Consider refactoring. Open
func decodeInfoStrings(line string) (types.Counter, error) {
if strings.HasSuffix(line, ":\n") { // A header line isn't a metric
return types.Counter{}, nil
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method Exporter.Collect
has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring. Open
func (e *Exporter) Collect(c chan<- prometheus.Metric) {
insts, err := e.client.GetCounters()
if err == nil {
e.up.With(prometheus.Labels{"host": e.hostname}).Set(1)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function decodeInfoStrings
has 72 lines of code (exceeds 50 allowed). Consider refactoring. Open
func decodeInfoStrings(line string) (types.Counter, error) {
if strings.HasSuffix(line, ":\n") { // A header line isn't a metric
return types.Counter{}, nil
}
Method CacheObjectClient.GetInfos
has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring. Open
func (c *CacheObjectClient) GetInfos() (types.Counters, error) {
var infos types.Counters
reader, err := c.readFromSquid("info")
if err != nil {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function decodeInfoStrings
has 7 return statements (exceeds 4 allowed). Open
func decodeInfoStrings(line string) (types.Counter, error) {
if strings.HasSuffix(line, ":\n") { // A header line isn't a metric
return types.Counter{}, nil
}
Avoid deeply nested control flow statements. Open
if slices := strings.Split(value, " "); len(slices) > 0 {
value = slices[1]
}
Avoid deeply nested control flow statements. Open
if len(value) > equalTwo {
value = strings.Split(strings.TrimSpace(value[equalTwo+1:]), " ")[0]
}
Function decodeServiceTimeStrings
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
func decodeServiceTimeStrings(line string) (types.Counter, error) {
if strings.HasSuffix(line, ":\n") { // A header line isn't a metric
return types.Counter{}, nil
}
if equal := strings.Index(line, ":"); equal >= 0 {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function createProxyHeader
has 5 return statements (exceeds 4 allowed). Open
func createProxyHeader(cfg *config.Config) string {
la := strings.Split(cfg.ListenAddress, ":")
if len(la) < 2 {
log.Printf("Cannot parse listen address (%s). Failed to create proxy header\n", cfg.ListenAddress)
return ""