File LexicalTableSelectionHelpers.ts
has 1595 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 applyTableHandlers
has 709 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function applyTableHandlers(
tableNode: TableNode,
tableElement: HTMLTableElementWithWithTableSelectionState,
editor: LexicalEditor,
hasTabHandler: boolean,
Function $handleArrowKey
has a Cognitive Complexity of 143 (exceeds 5 allowed). Consider refactoring. Open
function $handleArrowKey(
editor: LexicalEditor,
event: KeyboardEvent,
direction: Direction,
tableNode: TableNode,
- 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 applyTableHandlers
has a Cognitive Complexity of 72 (exceeds 5 allowed). Consider refactoring. Open
export function applyTableHandlers(
tableNode: TableNode,
tableElement: HTMLTableElementWithWithTableSelectionState,
editor: LexicalEditor,
hasTabHandler: boolean,
- 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 $handleArrowKey
has 271 lines of code (exceeds 25 allowed). Consider refactoring. Open
function $handleArrowKey(
editor: LexicalEditor,
event: KeyboardEvent,
direction: Direction,
tableNode: TableNode,
Function selectTableNodeInDirection
has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring. Open
const selectTableNodeInDirection = (
tableObserver: TableObserver,
tableNode: TableNode,
x: number,
y: number,
- 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 getTable
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
export function getTable(tableElement: HTMLElement): TableDOMTable {
const domRows: TableDOMRows = [];
const grid = {
columns: 0,
domRows,
- 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 getTable
has 54 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function getTable(tableElement: HTMLElement): TableDOMTable {
const domRows: TableDOMRows = [];
const grid = {
columns: 0,
domRows,
Function selectTableNodeInDirection
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
const selectTableNodeInDirection = (
tableObserver: TableObserver,
tableNode: TableNode,
x: number,
y: number,
Function deleteTextHandler
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
const deleteTextHandler = (command: LexicalCommand<boolean>) => () => {
const selection = $getSelection();
if (!$isSelectionInTable(selection, tableNode)) {
return false;
Function adjustFocusNodeInDirection
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
const adjustFocusNodeInDirection = (
tableObserver: TableObserver,
tableNode: TableNode,
x: number,
y: number,
- 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 $getTableEdgeCursorPosition
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
function $getTableEdgeCursorPosition(
editor: LexicalEditor,
selection: RangeSelection,
tableNode: TableNode,
) {
Function $deleteCellHandler
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
const $deleteCellHandler = (
event: KeyboardEvent | ClipboardEvent | null,
): boolean => {
const selection = $getSelection();
Function adjustFocusNodeInDirection
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
const adjustFocusNodeInDirection = (
tableObserver: TableObserver,
tableNode: TableNode,
x: number,
y: number,
Function $forEachTableCell
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
export function $forEachTableCell(
grid: TableDOMTable,
cb: (
cell: TableDOMCell,
lexicalNode: 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 $getTableEdgeCursorPosition
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
function $getTableEdgeCursorPosition(
editor: LexicalEditor,
selection: RangeSelection,
tableNode: TableNode,
) {
- 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 deeply nested control flow statements. Open
if (newSelection) {
newSelection.anchor.set(
tableNode.getKey(),
selection.isBackward() ? tableNode.getChildrenSize() : 0,
'element',
Avoid deeply nested control flow statements. Open
if ($isRootOrShadowRoot(focusNode)) {
const selectedNode = selection.getNodes()[0];
if (selectedNode) {
const tableCellNode = $findMatchingParent(
selectedNode,
Avoid deeply nested control flow statements. Open
if (!tableObserver.isSelecting) {
setTimeout(() => {
const {onMouseUp, onMouseMove} = createMouseHandlers();
tableObserver.isSelecting = true;
editorWindow.addEventListener('mouseup', onMouseUp);
Consider simplifying this complex logical expression. Open
} else if ($isRangeSelection(selection)) {
const tableCellNode = $findMatchingParent(
selection.anchor.getNode(),
(n) => $isTableCellNode(n),
);
Consider simplifying this complex logical expression. Open
if (
selection &&
!selection.is(prevSelection) &&
($isTableSelection(selection) || $isTableSelection(prevSelection)) &&
tableObserver.tableSelection &&
Function $handleArrowKey
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
editor: LexicalEditor,
event: KeyboardEvent,
direction: Direction,
tableNode: TableNode,
tableObserver: TableObserver,
Function getDOMCellFromTarget
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
export function getDOMCellFromTarget(node: Node): TableDOMCell | null {
let currentNode: ParentNode | Node | null = node;
while (currentNode != null) {
const nodeName = currentNode.nodeName;
- 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 undefined;
Avoid too many return
statements within this function. Open
return true;
Avoid too many return
statements within this function. Open
return true;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return 'last';
Avoid too many return
statements within this function. Open
return undefined;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return $handleTableExit(event, anchorNode, tableNode, direction);
Avoid too many return
statements within this function. Open
return true;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return true;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return adjustFocusNodeInDirection(
tableObserver,
tableNodeFromSelection,
cords.x,
cords.y,
Avoid too many return
statements within this function. Open
return 'first';
Avoid too many return
statements within this function. Open
return true;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return selectTableNodeInDirection(
tableObserver,
tableNode,
cords.x,
cords.y,
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return true;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return true;
Avoid too many return
statements within this function. Open
return $handleArrowKey(
editor,
event,
direction,
anchorCellTable,
Avoid too many return
statements within this function. Open
return false;
Function $handleTableExit
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
function $handleTableExit(
event: KeyboardEvent,
anchorNode: LexicalNode,
tableNode: TableNode,
direction: 'backward' | 'forward',
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
if ($isTableSelection(selection)) {
tableObserver.formatCells(payload);
return true;
} else if ($isRangeSelection(selection)) {
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if ($isTableSelection(selection)) {
if (event) {
event.preventDefault();
event.stopPropagation();
}
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
export function $findTableNode(node: LexicalNode): null | TableNode {
const tableNode = $findMatchingParent(node, $isTableNode);
return $isTableNode(tableNode) ? tableNode : null;
}
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
export function $findCellNode(node: LexicalNode): null | TableCellNode {
const cellNode = $findMatchingParent(node, $isTableCellNode);
return $isTableCellNode(cellNode) ? cellNode : null;
}
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
export const getDOMSelection = (
targetWindow: Window | null,
): Selection | null =>
CAN_USE_DOM ? (targetWindow || window).getSelection() : null;
- Read upRead up
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 46.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76