Showing 526 of 526 total issues
Method CopyOptions.Run
has 7 return statements (exceeds 4 allowed). Open
func (o *CopyOptions) Run() error {
srcSpec, err := extractFileSpec(o.args[0])
if err != nil {
return err
}
Avoid deeply nested control flow statements. Open
if err != nil {
return nil, err
}
Avoid deeply nested control flow statements. Open
} else if lookup.DefValue != "" {
configFlags.KubeConfig = pointer.String(lookup.DefValue)
}
Avoid deeply nested control flow statements. Open
} else if code := status.Code(err); code == codes.AlreadyExists {
return fmt.Errorf("connect with cluster already established, disconnect required before proceeding")
} else {
return err
}
Method Manager.RentIP
has 7 return statements (exceeds 4 allowed). Open
func (m *Manager) RentIP(ctx context.Context) (*net.IPNet, *net.IPNet, error) {
addrs, _ := net.InterfaceAddrs()
var isAlreadyExistedFunc = func(ip net.IP) bool {
for _, addr := range addrs {
if addr == nil {
Function PullImage
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
func PullImage(ctx context.Context, platform *v1.Platform, cli *client.Client, dockerCli *command.DockerCli, img string, out io.Writer) error {
Avoid deeply nested control flow statements. Open
} else if err != nil {
log.Errorf("Receive from disconnect failed: %v", err)
return err
}
Avoid deeply nested control flow statements. Open
if err != nil {
return nil, err
}
Avoid deeply nested control flow statements. Open
} else if lookup.DefValue != "" {
path = lookup.DefValue
} else {
path = lookup.NoOptDefVal
}
Avoid deeply nested control flow statements. Open
} else if event.Op&fsnotify.Remove == fsnotify.Remove {
notifyCh <- NotifyMessage{
Operation: Remove,
FilePath: event.Name,
}
Method CCache.writePrincipal
has 7 return statements (exceeds 4 allowed). Open
func (c *CCache) writePrincipal(p principal, endian *binary.ByteOrder) ([]byte, error) {
var byteString bytes.Buffer
var err error
b := &byteString
Function NewTunEndpoint
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
func NewTunEndpoint(ctx context.Context, tun net.Conn, mtu uint32, engine config.Engine, in chan<- *DataElem, out chan *DataElem) stack.LinkEndpoint {
Method hijackedIOStreamer.stream
has 7 return statements (exceeds 4 allowed). Open
func (h *hijackedIOStreamer) stream(ctx context.Context) error {
restoreInput, err := h.setupInput()
if err != nil {
return fmt.Errorf("unable to setup input stream: %s", err)
}
Avoid deeply nested control flow statements. Open
if net.ParseIP(svc.Spec.ClusterIP) == nil {
continue
}
Avoid deeply nested control flow statements. Open
if err != nil {
log.Errorf("Failed to add hosts(%s) to hosts: %v", entryList2String(appendHosts), err)
}
Function ParseProxyInfo
has 7 return statements (exceeds 4 allowed). Open
func ParseProxyInfo(conn net.Conn) (id stack.TransportEndpointID, err error) {
var n int
var port = make([]byte, 2)
// local port
Function transportTun
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
func transportTun(ctx context.Context, tunInbound <-chan *DataElem, tunOutbound chan<- *DataElem, packetConn net.PacketConn, routeMapUDP *RouteMap, routeMapTCP *sync.Map) error {
Avoid deeply nested control flow statements. Open
if err != nil {
log.Errorf("Failed to remove hosts(%s) to hosts: %v", entryList2String(list), err)
}
Method Config.CancelDNS
has 7 return statements (exceeds 4 allowed). Open
func (c *Config) CancelDNS() {
if cancel != nil {
cancel()
}
dir := "/etc/resolver"
Identical blocks of code found in 2 locations. Consider refactoring. Open
for {
resp, err = client.Recv()
if err == io.EOF {
break
} else if err == nil {
- 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 115.
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