BookStackApp/BookStack

View on GitHub
resources/js/wysiwyg/lexical/core/nodes/LexicalElementNode.ts

Summary

Maintainability
F
6 days
Test Coverage

File LexicalElementNode.ts has 559 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/nodes/LexicalElementNode.ts - About 1 day to fix

    ElementNode has 50 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export class ElementNode extends LexicalNode {
      ['constructor']!: KlassConstructor<typeof ElementNode>;
      /** @internal */
      __first: null | NodeKey;
      /** @internal */
    Severity: Minor
    Found in resources/js/wysiwyg/lexical/core/nodes/LexicalElementNode.ts - About 7 hrs to fix

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

        splice(
          start: number,
          deleteCount: number,
          nodesToInsert: Array<LexicalNode>,
        ): this {
      Severity: Minor
      Found in resources/js/wysiwyg/lexical/core/nodes/LexicalElementNode.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 splice has 110 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        splice(
          start: number,
          deleteCount: number,
          nodesToInsert: Array<LexicalNode>,
        ): this {
      Severity: Major
      Found in resources/js/wysiwyg/lexical/core/nodes/LexicalElementNode.ts - About 4 hrs to fix

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

          select(_anchorOffset?: number, _focusOffset?: number): RangeSelection {
            errorOnReadOnly();
            const selection = $getSelection();
            let anchorOffset = _anchorOffset;
            let focusOffset = _focusOffset;
        Severity: Minor
        Found in resources/js/wysiwyg/lexical/core/nodes/LexicalElementNode.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 select has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          select(_anchorOffset?: number, _focusOffset?: number): RangeSelection {
            errorOnReadOnly();
            const selection = $getSelection();
            let anchorOffset = _anchorOffset;
            let focusOffset = _focusOffset;
        Severity: Minor
        Found in resources/js/wysiwyg/lexical/core/nodes/LexicalElementNode.ts - About 1 hr to fix

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

            getChildAtIndex<T extends LexicalNode>(index: number): null | T {
              const size = this.getChildrenSize();
              let node: null | T;
              let i;
              if (index < size / 2) {
          Severity: Minor
          Found in resources/js/wysiwyg/lexical/core/nodes/LexicalElementNode.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

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

            getFirstDescendant<T extends LexicalNode>(): null | T {
              let node = this.getFirstChild<T>();
              while ($isElementNode(node)) {
                const child = node.getFirstChild<T>();
                if (child === null) {
          resources/js/wysiwyg/lexical/core/nodes/LexicalElementNode.ts on lines 184..194

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

          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

            getLastDescendant<T extends LexicalNode>(): null | T {
              let node = this.getLastChild<T>();
              while ($isElementNode(node)) {
                const child = node.getLastChild<T>();
                if (child === null) {
          resources/js/wysiwyg/lexical/core/nodes/LexicalElementNode.ts on lines 173..183

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

          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

            getLastChild<T extends LexicalNode>(): null | T {
              const self = this.getLatest();
              const lastKey = self.__last;
              return lastKey === null ? null : $getNodeByKey<T>(lastKey);
            }
          resources/js/wysiwyg/lexical/core/nodes/LexicalElementNode.ts on lines 215..219

          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

            getFirstChild<T extends LexicalNode>(): null | T {
              const self = this.getLatest();
              const firstKey = self.__first;
              return firstKey === null ? null : $getNodeByKey<T>(firstKey);
            }
          resources/js/wysiwyg/lexical/core/nodes/LexicalElementNode.ts on lines 227..231

          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

            getFirstChildOrThrow<T extends LexicalNode>(): T {
              const firstChild = this.getFirstChild<T>();
              if (firstChild === null) {
                invariant(false, 'Expected node %s to have a first child.', this.__key);
              }
          resources/js/wysiwyg/lexical/core/nodes/LexicalElementNode.ts on lines 232..238

          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

            getLastChildOrThrow<T extends LexicalNode>(): T {
              const lastChild = this.getLastChild<T>();
              if (lastChild === null) {
                invariant(false, 'Expected node %s to have a last child.', this.__key);
              }
          resources/js/wysiwyg/lexical/core/nodes/LexicalElementNode.ts on lines 220..226

          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

            exportJSON(): SerializedElementNode {
              return {
                children: [],
                direction: this.getDirection(),
                format: this.getFormatType(),
          resources/js/wysiwyg/lexical/core/nodes/LexicalRootNode.ts on lines 108..117

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

          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 (node !== null && i <= index) {
                  if (i === index) {
                    return node;
                  }
                  node = node.getNextSibling();
          Severity: Minor
          Found in resources/js/wysiwyg/lexical/core/nodes/LexicalElementNode.ts and 1 other location - About 50 mins to fix
          resources/js/wysiwyg/lexical/core/nodes/LexicalElementNode.ts on lines 257..263

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

          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 (node !== null && i >= index) {
                if (i === index) {
                  return node;
                }
                node = node.getPreviousSibling();
          Severity: Minor
          Found in resources/js/wysiwyg/lexical/core/nodes/LexicalElementNode.ts and 1 other location - About 50 mins to fix
          resources/js/wysiwyg/lexical/core/nodes/LexicalElementNode.ts on lines 246..252

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

          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

            selectEnd(): RangeSelection {
              const lastNode = this.getLastDescendant();
              return lastNode ? lastNode.selectEnd() : this.select();
            }
          Severity: Minor
          Found in resources/js/wysiwyg/lexical/core/nodes/LexicalElementNode.ts and 1 other location - About 50 mins to fix
          resources/js/wysiwyg/lexical/core/nodes/LexicalElementNode.ts on lines 359..362

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

            selectStart(): RangeSelection {
              const firstNode = this.getFirstDescendant();
              return firstNode ? firstNode.selectStart() : this.select();
            }
          Severity: Minor
          Found in resources/js/wysiwyg/lexical/core/nodes/LexicalElementNode.ts and 1 other location - About 50 mins to fix
          resources/js/wysiwyg/lexical/core/nodes/LexicalElementNode.ts on lines 363..366

          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

          There are no issues that match your filters.

          Category
          Status