Function updateDict
has a Cognitive Complexity of 32 (exceeds 20 allowed). Consider refactoring. Open
func updateDict(dict *GoMap, updates starlark.Tuple, kwargs []starlark.Tuple) error {
if len(updates) == 1 {
switch updates := updates[0].(type) {
case starlark.NoneType:
// no-op
- 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 updateDict
has 8 return statements (exceeds 4 allowed). Open
func updateDict(dict *GoMap, updates starlark.Tuple, kwargs []starlark.Tuple) error {
if len(updates) == 1 {
switch updates := updates[0].(type) {
case starlark.NoneType:
// no-op
Avoid deeply nested control flow statements. Open
} else if l != 2 {
return fmt.Errorf("dictionary update sequence element #%d has length %d, want 2", i, l)
}
Method GoMap.SetKey
has 5 return statements (exceeds 4 allowed). Open
func (g *GoMap) SetKey(k, v starlark.Value) (err error) {
if g.frozen {
return fmt.Errorf("cannot insert into frozen map")
}
if g.numIt > 0 {
Function dict_pop
has 5 return statements (exceeds 4 allowed). Open
func dict_pop(fnname string, g *GoMap, args starlark.Tuple, _ []starlark.Tuple) (starlark.Value, error) {
if len(args) == 0 || len(args) > 2 {
return nil, fmt.Errorf("%s: got %d arguments, want 1 or 2", fnname, len(args))
}
v, found, err := g.Delete(args[0])
Function dict_popitem
has 5 return statements (exceeds 4 allowed). Open
func dict_popitem(fnname string, g *GoMap, args starlark.Tuple, _ []starlark.Tuple) (starlark.Value, error) {
if len(args) > 0 {
return nil, fmt.Errorf("%s: wanted 0 args, got %d", fnname, len(args))
}
keys := g.v.MapKeys()
Similar blocks of code found in 2 locations. Consider refactoring. Open
func mapAttr(recv *GoMap, name string, methods map[string]builtinMapMethod) (starlark.Value, error) {
method := methods[name]
if method == nil {
return nil, nil // no such method
}
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 173.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
don't use underscores in Go names; func dict_pop should be dictPop Open
func dict_pop(fnname string, g *GoMap, args starlark.Tuple, _ []starlark.Tuple) (starlark.Value, error) {
- Exclude checks
don't use underscores in Go names; func dict_popitem should be dictPopitem Open
func dict_popitem(fnname string, g *GoMap, args starlark.Tuple, _ []starlark.Tuple) (starlark.Value, error) {
- Exclude checks
exported method GoMap.Clear should have comment or be unexported Open
func (g *GoMap) Clear() error {
- Exclude checks
exported method GoMap.Items should have comment or be unexported Open
func (g *GoMap) Items() []starlark.Tuple {
- Exclude checks
exported method GoMap.Keys should have comment or be unexported Open
func (g *GoMap) Keys() []starlark.Value {
- Exclude checks
don't use underscores in Go names; func dict_setdefault should be dictSetdefault Open
func dict_setdefault(fnname string, g *GoMap, args starlark.Tuple, _ []starlark.Tuple) (starlark.Value, error) {
- Exclude checks
don't use underscores in Go names; func dict_clear should be dictClear Open
func dict_clear(fnname string, g *GoMap, args starlark.Tuple, _ []starlark.Tuple) (starlark.Value, error) {
- Exclude checks
don't use underscores in Go names; func dict_update should be dictUpdate Open
func dict_update(fnname string, g *GoMap, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
- Exclude checks
don't use underscores in Go names; func dict_values should be dictValues Open
func dict_values(fnname string, g *GoMap, args starlark.Tuple, _ []starlark.Tuple) (starlark.Value, error) {
- Exclude checks
exported method GoMap.Attr should have comment or be unexported Open
func (g *GoMap) Attr(name string) (starlark.Value, error) {
- Exclude checks
don't use underscores in Go names; func dict_items should be dictItems Open
func dict_items(fnname string, g *GoMap, args starlark.Tuple, _ []starlark.Tuple) (starlark.Value, error) {
- Exclude checks
exported method GoMap.AttrNames should have comment or be unexported Open
func (g *GoMap) AttrNames() []string {
- Exclude checks
exported method GoMap.Delete should have comment or be unexported Open
func (g *GoMap) Delete(k starlark.Value) (v starlark.Value, found bool, err error) {
- Exclude checks
exported method GoMap.Len should have comment or be unexported Open
func (g *GoMap) Len() int {
- Exclude checks
don't use underscores in Go names; func dict_keys should be dictKeys Open
func dict_keys(fnname string, g *GoMap, args starlark.Tuple, _ []starlark.Tuple) (starlark.Value, error) {
- Exclude checks
don't use underscores in Go names; func dict_get should be dictGet Open
func dict_get(fnname string, g *GoMap, args starlark.Tuple, _ []starlark.Tuple) (starlark.Value, error) {
- Exclude checks
exported method GoMap.Iterate should have comment or be unexported Open
func (g *GoMap) Iterate() starlark.Iterator {
- Exclude checks