BookStackApp/BookStack

View on GitHub
resources/js/wysiwyg/lexical/history/index.ts

Summary

Maintainability
F
3 days
Test Coverage

File index.ts has 395 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/history/index.ts - About 5 hrs to fix

    Function registerHistory has 86 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function registerHistory(
      editor: LexicalEditor,
      historyState: HistoryState,
      delay: number,
    ): () => void {
    Severity: Major
    Found in resources/js/wysiwyg/lexical/history/index.ts - About 3 hrs to fix

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

      function getChangeType(
        prevEditorState: null | EditorState,
        nextEditorState: EditorState,
        dirtyLeavesSet: Set<NodeKey>,
        dirtyElementsSet: Map<NodeKey, IntentionallyMarkedAsDirtyElement>,
      Severity: Major
      Found in resources/js/wysiwyg/lexical/history/index.ts - About 3 hrs to fix

        Function createMergeActionGetter has 66 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function createMergeActionGetter(
          editor: LexicalEditor,
          delay: number,
        ): (
          prevEditorState: null | EditorState,
        Severity: Major
        Found in resources/js/wysiwyg/lexical/history/index.ts - About 2 hrs to fix

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

          function getChangeType(
            prevEditorState: null | EditorState,
            nextEditorState: EditorState,
            dirtyLeavesSet: Set<NodeKey>,
            dirtyElementsSet: Map<NodeKey, IntentionallyMarkedAsDirtyElement>,
          Severity: Minor
          Found in resources/js/wysiwyg/lexical/history/index.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 registerHistory has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

          export function registerHistory(
            editor: LexicalEditor,
            historyState: HistoryState,
            delay: number,
          ): () => void {
          Severity: Minor
          Found in resources/js/wysiwyg/lexical/history/index.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 mergeAction has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              const mergeAction = (() => {
                const isSameEditor =
                  currentHistoryEntry === null || currentHistoryEntry.editor === editor;
                const shouldPushHistory = tags.has('history-push');
                const shouldMergeHistory =
          Severity: Minor
          Found in resources/js/wysiwyg/lexical/history/index.ts - About 1 hr to fix

            Function getDirtyNodes has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

            function getDirtyNodes(
              editorState: EditorState,
              dirtyLeaves: Set<NodeKey>,
              dirtyElements: Map<NodeKey, IntentionallyMarkedAsDirtyElement>,
            ): Array<LexicalNode> {
            Severity: Minor
            Found in resources/js/wysiwyg/lexical/history/index.ts - About 55 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 redo has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

            function redo(editor: LexicalEditor, historyState: HistoryState): void {
              const redoStack = historyState.redoStack;
              const undoStack = historyState.undoStack;
            
              if (redoStack.length !== 0) {
            Severity: Minor
            Found in resources/js/wysiwyg/lexical/history/index.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

            Consider simplifying this complex logical expression.
            Open

                if (
                  nextAnchorNode &&
                  prevAnchorNode &&
                  !prevEditorState._nodeMap.has(nextAnchorNode.__key) &&
                  $isTextNode(nextAnchorNode) &&
            Severity: Major
            Found in resources/js/wysiwyg/lexical/history/index.ts - About 40 mins to fix

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

                prevEditorState: null | EditorState,
                nextEditorState: EditorState,
                dirtyLeavesSet: Set<NodeKey>,
                dirtyElementsSet: Map<NodeKey, IntentionallyMarkedAsDirtyElement>,
                isComposing: boolean,
              Severity: Minor
              Found in resources/js/wysiwyg/lexical/history/index.ts - About 35 mins to fix

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

                function undo(editor: LexicalEditor, historyState: HistoryState): void {
                  const redoStack = historyState.redoStack;
                  const undoStack = historyState.undoStack;
                  const undoStackLength = undoStack.length;
                
                
                Severity: Minor
                Found in resources/js/wysiwyg/lexical/history/index.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

                Avoid too many return statements within this function.
                Open

                    return OTHER;
                Severity: Major
                Found in resources/js/wysiwyg/lexical/history/index.ts - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                        return INSERT_CHARACTER_AFTER_SELECTION;
                  Severity: Major
                  Found in resources/js/wysiwyg/lexical/history/index.ts - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                        return OTHER;
                    Severity: Major
                    Found in resources/js/wysiwyg/lexical/history/index.ts - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                            return HISTORY_PUSH;
                      Severity: Major
                      Found in resources/js/wysiwyg/lexical/history/index.ts - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                            return OTHER;
                        Severity: Major
                        Found in resources/js/wysiwyg/lexical/history/index.ts - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                              return INSERT_CHARACTER_AFTER_SELECTION;
                          Severity: Major
                          Found in resources/js/wysiwyg/lexical/history/index.ts - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                return DELETE_CHARACTER_AFTER_SELECTION;
                            Severity: Major
                            Found in resources/js/wysiwyg/lexical/history/index.ts - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                  return OTHER;
                              Severity: Major
                              Found in resources/js/wysiwyg/lexical/history/index.ts - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                        return HISTORY_MERGE;
                                Severity: Major
                                Found in resources/js/wysiwyg/lexical/history/index.ts - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                      return DELETE_CHARACTER_BEFORE_SELECTION;
                                  Severity: Major
                                  Found in resources/js/wysiwyg/lexical/history/index.ts - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                      return OTHER;
                                    Severity: Major
                                    Found in resources/js/wysiwyg/lexical/history/index.ts - About 30 mins to fix

                                      Avoid too many return statements within this function.
                                      Open

                                                return HISTORY_MERGE;
                                      Severity: Major
                                      Found in resources/js/wysiwyg/lexical/history/index.ts - About 30 mins to fix

                                        There are no issues that match your filters.

                                        Category
                                        Status