app/javascript/components/UI/rich-text/RichInputElement.js
Function RichInputElement
has a Cognitive Complexity of 241 (exceeds 5 allowed). Consider refactoring. Open
Open
const RichInputElement = ({ richText = '',
listUsers: listAllUsers,
setChosenUsers = ()=>{},
onSubmit ,
onClose,
- 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 handleKeyDown
has 216 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
const handleKeyDown = event => {
event.preventDefault()
const selectedValue = window.getSelection().toString();
const text = element.textContent
const cursorPos = Cursor.getCurrentCursorPosition(element, initCoordinates)
File RichInputElement.js
has 410 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
import React, { useEffect, useRef, useState} from 'react';
import Cursor from "../rich-text/cursor";
import DropDownList from "./DropDownList";
import {userFullName} from "../../helpers/library";
import RichText from "./rich-text";
Function clickEnterTabHandling
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
const clickEnterTabHandling = ( i ) => {
if ( i === undefined ) {
setIsDropdownList(false)
return 0
}
Avoid deeply nested control flow statements. Open
Open
if(userFromNode?.length) {
const filtratedUsersByName = RichText.filtrationByName(userFullName(userFromNode[0]), copyChosenUsers)
setCopyChosenUsers(filtratedUsersByName)
setChosenUsers(filtratedUsersByName)
setFilteredUsers(RichText.sortUsersByFullName([...filteredUsers, userFromNode[0]]))
Avoid deeply nested control flow statements. Open
Open
} else if (listFoundUsers.length) {
//delete user from text, Users, ChosenUsers and put instead of it char
const userToDel = RichText.contentBtwTags(textHTML, cursorPos, END_TAG_AT, 1)
const decrementedNumberChosenUsers = copyChosenUsers.filter(user => userFullName(user) !== userToDel) // delete user from chosenUsers
Avoid deeply nested control flow statements. Open
Open
if (copyChosenUsers.find(user => userFullName(user) === newSearchString))
return 0
Avoid deeply nested control flow statements. Open
Open
if (isBtwSpecialSmb) {
RichText.pasteNodeToHTMLobj( MARKER, textHTML, cursorPos, setTextHTML, setCaret, TAG_AT.slice(0, -1), END_TAG_AT )
setIsDropdownList(true)
setCoordinates(cursorPos.coordinates)
return 0
Avoid deeply nested control flow statements. Open
Open
if (listAllUsers.find(user => userFullName(user) === nameUserToDel) && !char.match(/[@<>]/)
&& nameUserToDel.length === cursorPos.focusOffset - 1) {
//if user have in the ListUsers and cursor at the end of firstLastName of user
//then dropdown turn off and put chars in the DIV after endTag
Avoid too many return
statements within this function. Open
Open
return 0
Avoid too many return
statements within this function. Open
Open
return
Avoid too many return
statements within this function. Open
Open
return 0
Avoid too many return
statements within this function. Open
Open
return 0
Avoid too many return
statements within this function. Open
Open
return 0
Avoid too many return
statements within this function. Open
Open
|| RichText.contentBtwTags(textHTML, cursorPos, END_TAG_AT, 1).length !== cursorPos.focusOffset-1) return 0
Avoid too many return
statements within this function. Open
Open
return 0
Avoid too many return
statements within this function. Open
Open
return 0
Avoid too many return
statements within this function. Open
Open
if (indexOfSelection === -1 ) return