packages/nerv/src/vdom/patch.ts

Summary

Maintainability
F
1 wk
Test Coverage

Function patchKeyedChildren has a Cognitive Complexity of 138 (exceeds 5 allowed). Consider refactoring.
Open

function patchKeyedChildren (
  a: VNode[],
  b: VNode[],
  dom: Element,
  context,
Severity: Minor
Found in packages/nerv/src/vdom/patch.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

File patch.ts has 612 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* tslint:disable: no-empty*/
import {
  isString,
  isAttrAnEvent,
  isNumber,
Severity: Major
Found in packages/nerv/src/vdom/patch.ts - About 1 day to fix

    Function patchProp has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
    Open

    export function patchProp (
      domNode: Element,
      prop: string,
      lastValue,
      nextValue,
    Severity: Minor
    Found in packages/nerv/src/vdom/patch.ts - 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

    Function patchKeyedChildren has 167 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function patchKeyedChildren (
      a: VNode[],
      b: VNode[],
      dom: Element,
      context,
    Severity: Major
    Found in packages/nerv/src/vdom/patch.ts - About 6 hrs to fix

      Function patch has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
      Open

      export function patch (
        lastVnode,
        nextVnode,
        parentNode: Element,
        context: object,
      Severity: Minor
      Found in packages/nerv/src/vdom/patch.ts - About 5 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 patch has 65 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export function patch (
        lastVnode,
        nextVnode,
        parentNode: Element,
        context: object,
      Severity: Major
      Found in packages/nerv/src/vdom/patch.ts - About 2 hrs to fix

        Function patchProp has 57 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export function patchProp (
          domNode: Element,
          prop: string,
          lastValue,
          nextValue,
        Severity: Major
        Found in packages/nerv/src/vdom/patch.ts - About 2 hrs to fix

          Function lis has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

          function lis (a: number[]): number[] {
            const p = a.slice()
            const result: number[] = []
            result.push(0)
            let u: number
          Severity: Minor
          Found in packages/nerv/src/vdom/patch.ts - About 2 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 patchStyle has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

          function patchStyle (lastAttrValue: CSSStyleSheet, nextAttrValue: CSSStyleSheet, dom: HTMLElement) {
            const domStyle = dom.style
            let style
            let value
          
          
          Severity: Minor
          Found in packages/nerv/src/vdom/patch.ts - About 2 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 patchNonKeyedChildren has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

          function patchNonKeyedChildren (
            parentDom: Element,
            lastChildren,
            nextChildren,
            context: object,
          Severity: Minor
          Found in packages/nerv/src/vdom/patch.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 lis has 39 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function lis (a: number[]): number[] {
            const p = a.slice()
            const result: number[] = []
            result.push(0)
            let u: number
          Severity: Minor
          Found in packages/nerv/src/vdom/patch.ts - About 1 hr to fix

            Function patchArrayChildren has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function patchArrayChildren (
              parentDom: Element,
              lastChildren,
              nextChildren,
              context: object,
            Severity: Minor
            Found in packages/nerv/src/vdom/patch.ts - About 1 hr to fix

              Function patchArrayChildren has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

              function patchArrayChildren (
                parentDom: Element,
                lastChildren,
                nextChildren,
                context: object,
              Severity: Minor
              Found in packages/nerv/src/vdom/patch.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 patchNonKeyedChildren has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function patchNonKeyedChildren (
                parentDom: Element,
                lastChildren,
                nextChildren,
                context: object,
              Severity: Minor
              Found in packages/nerv/src/vdom/patch.ts - About 1 hr to fix

                Function patchProps has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                function patchProps (
                  domNode: Element,
                  nextProps: Props,
                  previousProps: Props,
                  lastVnode: VNode,
                Severity: Minor
                Found in packages/nerv/src/vdom/patch.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 patchNonKeyedChildren has 7 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                  parentDom: Element,
                  lastChildren,
                  nextChildren,
                  context: object,
                  isSvg: boolean,
                Severity: Major
                Found in packages/nerv/src/vdom/patch.ts - About 50 mins to fix

                  Function patchKeyedChildren has 7 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                    a: VNode[],
                    b: VNode[],
                    dom: Element,
                    context,
                    isSvg: boolean,
                  Severity: Major
                  Found in packages/nerv/src/vdom/patch.ts - About 50 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                            if (patched < bLeft) {
                              for (j = bStart; j <= bEnd; j++) {
                                bNode = b[j]
                                if (aNode.key === bNode.key) {
                                  sources[j - bStart] = i
                    Severity: Major
                    Found in packages/nerv/src/vdom/patch.ts - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                              if (patched < bLeft) {
                                j = keyIndex.get(aNode.key)
                      
                                if (j !== undefined) {
                                  bNode = b[j]
                      Severity: Major
                      Found in packages/nerv/src/vdom/patch.ts - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                              if (isSvg && namespace) {
                                if (nextValue) {
                                  domNode.setAttributeNS(namespace, prop, nextValue)
                                } else {
                                  const colonPosition = prop.indexOf(':')
                        Severity: Major
                        Found in packages/nerv/src/vdom/patch.ts - About 45 mins to fix

                          Function patchProp has 6 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                            domNode: Element,
                            prop: string,
                            lastValue,
                            nextValue,
                            lastVnode: VNode | null,
                          Severity: Minor
                          Found in packages/nerv/src/vdom/patch.ts - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                  } else if (patched !== bLeft) {
                                    for (i = bLeft - 1; i >= 0; i--) {
                                      if (sources[i] === -1) {
                                        pos = i + bStart
                                        node = b[pos]
                            Severity: Major
                            Found in packages/nerv/src/vdom/patch.ts - About 45 mins to fix

                              Avoid deeply nested control flow statements.
                              Open

                                      for (i = bLeft - 1; i >= 0; i--) {
                                        if (sources[i] === -1) {
                                          pos = i + bStart
                                          node = b[pos]
                                          nextPos = pos + 1
                              Severity: Major
                              Found in packages/nerv/src/vdom/patch.ts - About 45 mins to fix

                                Avoid deeply nested control flow statements.
                                Open

                                        if (aNode !== null) {
                                          unmount(aNode, dom)
                                          i--
                                        }
                                Severity: Major
                                Found in packages/nerv/src/vdom/patch.ts - About 45 mins to fix

                                  Avoid deeply nested control flow statements.
                                  Open

                                        if (lastDom != null) {
                                          parentNode.replaceChild(newDom, lastDom)
                                        } else {
                                          parentNode.appendChild(newDom)
                                        }
                                  Severity: Major
                                  Found in packages/nerv/src/vdom/patch.ts - About 45 mins to fix

                                    Avoid deeply nested control flow statements.
                                    Open

                                              if (
                                                isValidElement(lastVnode) &&
                                                lastVnode.children !== EMPTY_CHILDREN
                                              ) {
                                                unmountChildren(lastVnode.children)
                                    Severity: Major
                                    Found in packages/nerv/src/vdom/patch.ts - About 45 mins to fix

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

                                        lastVnode,
                                        nextVnode,
                                        parentNode: Element,
                                        context: object,
                                        isSvg?: boolean
                                      Severity: Minor
                                      Found in packages/nerv/src/vdom/patch.ts - About 35 mins to fix

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

                                          parentDom: Element,
                                          lastChildren,
                                          nextChildren,
                                          context: object,
                                          isSvg: boolean
                                        Severity: Minor
                                        Found in packages/nerv/src/vdom/patch.ts - About 35 mins to fix

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

                                            domNode: Element,
                                            nextProps: Props,
                                            previousProps: Props,
                                            lastVnode: VNode,
                                            isSvg?: boolean
                                          Severity: Minor
                                          Found in packages/nerv/src/vdom/patch.ts - About 35 mins to fix

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

                                              parentDom: Element,
                                              lastChildren,
                                              nextChildren,
                                              context: object,
                                              isSvg: boolean
                                            Severity: Minor
                                            Found in packages/nerv/src/vdom/patch.ts - About 35 mins to fix

                                              Function setStyle has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                              Open

                                              function setStyle (domStyle, style, value) {
                                                if (isNullOrUndef(value) || (isNumber(value) && isNaN(value))) {
                                                  domStyle[style] = ''
                                                  return
                                                }
                                              Severity: Minor
                                              Found in packages/nerv/src/vdom/patch.ts - About 25 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

                                              Identical blocks of code found in 2 locations. Consider refactoring.
                                              Open

                                                        if (sources[i] === -1) {
                                                          pos = i + bStart
                                                          node = b[pos]
                                                          nextPos = pos + 1
                                                          attachNewNode(
                                              Severity: Major
                                              Found in packages/nerv/src/vdom/patch.ts and 1 other location - About 1 hr to fix
                                              packages/nerv/src/vdom/patch.ts on lines 393..402

                                              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 70.

                                              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

                                              Further Reading

                                              Identical blocks of code found in 2 locations. Consider refactoring.
                                              Open

                                                        if (sources[i] === -1) {
                                                          pos = i + bStart
                                                          node = b[pos]
                                                          nextPos = pos + 1
                                                          attachNewNode(
                                              Severity: Major
                                              Found in packages/nerv/src/vdom/patch.ts and 1 other location - About 1 hr to fix
                                              packages/nerv/src/vdom/patch.ts on lines 367..389

                                              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 70.

                                              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

                                              Further Reading

                                              Similar blocks of code found in 2 locations. Consider refactoring.
                                              Open

                                                  while (aStartNode.key === bStartNode.key) {
                                                    patch(aStartNode, bStartNode, dom, context, isSvg)
                                                    aStart++
                                                    bStart++
                                                    if (aStart > aEnd || bStart > bEnd) {
                                              Severity: Major
                                              Found in packages/nerv/src/vdom/patch.ts and 1 other location - About 1 hr to fix
                                              packages/nerv/src/vdom/patch.ts on lines 256..265

                                              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 69.

                                              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

                                              Further Reading

                                              Similar blocks of code found in 2 locations. Consider refactoring.
                                              Open

                                                  while (aEndNode.key === bEndNode.key) {
                                                    patch(aEndNode, bEndNode, dom, context, isSvg)
                                                    aEnd--
                                                    bEnd--
                                                    if (aStart > aEnd || bStart > bEnd) {
                                              Severity: Major
                                              Found in packages/nerv/src/vdom/patch.ts and 1 other location - About 1 hr to fix
                                              packages/nerv/src/vdom/patch.ts on lines 244..253

                                              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 69.

                                              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

                                              Further Reading

                                              There are no issues that match your filters.

                                              Category
                                              Status