rueian/rueidis

View on GitHub
rueidislock/lock.go

Summary

Maintainability
D
1 day
Test Coverage
A
99%

Method locker.try has a Cognitive Complexity of 68 (exceeds 20 allowed). Consider refactoring.
Open

func (m *locker) try(ctx context.Context, cancel context.CancelFunc, name string, g *gate) context.CancelFunc {
    var err error

    val := random()
    deadline := time.Now().Add(m.validity)
Severity: Minor
Found in rueidislock/lock.go - About 1 day to fix

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 locker.try has 84 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (m *locker) try(ctx context.Context, cancel context.CancelFunc, name string, g *gate) context.CancelFunc {
    var err error

    val := random()
    deadline := time.Now().Add(m.validity)
Severity: Major
Found in rueidislock/lock.go - About 2 hrs to fix

    Avoid deeply nested control flow statements.
    Open

                            if !m.noloop {
                                <-csc
                            }
    Severity: Major
    Found in rueidislock/lock.go - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          select {
                          case g.ch <- struct{}{}:
                          default:
                          }
      Severity: Major
      Found in rueidislock/lock.go - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if !m.noloop {
                                    <-csc
                                }
        Severity: Major
        Found in rueidislock/lock.go - About 45 mins to fix

          Method locker.waitgate has 5 return statements (exceeds 4 allowed).
          Open

          func (m *locker) waitgate(ctx context.Context, name string) (g *gate, err error) {
              m.mu.Lock()
              g, ok := m.gates[name]
              if !ok {
                  if m.gates == nil {
          Severity: Major
          Found in rueidislock/lock.go - About 35 mins to fix

            There are no issues that match your filters.

            Category
            Status