pkg/kt/service/dns/hosts.go
Function dropHosts
has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring. Open
Open
func dropHosts(rawLines []string, namespaceToDrop string) ([]string, []string, error) {
escapeBegin := -1
escapeEnd := -1
midDomain := fmt.Sprintf(".%s", namespaceToDrop)
fullDomain := fmt.Sprintf(".%s.svc.%s", namespaceToDrop, opt.Get().Connect.ClusterDomain)
- 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
Avoid deeply nested control flow statements. Open
Open
} else if !strings.HasSuffix(l, midDomain) && !strings.HasSuffix(l, fullDomain) {
recordsToKeep = append(recordsToKeep, l)
}
Avoid deeply nested control flow statements. Open
Open
if keepShortDomain {
recordsToKeep = append(recordsToKeep, l)
}
Function updateHostsFile
has 5 return statements (exceeds 4 allowed). Open
Open
func updateHostsFile(lines []string) error {
lock := flock.New(fmt.Sprintf("%s/hosts.lock", util.KtLockDir))
timeoutContext, cancel := context.WithTimeout(context.TODO(), 2 * time.Second)
defer cancel()
if ok, err := lock.TryLockContext(timeoutContext, 100 * time.Millisecond); !ok {
Function DumpHosts
has 5 return statements (exceeds 4 allowed). Open
Open
func DumpHosts(hostsMap map[string]string, namespaceToDrop string) error {
if doNotDump {
return nil
}
lines, err := loadHostsFile()