taye/interact.js

View on GitHub
packages/utils/events.ts

Summary

Maintainability
D
2 days
Test Coverage
F
47%

Function remove has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
Open

function remove (element: EventTarget, type: string, listener?: 'all' | Listener, optionalArg?: boolean | any) {
  const options = getOptions(optionalArg)
  const elementIndex = elements.indexOf(element)
  const target = targets[elementIndex]

Severity: Minor
Found in packages/utils/events.ts - About 4 hrs 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 removeDelegate has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

function removeDelegate (selector, context, type, listener?, optionalArg?: any) {
  const options = getOptions(optionalArg)
  const delegated = delegatedEvents[type]
  let matchFound = false
  let index
Severity: Minor
Found in packages/utils/events.ts - About 3 hrs 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 delegateListener has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

function delegateListener (event: Event, optionalArg?: any) {
  const options = getOptions(optionalArg)
  const fakeEvent = new FakeEvent(event)
  const delegated = delegatedEvents[event.type]
  const [eventTarget] = (pointerUtils.getEventTargets(event))
Severity: Minor
Found in packages/utils/events.ts - About 1 hr 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 remove has 40 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function remove (element: EventTarget, type: string, listener?: 'all' | Listener, optionalArg?: boolean | any) {
  const options = getOptions(optionalArg)
  const elementIndex = elements.indexOf(element)
  const target = targets[elementIndex]

Severity: Minor
Found in packages/utils/events.ts - About 1 hr to fix

    Function removeDelegate has 30 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function removeDelegate (selector, context, type, listener?, optionalArg?: any) {
      const options = getOptions(optionalArg)
      const delegated = delegatedEvents[type]
      let matchFound = false
      let index
    Severity: Minor
    Found in packages/utils/events.ts - About 1 hr to fix

      Function addDelegate has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function addDelegate (selector: string, context: Node, type: string, listener: Listener, optionalArg?: any) {
        const options = getOptions(optionalArg)
        if (!delegatedEvents[type]) {
          delegatedEvents[type] = {
            contexts : [],
      Severity: Minor
      Found in packages/utils/events.ts - About 1 hr to fix

        Avoid deeply nested control flow statements.
        Open

                  if (!listeners.length) {
                    delegated.selectors.splice(index, 1)
                    delegated.contexts.splice(index, 1)
                    delegated.listeners.splice(index, 1)
        
        
        Severity: Major
        Found in packages/utils/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/utils/events.ts - About 45 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/utils/events.ts - About 35 mins to fix

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

              function removeDelegate (selector, context, type, listener?, optionalArg?: any) {
              Severity: Minor
              Found in packages/utils/events.ts - About 35 mins to fix

                Function addDelegate has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                function addDelegate (selector: string, context: Node, type: string, listener: Listener, optionalArg?: any) {
                  const options = getOptions(optionalArg)
                  if (!delegatedEvents[type]) {
                    delegatedEvents[type] = {
                      contexts : [],
                Severity: Minor
                Found in packages/utils/events.ts - About 35 mins 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

                There are no issues that match your filters.

                Category
                Status