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.
Function registerHistory
has 86 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function registerHistory(
editor: LexicalEditor,
historyState: HistoryState,
delay: number,
): () => void {
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>,
Function createMergeActionGetter
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
function createMergeActionGetter(
editor: LexicalEditor,
delay: number,
): (
prevEditorState: null | EditorState,
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>,
- Read upRead up
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 {
- Read upRead up
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 =
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> {
- Read upRead up
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) {
- Read upRead up
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) &&
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,
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;
- Read upRead up
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;
Avoid too many return
statements within this function. Open
return INSERT_CHARACTER_AFTER_SELECTION;
Avoid too many return
statements within this function. Open
return OTHER;
Avoid too many return
statements within this function. Open
return HISTORY_PUSH;
Avoid too many return
statements within this function. Open
return OTHER;
Avoid too many return
statements within this function. Open
return INSERT_CHARACTER_AFTER_SELECTION;
Avoid too many return
statements within this function. Open
return DELETE_CHARACTER_AFTER_SELECTION;
Avoid too many return
statements within this function. Open
return OTHER;
Avoid too many return
statements within this function. Open
return HISTORY_MERGE;
Avoid too many return
statements within this function. Open
return DELETE_CHARACTER_BEFORE_SELECTION;
Avoid too many return
statements within this function. Open
return OTHER;
Avoid too many return
statements within this function. Open
return HISTORY_MERGE;