bokuweb/react-resizable-box

View on GitHub

Showing 27 of 59 total issues

File index.tsx has 868 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import * as React from 'react';
import { flushSync } from 'react-dom';

import { Resizer, Direction } from './resizer';

Severity: Major
Found in src/index.tsx - About 2 days to fix

    Function onMouseMove has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
    Open

      onMouseMove(event: MouseEvent | TouchEvent) {
        if (!this.state.isResizing || !this.resizable || !this.window) {
          return;
        }
        if (this.window.TouchEvent && isTouchEvent(event)) {
    Severity: Minor
    Found in src/index.tsx - About 4 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 calculateNewMaxFromBoundary has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

      calculateNewMaxFromBoundary(maxWidth?: number, maxHeight?: number) {
        const { boundsByDirection } = this.props;
        const { direction } = this.state;
        const widthByDirection = boundsByDirection && hasDirection('left', direction);
        const heightByDirection = boundsByDirection && hasDirection('top', direction);
    Severity: Minor
    Found in src/index.tsx - About 4 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 onMouseMove has 104 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      onMouseMove(event: MouseEvent | TouchEvent) {
        if (!this.state.isResizing || !this.resizable || !this.window) {
          return;
        }
        if (this.window.TouchEvent && isTouchEvent(event)) {
    Severity: Major
    Found in src/index.tsx - About 4 hrs to fix

      Function onResizeStart has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
      Open

        onResizeStart(event: React.MouseEvent<HTMLElement> | React.TouchEvent<HTMLElement>, direction: Direction) {
          if (!this.resizable || !this.window) {
            return;
          }
          let clientX = 0;
      Severity: Minor
      Found in src/index.tsx - About 3 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

      Resizable has 24 functions (exceeds 20 allowed). Consider refactoring.
      Open

      export class Resizable extends React.PureComponent<ResizableProps, State> {
        flexDir?: 'row' | 'column';
      
        get parentNode(): HTMLElement | null {
          if (!this.resizable) {
      Severity: Minor
      Found in src/index.tsx - About 2 hrs to fix

        Function onResizeStart has 58 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          onResizeStart(event: React.MouseEvent<HTMLElement> | React.TouchEvent<HTMLElement>, direction: Direction) {
            if (!this.resizable || !this.window) {
              return;
            }
            let clientX = 0;
        Severity: Major
        Found in src/index.tsx - About 2 hrs to fix

          Function calculateNewSizeFromDirection has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

            calculateNewSizeFromDirection(clientX: number, clientY: number) {
              const scale = this.props.scale || 1;
              const [resizeRatioX, resizeRatioY] = normalizeToPair(this.props.resizeRatio || 1);
              const { direction, original } = this.state;
              const { lockAspectRatio, lockAspectRatioExtraHeight, lockAspectRatioExtraWidth } = this.props;
          Severity: Minor
          Found in src/index.tsx - 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 render has 39 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            render() {
              const extendsProps = Object.keys(this.props).reduce((acc, key) => {
                if (definedProps.indexOf(key) !== -1) {
                  return acc;
                }
          Severity: Minor
          Found in src/index.tsx - About 1 hr to fix

            Function calculateNewMaxFromBoundary has 36 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              calculateNewMaxFromBoundary(maxWidth?: number, maxHeight?: number) {
                const { boundsByDirection } = this.props;
                const { direction } = this.state;
                const widthByDirection = boundsByDirection && hasDirection('left', direction);
                const heightByDirection = boundsByDirection && hasDirection('top', direction);
            Severity: Minor
            Found in src/index.tsx - About 1 hr to fix

              Function calculateNewSizeFromDirection has 33 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                calculateNewSizeFromDirection(clientX: number, clientY: number) {
                  const scale = this.props.scale || 1;
                  const [resizeRatioX, resizeRatioY] = normalizeToPair(this.props.resizeRatio || 1);
                  const { direction, original } = this.state;
                  const { lockAspectRatio, lockAspectRatioExtraHeight, lockAspectRatioExtraWidth } = this.props;
              Severity: Minor
              Found in src/index.tsx - About 1 hr to fix

                Function sizeStyle has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                  get sizeStyle(): { width: string; height: string } {
                    const { size } = this.props;
                    const getSize = (key: 'width' | 'height'): string => {
                      if (typeof this.state[key] === 'undefined' || this.state[key] === 'auto') {
                        return 'auto';
                Severity: Minor
                Found in src/index.tsx - 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 constructor has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  constructor(props: ResizableProps) {
                    super(props);
                    this.state = {
                      isResizing: false,
                      width: this.propsSize?.width ?? 'auto',
                Severity: Minor
                Found in src/index.tsx - About 1 hr to fix

                  Function getParentSize has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    getParentSize(): { width: number; height: number } {
                      if (!this.parentNode) {
                        if (!this.window) {
                          return { width: 0, height: 0 };
                        }
                  Severity: Minor
                  Found in src/index.tsx - About 1 hr to fix

                    Function getPixelSize has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                    const getPixelSize = (
                      size: undefined | string | number,
                      parentSize: number,
                      innerWidth: number,
                      innerHeight: number,
                    Severity: Minor
                    Found in src/index.tsx - 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 size has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                      get size(): NumberSize {
                        let width = 0;
                        let height = 0;
                        if (this.resizable && this.window) {
                          const orgWidth = this.resizable.offsetWidth;
                    Severity: Minor
                    Found in src/index.tsx - 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

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

                      renderResizer() {
                        const { enable, handleStyles, handleClasses, handleWrapperStyle, handleWrapperClass, handleComponent } = this.props;
                        if (!enable) {
                          return null;
                        }
                    Severity: Minor
                    Found in src/index.tsx - 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

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

                    const getStringSize = (n: number | string): string => {
                      n = n.toString();
                      if (n === 'auto') {
                        return n;
                      }
                    Severity: Minor
                    Found in src/index.tsx - 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 n;
                    Severity: Major
                    Found in src/index.tsx - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                        return `${n}px`;
                      Severity: Major
                      Found in src/index.tsx - About 30 mins to fix
                        Severity
                        Category
                        Status
                        Source
                        Language