Showing 43 of 107 total issues
Function main
has 12 return statements (exceeds 4 allowed). Open
func main() {
colors.LoadFromMap(map[string]string{
"good": "#0f0",
"bad": "#f00",
"degraded": "#ff0",
Method SegmentGroup.Segments
has 54 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (g *SegmentGroup) Segments() []*bar.Segment {
var segments []*bar.Segment
for _, o := range g.outputs {
for _, s := range o.Segments() {
segments = append(segments, s.Clone())
Method write_capi_file
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def write_capi_file(library, package, pkg_config, header_filename, c_functions)
aliases = Set.new(
c_functions.flat_map { |fn| [fn.type] + fn.args.map(&:type) }
).map(&:aliases).reduce(&:merge)
Method alsaModule.Worker
has 9 return statements (exceeds 4 allowed). Open
func (m *alsaModule) Worker(s *value.ErrorValue) {
// Structs for querying ALSA.
var handle *ctyp_snd_mixer_t
var sid *ctyp_snd_mixer_selem_id_t
// Shortcut for error handling
Function fetch
has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring. Open
func fetch(srv *calendar.Service, conf config) ([]Event, error) {
timeMin := timing.Now()
timeMax := timeMin.Add(conf.lookahead)
req := srv.Events.List(conf.calendarID)
- 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 equalMarkup
has 8 return statements (exceeds 4 allowed). Open
func equalMarkup(a, b *html.Node) bool {
if a == nil && b == nil {
return true
}
if a == nil || b == nil {
Function Load
has 8 return statements (exceeds 4 allowed). Open
func Load(repoPath string) error {
f, err := fs.Open(filepath.Join(repoPath, "scss/_variables.scss"))
if err != nil {
return err
}
Method write_capi_file
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def write_capi_file(library, package, pkg_config, header_filename, c_functions)
aliases = Set.new(
c_functions.flat_map { |fn| [fn.type] + fn.args.map(&:type) }
).map(&:aliases).reduce(&:merge)
- 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 Watcher.tryWatch
has 7 return statements (exceeds 4 allowed). Open
func (w *Watcher) tryWatch(restarted bool) error {
currentLvl := -1
for lvl, p := range w.hierarchy {
err := w.fswatcher.Add(p)
if err == nil {
Avoid deeply nested control flow statements. Open
if !os.IsNotExist(err) {
l.Log("%s: %v", l.ID(w), err)
return err
}
Method provider.GetWeather
has 7 return statements (exceeds 4 allowed). Open
func (p *provider) GetWeather() (weather.Weather, error) {
response, err := http.Get(p.url)
if err != nil {
return weather.Weather{}, err
}
Function typeName
has 6 return statements (exceeds 4 allowed). Open
func typeName(typ reflect.Type) string {
if typ == nil {
return "nil"
}
name := typ.Name()
Method write_capi_file
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def write_capi_file(library, package, pkg_config, header_filename, c_functions)
Method TestBusObject.GoWithContext
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
func (t *TestBusObject) GoWithContext(ctx context.Context, method string, flags dbus.Flags, ch chan *dbus.Call, args ...interface{}) *dbus.Call {
Function Load
has 5 return statements (exceeds 4 allowed). Open
func Load(repoPath string) error {
f, err := fs.Open(filepath.Join(repoPath, "metadata/icons.yml"))
if err != nil {
return err
}
Function updateTz
has 5 return statements (exceeds 4 allowed). Open
func updateTz(tzFile string) error {
if atomic.LoadUint32(&testMode) > 0 {
return errTestMode
}
link, err := os.Readlink(tzFile)
Function shorten
has 5 return statements (exceeds 4 allowed). Open
func shorten(path string) string {
// If path is a function, it can be something like some/package.(*Type).fn,
// but we'll simplify it to some/package.Type.fn for logging.
path = strings.Replace(path, "*", "", -1)
path = strings.Replace(path, "(", "", -1)
Function getCondition
has 5 return statements (exceeds 4 allowed). Open
func getCondition(owmCondition int) weather.Condition {
switch owmCondition {
case 611, 612:
return weather.Sleet
case 701:
Function allBatteriesInfo
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
func allBatteriesInfo() Info {
dir, err := fs.Open("/sys/class/power_supply")
if err != nil {
l.Log("No batteries: %s", err)
return Info{Status: Disconnected}
- 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 SI
has 5 return statements (exceeds 4 allowed). Open
func SI(v float64, unit string) Value {
if v < 0 {
inv := SI(-v, unit)
inv.number = "-" + inv.number
return inv