nmanandhar/react-app-menu

View on GitHub

Showing 3 of 9 total issues

Function MenuBar has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
Open

export const MenuBar: React.FC<MenuBarProps> = ({onSelect, expandIcon = "⮞", checkedIcon = "✔", enableHotKeys = false, disableMenubar = false, openMenusOnHover = false, className, children}) => {
    const [callbacks] = useState<{ [key: string]: Callback }>({});

    useEffect(() => {
        const hotKeyHandler = (keyboardEvent: KeyboardEvent): void => {
Severity: Minor
Found in src/menu/MenuBar.tsx - About 6 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 Menu has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
Open

export const Menu: React.FC<MenuProps> = ({onSelect, menuId, label, icon, hotKeys, focusKey, show = true, disabled = false, checked, children, closeOnSelect}) => {
    const menuBar = useContext(MenuBarContext);
    const longestSiblingHotkey = useContext(MenuContext);
    const ref = useRef<HTMLLIElement>(null);

Severity: Minor
Found in src/menu/Menu.tsx - About 5 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

Consider simplifying this complex logical expression.
Open

    } else if (isRootMenu) {
        return (
            <li ref={ref} tabIndex={0}
                className={classNames(`reactAppMenubar--menu`, MENU_ROOT, {[`reactAppMenubar--menu-isDisabled`]: disabled})}>
                <div className={`reactAppMenubar--menu--labelContainer`}>
Severity: Critical
Found in src/menu/Menu.tsx - About 3 hrs to fix
    Severity
    Category
    Status
    Source
    Language