BookStackApp/BookStack

View on GitHub
resources/js/wysiwyg/lexical/core/LexicalReconciler.ts

Summary

Maintainability
F
1 wk
Test Coverage

File LexicalReconciler.ts has 678 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
Severity: Major
Found in resources/js/wysiwyg/lexical/core/LexicalReconciler.ts - About 1 day to fix

    Function $reconcileChildren has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
    Open

    function $reconcileChildren(
      prevElement: ElementNode,
      nextElement: ElementNode,
      dom: HTMLElement,
    ): void {
    Severity: Minor
    Found in resources/js/wysiwyg/lexical/core/LexicalReconciler.ts - About 6 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 $reconcileNodeChildren has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
    Open

    function $reconcileNodeChildren(
      nextElement: ElementNode,
      prevChildren: Array<NodeKey>,
      nextChildren: Array<NodeKey>,
      prevChildrenLength: number,
    Severity: Minor
    Found in resources/js/wysiwyg/lexical/core/LexicalReconciler.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 $reconcileNode has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
    Open

    function $reconcileNode(
      key: NodeKey,
      parentDOM: HTMLElement | null,
    ): HTMLElement {
      const prevNode = activePrevNodeMap.get(key);
    Severity: Minor
    Found in resources/js/wysiwyg/lexical/core/LexicalReconciler.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 $createNode has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

    function $createNode(
      key: NodeKey,
      parentDOM: null | HTMLElement,
      insertDOM: null | Node,
    ): HTMLElement {
    Severity: Minor
    Found in resources/js/wysiwyg/lexical/core/LexicalReconciler.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 $reconcileNode has 88 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function $reconcileNode(
      key: NodeKey,
      parentDOM: HTMLElement | null,
    ): HTMLElement {
      const prevNode = activePrevNodeMap.get(key);
    Severity: Major
    Found in resources/js/wysiwyg/lexical/core/LexicalReconciler.ts - About 3 hrs to fix

      Function $reconcileChildren has 83 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function $reconcileChildren(
        prevElement: ElementNode,
        nextElement: ElementNode,
        dom: HTMLElement,
      ): void {
      Severity: Major
      Found in resources/js/wysiwyg/lexical/core/LexicalReconciler.ts - About 3 hrs to fix

        Function $reconcileNodeChildren has 75 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function $reconcileNodeChildren(
          nextElement: ElementNode,
          prevChildren: Array<NodeKey>,
          nextChildren: Array<NodeKey>,
          prevChildrenLength: number,
        Severity: Major
        Found in resources/js/wysiwyg/lexical/core/LexicalReconciler.ts - About 3 hrs to fix

          Function $createNode has 68 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function $createNode(
            key: NodeKey,
            parentDOM: null | HTMLElement,
            insertDOM: null | Node,
          ): HTMLElement {
          Severity: Major
          Found in resources/js/wysiwyg/lexical/core/LexicalReconciler.ts - About 2 hrs to fix

            Function reconcileElementTerminatingLineBreak has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
            Open

            function reconcileElementTerminatingLineBreak(
              prevElement: null | ElementNode,
              nextElement: ElementNode,
              dom: HTMLElement,
            ): void {
            Severity: Minor
            Found in resources/js/wysiwyg/lexical/core/LexicalReconciler.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 reconcileElementTerminatingLineBreak has 37 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function reconcileElementTerminatingLineBreak(
              prevElement: null | ElementNode,
              nextElement: ElementNode,
              dom: HTMLElement,
            ): void {
            Severity: Minor
            Found in resources/js/wysiwyg/lexical/core/LexicalReconciler.ts - About 1 hr to fix

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

              function $createChildren(
                children: Array<NodeKey>,
                element: ElementNode,
                _startIndex: number,
                endIndex: number,
              Severity: Minor
              Found in resources/js/wysiwyg/lexical/core/LexicalReconciler.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 $reconcileRoot has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              export function $reconcileRoot(
                prevEditorState: EditorState,
                nextEditorState: EditorState,
                editor: LexicalEditor,
                dirtyType: 0 | 1 | 2,
              Severity: Minor
              Found in resources/js/wysiwyg/lexical/core/LexicalReconciler.ts - About 1 hr to fix

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

                  nextElement: ElementNode,
                  prevChildren: Array<NodeKey>,
                  nextChildren: Array<NodeKey>,
                  prevChildrenLength: number,
                  nextChildrenLength: number,
                Severity: Minor
                Found in resources/js/wysiwyg/lexical/core/LexicalReconciler.ts - About 45 mins to fix

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

                    children: Array<NodeKey>,
                    element: ElementNode,
                    _startIndex: number,
                    endIndex: number,
                    dom: null | HTMLElement,
                  Severity: Minor
                  Found in resources/js/wysiwyg/lexical/core/LexicalReconciler.ts - About 45 mins to fix

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

                      prevEditorState: EditorState,
                      nextEditorState: EditorState,
                      editor: LexicalEditor,
                      dirtyType: 0 | 1 | 2,
                      dirtyElements: Map<NodeKey, IntentionallyMarkedAsDirtyElement>,
                    Severity: Minor
                    Found in resources/js/wysiwyg/lexical/core/LexicalReconciler.ts - About 45 mins to fix

                      Function setElementIndent has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                      Open

                      function setElementIndent(dom: HTMLElement, indent: number): void {
                        const indentClassName = activeEditorConfig.theme.indent;
                      
                        if (typeof indentClassName === 'string') {
                          const elementHasClassName = dom.classList.contains(indentClassName);
                      Severity: Minor
                      Found in resources/js/wysiwyg/lexical/core/LexicalReconciler.ts - About 45 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

                      Avoid deeply nested control flow statements.
                      Open

                              if (canUseFastPath) {
                                // Fast path for removing DOM nodes
                                dom.textContent = '';
                              }
                      Severity: Major
                      Found in resources/js/wysiwyg/lexical/core/LexicalReconciler.ts - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                  if (siblingDOM != null) {
                                    dom.insertBefore(childDOM, siblingDOM);
                                  } else {
                                    dom.appendChild(childDOM);
                                  }
                        Severity: Major
                        Found in resources/js/wysiwyg/lexical/core/LexicalReconciler.ts - About 45 mins to fix

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

                          function setElementFormat(dom: HTMLElement, format: number): void {
                            const domStyle = dom.style;
                          
                            if (format === 0) {
                              setTextAlign(domStyle, '');
                          Severity: Minor
                          Found in resources/js/wysiwyg/lexical/core/LexicalReconciler.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

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

                          function destroyNode(key: NodeKey, parentDOM: null | HTMLElement): void {
                            const node = activePrevNodeMap.get(key);
                          
                            if (parentDOM !== null) {
                              const dom = getPrevElementByKeyOrThrow(key);
                          Severity: Minor
                          Found in resources/js/wysiwyg/lexical/core/LexicalReconciler.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 (node !== null && $isTextNode(node)) {
                                if (subTreeTextFormat === null) {
                                  subTreeTextFormat = node.getFormat();
                                }
                                if (subTreeTextStyle === '') {
                          Severity: Major
                          Found in resources/js/wysiwyg/lexical/core/LexicalReconciler.ts and 1 other location - About 1 hr to fix
                          resources/js/wysiwyg/lexical/core/LexicalReconciler.ts on lines 719..726

                          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

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

                              if (node !== null && $isTextNode(node)) {
                                if (subTreeTextFormat === null) {
                                  subTreeTextFormat = node.getFormat();
                                }
                                if (subTreeTextStyle === '') {
                          Severity: Major
                          Found in resources/js/wysiwyg/lexical/core/LexicalReconciler.ts and 1 other location - About 1 hr to fix
                          resources/js/wysiwyg/lexical/core/LexicalReconciler.ts on lines 272..279

                          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