BookStackApp/BookStack

View on GitHub
resources/js/wysiwyg/lexical/list/formatList.ts

Summary

Maintainability
F
3 days
Test Coverage

File formatList.ts has 377 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: Minor
Found in resources/js/wysiwyg/lexical/list/formatList.ts - About 5 hrs to fix

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

    export function $handleIndent(listItemNode: ListItemNode): void {
      // go through each node and decide where to move it.
      const removed = new Set<NodeKey>();
    
      if (isNestedListNode(listItemNode) || removed.has(listItemNode.getKey())) {
    Severity: Minor
    Found in resources/js/wysiwyg/lexical/list/formatList.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 insertList has 69 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function insertList(editor: LexicalEditor, listType: ListType): void {
      editor.update(() => {
        const selection = $getSelection();
    
        if (selection !== null) {
    Severity: Major
    Found in resources/js/wysiwyg/lexical/list/formatList.ts - About 2 hrs to fix

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

      export function $handleOutdent(listItemNode: ListItemNode): void {
        // go through each node and decide where to move it.
      
        if (isNestedListNode(listItemNode)) {
          return;
      Severity: Minor
      Found in resources/js/wysiwyg/lexical/list/formatList.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 $handleIndent has 49 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export function $handleIndent(listItemNode: ListItemNode): void {
        // go through each node and decide where to move it.
        const removed = new Set<NodeKey>();
      
        if (isNestedListNode(listItemNode) || removed.has(listItemNode.getKey())) {
      Severity: Minor
      Found in resources/js/wysiwyg/lexical/list/formatList.ts - About 1 hr to fix

        Function $handleListInsertParagraph has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export function $handleListInsertParagraph(): boolean {
          const selection = $getSelection();
        
          if (!$isRangeSelection(selection) || !selection.isCollapsed()) {
            return false;
        Severity: Minor
        Found in resources/js/wysiwyg/lexical/list/formatList.ts - About 1 hr to fix

          Function $handleOutdent has 42 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export function $handleOutdent(listItemNode: ListItemNode): void {
            // go through each node and decide where to move it.
          
            if (isNestedListNode(listItemNode)) {
              return;
          Severity: Minor
          Found in resources/js/wysiwyg/lexical/list/formatList.ts - About 1 hr to fix

            Function removeList has 39 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export function removeList(editor: LexicalEditor): void {
              editor.update(() => {
                const selection = $getSelection();
            
                if ($isRangeSelection(selection)) {
            Severity: Minor
            Found in resources/js/wysiwyg/lexical/list/formatList.ts - About 1 hr to fix

              Function updateChildrenListItemValue has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

              export function updateChildrenListItemValue(list: ListNode): void {
                const isNotChecklist = list.getListType() !== 'check';
                let value = list.getStart();
                for (const child of list.getChildren()) {
                  if ($isListItemNode(child)) {
              Severity: Minor
              Found in resources/js/wysiwyg/lexical/list/formatList.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 $createListOrMerge has 33 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function $createListOrMerge(node: ElementNode, listType: ListType): ListNode {
                if ($isListNode(node)) {
                  return node;
                }
              
              
              Severity: Minor
              Found in resources/js/wysiwyg/lexical/list/formatList.ts - About 1 hr to fix

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

                export function $handleListInsertParagraph(): boolean {
                  const selection = $getSelection();
                
                  if (!$isRangeSelection(selection) || !selection.isCollapsed()) {
                    return false;
                Severity: Minor
                Found in resources/js/wysiwyg/lexical/list/formatList.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

                Avoid deeply nested control flow statements.
                Open

                            if ($isElementNode(anchorNode)) {
                              listItem.setFormat(anchorNode.getFormatType());
                              listItem.setIndent(anchorNode.getIndent());
                            }
                Severity: Major
                Found in resources/js/wysiwyg/lexical/list/formatList.ts - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                              if (listItemNode != null) {
                                listNodes.add($getTopListNode(listItemNode));
                              }
                  Severity: Major
                  Found in resources/js/wysiwyg/lexical/list/formatList.ts - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                              } else if ($isListItemNode(anchorNode)) {
                                const parent = anchorNode.getParentOrThrow();
                                append(list, parent.getChildren());
                                parent.replace(list);
                              }
                    Severity: Major
                    Found in resources/js/wysiwyg/lexical/list/formatList.ts - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                            if (previousSibling) {
                              previousSibling.insertAfter(newListItem);
                            } else if (nextSibling) {
                              nextSibling.insertBefore(newListItem);
                            } else {
                      Severity: Major
                      Found in resources/js/wysiwyg/lexical/list/formatList.ts - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                    if ($isListNode(parent)) {
                                      if (!handled.has(parentKey)) {
                                        const newListNode = $createListNode(listType);
                                        append(newListNode, parent.getChildren());
                                        parent.replace(newListNode);
                        Severity: Major
                        Found in resources/js/wysiwyg/lexical/list/formatList.ts - About 45 mins to fix

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

                          function $createListOrMerge(node: ElementNode, listType: ListType): ListNode {
                            if ($isListNode(node)) {
                              return node;
                            }
                          
                          
                          Severity: Minor
                          Found in resources/js/wysiwyg/lexical/list/formatList.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

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

                            if (
                              listItem1 &&
                              listItem2 &&
                              isNestedListNode(listItem1) &&
                              isNestedListNode(listItem2)
                          Severity: Major
                          Found in resources/js/wysiwyg/lexical/list/formatList.ts and 1 other location - About 1 hr to fix
                          resources/js/wysiwyg/lexical/list/LexicalListItemNode.ts on lines 247..255

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

                          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