taye/interact.js

View on GitHub
packages/@interactjs/core/events.ts

Summary

Maintainability
F
3 days
Test Coverage
A
97%

Function install has a Cognitive Complexity of 109 (exceeds 5 allowed). Consider refactoring.
Open

function install (scope: Interact.Scope) {
  const targets: Array<{
    eventTarget: EventTarget
    events: { [type: string]: Listener[] }
  }> = []
Severity: Minor
Found in packages/@interactjs/core/events.ts - About 2 days 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

Function install has 169 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function install (scope: Interact.Scope) {
  const targets: Array<{
    eventTarget: EventTarget
    events: { [type: string]: Listener[] }
  }> = []
Severity: Major
Found in packages/@interactjs/core/events.ts - About 6 hrs to fix

    Function remove has 40 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      function remove (eventTarget: EventTarget, type: string, listener?: 'all' | Listener, optionalArg?: boolean | any) {
        const options = getOptions(optionalArg)
        const targetIndex = arr.findIndex(targets, t => t.eventTarget === eventTarget)
        const target = targets[targetIndex]
    
    
    Severity: Minor
    Found in packages/@interactjs/core/events.ts - About 1 hr to fix

      Avoid deeply nested control flow statements.
      Open

                  if (typeListeners.length === 0) {
                    delete target.events[type]
                    typeIsEmpty = true
                  }
      Severity: Major
      Found in packages/@interactjs/core/events.ts - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                    if (!listeners.length) {
                      delegates.splice(index, 1)
        
                      // remove delegate function from context
                      remove(context, type, delegateListener)
        Severity: Major
        Found in packages/@interactjs/core/events.ts - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                      if (capture === options.capture && passive === options.passive) {
                        fn(fakeEvent)
                      }
          Severity: Major
          Found in packages/@interactjs/core/events.ts - About 45 mins to fix

            Function removeDelegate has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                selector: string,
                context: Document | Interact.Element,
                type: string,
                listener?: Listener,
                optionalArg?: any,
            Severity: Minor
            Found in packages/@interactjs/core/events.ts - About 35 mins to fix

              Function addDelegate has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                function addDelegate (selector: string, context: Node, type: string, listener: Listener, optionalArg?: any) {
              Severity: Minor
              Found in packages/@interactjs/core/events.ts - About 35 mins to fix

                There are no issues that match your filters.

                Category
                Status