BookStackApp/BookStack

View on GitHub
resources/js/wysiwyg/lexical/yjs/CollabElementNode.ts

Summary

Maintainability
F
1 wk
Test Coverage

File CollabElementNode.ts has 558 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/yjs/CollabElementNode.ts - About 1 day to fix

    Function syncChildrenFromYjs has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring.
    Open

      syncChildrenFromYjs(binding: Binding): void {
        // Now diff the children of the collab node with that of our existing Lexical node.
        const lexicalNode = this.getNode();
        invariant(
          lexicalNode !== null,
    Severity: Minor
    Found in resources/js/wysiwyg/lexical/yjs/CollabElementNode.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 applyChildrenYjsDelta has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
    Open

      applyChildrenYjsDelta(
        binding: Binding,
        deltas: Array<{
          insert?: string | object | AbstractType<unknown>;
          delete?: number;
    Severity: Minor
    Found in resources/js/wysiwyg/lexical/yjs/CollabElementNode.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 syncChildrenFromYjs has 117 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      syncChildrenFromYjs(binding: Binding): void {
        // Now diff the children of the collab node with that of our existing Lexical node.
        const lexicalNode = this.getNode();
        invariant(
          lexicalNode !== null,
    Severity: Major
    Found in resources/js/wysiwyg/lexical/yjs/CollabElementNode.ts - About 4 hrs to fix

      Function syncChildrenFromLexical has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
      Open

        syncChildrenFromLexical(
          binding: Binding,
          nextLexicalNode: ElementNode,
          prevNodeMap: null | NodeMap,
          dirtyElements: null | Map<NodeKey, IntentionallyMarkedAsDirtyElement>,
      Severity: Minor
      Found in resources/js/wysiwyg/lexical/yjs/CollabElementNode.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 applyChildrenYjsDelta has 77 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        applyChildrenYjsDelta(
          binding: Binding,
          deltas: Array<{
            insert?: string | object | AbstractType<unknown>;
            delete?: number;
      Severity: Major
      Found in resources/js/wysiwyg/lexical/yjs/CollabElementNode.ts - About 3 hrs to fix

        Function syncChildrenFromLexical has 77 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          syncChildrenFromLexical(
            binding: Binding,
            nextLexicalNode: ElementNode,
            prevNodeMap: null | NodeMap,
            dirtyElements: null | Map<NodeKey, IntentionallyMarkedAsDirtyElement>,
        Severity: Major
        Found in resources/js/wysiwyg/lexical/yjs/CollabElementNode.ts - About 3 hrs to fix

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

            splice(
              binding: Binding,
              index: number,
              delCount: number,
              collabNode?:
          Severity: Minor
          Found in resources/js/wysiwyg/lexical/yjs/CollabElementNode.ts - About 1 hr to fix

            Function splice has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

              splice(
                binding: Binding,
                index: number,
                delCount: number,
                collabNode?:
            Severity: Minor
            Found in resources/js/wysiwyg/lexical/yjs/CollabElementNode.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 _syncChildFromLexical has 37 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              _syncChildFromLexical(
                binding: Binding,
                index: number,
                key: NodeKey,
                prevNodeMap: null | NodeMap,
            Severity: Minor
            Found in resources/js/wysiwyg/lexical/yjs/CollabElementNode.ts - About 1 hr to fix

              Avoid deeply nested control flow statements.
              Open

                          if (childKey !== '') {
                            collabKeys.add(childKey);
                          }
              Severity: Major
              Found in resources/js/wysiwyg/lexical/yjs/CollabElementNode.ts - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                            if (
                              offset === 0 &&
                              delCount === 1 &&
                              nodeIndex > 0 &&
                              prevCollabNode instanceof CollabTextNode &&
                Severity: Major
                Found in resources/js/wysiwyg/lexical/yjs/CollabElementNode.ts - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                            if (node instanceof CollabTextNode) {
                              node._text = spliceString(node._text, offset, 0, insertDelta);
                            } else {
                              // TODO: maybe we can improve this by keeping around a redundant
                              // text node map, rather than removing all the text nodes, so there
                  Severity: Major
                  Found in resources/js/wysiwyg/lexical/yjs/CollabElementNode.ts - About 45 mins to fix

                    Consider simplifying this complex logical expression.
                    Open

                                if (
                                  offset === 0 &&
                                  delCount === 1 &&
                                  nodeIndex > 0 &&
                                  prevCollabNode instanceof CollabTextNode &&
                    Severity: Major
                    Found in resources/js/wysiwyg/lexical/yjs/CollabElementNode.ts - About 40 mins to fix

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

                        append(
                          collabNode:
                            | CollabElementNode
                            | CollabDecoratorNode
                            | CollabTextNode
                      Severity: Minor
                      Found in resources/js/wysiwyg/lexical/yjs/CollabElementNode.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

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

                          if (collabNode instanceof CollabElementNode) {
                            xmlText.insertEmbed(offset, collabNode._xmlText);
                          } else if (collabNode instanceof CollabTextNode) {
                            const map = collabNode._map;
                      
                      
                      Severity: Major
                      Found in resources/js/wysiwyg/lexical/yjs/CollabElementNode.ts and 1 other location - About 5 hrs to fix
                      resources/js/wysiwyg/lexical/yjs/CollabElementNode.ts on lines 540..554

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

                      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 (collabNode instanceof CollabElementNode) {
                            xmlText.insertEmbed(offset, collabNode._xmlText);
                          } else if (collabNode instanceof CollabTextNode) {
                            const map = collabNode._map;
                      
                      
                      Severity: Major
                      Found in resources/js/wysiwyg/lexical/yjs/CollabElementNode.ts and 1 other location - About 5 hrs to fix
                      resources/js/wysiwyg/lexical/yjs/CollabElementNode.ts on lines 592..606

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

                      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

                        getPrevNode(nodeMap: null | NodeMap): null | ElementNode {
                          if (nodeMap === null) {
                            return null;
                          }
                      
                      
                      Severity: Major
                      Found in resources/js/wysiwyg/lexical/yjs/CollabElementNode.ts and 1 other location - About 1 hr to fix
                      resources/js/wysiwyg/lexical/yjs/CollabTextNode.ts on lines 68..75

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

                      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

                                if (childCollabNode instanceof CollabElementNode) {
                                  const xmlText = childCollabNode._xmlText;
                                  childCollabNode.syncPropertiesFromYjs(binding, null);
                                  childCollabNode.applyChildrenYjsDelta(binding, xmlText.toDelta());
                                  childCollabNode.syncChildrenFromYjs(binding);
                      Severity: Major
                      Found in resources/js/wysiwyg/lexical/yjs/CollabElementNode.ts and 1 other location - About 1 hr to fix
                      resources/js/wysiwyg/lexical/yjs/Utils.ts on lines 241..250

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

                      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 (nextSibling !== null) {
                                  const writableNextSibling = nextSibling.getWritable();
                                  writableNextSibling.__prev = childKey;
                                  lexicalChildNode.__next = writableNextSibling.__key;
                                }
                      Severity: Minor
                      Found in resources/js/wysiwyg/lexical/yjs/CollabElementNode.ts and 1 other location - About 50 mins to fix
                      resources/js/wysiwyg/lexical/yjs/CollabElementNode.ts on lines 337..341

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

                      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 (nextSibling !== null) {
                                  const writableNextSibling = nextSibling.getWritable();
                                  writableNextSibling.__prev = childKey;
                                  lexicalChildNode.__next = writableNextSibling.__key;
                                }
                      Severity: Minor
                      Found in resources/js/wysiwyg/lexical/yjs/CollabElementNode.ts and 1 other location - About 50 mins to fix
                      resources/js/wysiwyg/lexical/yjs/CollabElementNode.ts on lines 327..331

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

                      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 3 locations. Consider refactoring.
                      Open

                        getNode(): null | ElementNode {
                          const node = $getNodeByKey(this._key);
                          return $isElementNode(node) ? node : null;
                        }
                      Severity: Minor
                      Found in resources/js/wysiwyg/lexical/yjs/CollabElementNode.ts and 2 other locations - About 30 mins to fix
                      resources/js/wysiwyg/lexical/yjs/CollabLineBreakNode.ts on lines 29..32
                      resources/js/wysiwyg/lexical/yjs/CollabTextNode.ts on lines 77..80

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

                      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