FarmBot/Farmbot-Web-App

View on GitHub
frontend/farm_designer/map/layers/images/map_image.tsx

Summary

Maintainability
D
2 days
Test Coverage

File map_image.tsx has 407 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import React from "react";
import { TaggedImage } from "farmbot";
import { CameraCalibrationData, BotOriginQuadrant } from "../../../interfaces";
import { MapTransformProps } from "../../interfaces";
import { transformXY } from "../../util";
Severity: Minor
Found in frontend/farm_designer/map/layers/images/map_image.tsx - About 5 hrs to fix

    Function render has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

      render() {
        const { imageWidth, imageHeight } = this.state;
        const { image, cameraCalibrationData, mapTransformProps, cropImage,
        } = this.props;
        const imageRotation = parse(cameraCalibrationData.rotation) ?? 0;
    Severity: Minor
    Found in frontend/farm_designer/map/layers/images/map_image.tsx - About 2 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 render has 53 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      render() {
        const { imageWidth, imageHeight } = this.state;
        const { image, cameraCalibrationData, mapTransformProps, cropImage,
        } = this.props;
        const imageRotation = parse(cameraCalibrationData.rotation) ?? 0;
    Severity: Major
    Found in frontend/farm_designer/map/layers/images/map_image.tsx - About 2 hrs to fix

      Function mapImagePositionData has 49 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export const mapImagePositionData = (props: MapImagePositionDataProps):
        MapImagePositionData | undefined => {
        const { cameraCalibrationData, alreadyRotated, noRotation } = props;
        const imageRotated = alreadyRotated && !noRotation;
        const parsed = parseCalibrationData(cameraCalibrationData);
      Severity: Minor
      Found in frontend/farm_designer/map/layers/images/map_image.tsx - About 1 hr to fix

        Consider simplifying this complex logical expression.
        Open

          if (isNumber(x) && isNumber(y) && height > 0 && width > 0 &&
            isNumber(imageScale) && imageScale > 0 &&
            isNumber(imageOffsetX) && isNumber(imageOffsetY) && imageOrigin) {
            return {
              x, y, width, height, imageScale, imageOffsetX, imageOffsetY, imageOrigin
        Severity: Critical
        Found in frontend/farm_designer/map/layers/images/map_image.tsx - About 1 hr to fix

          Function generateTransform has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          const generateTransform = (props: TransformProps): string => {
            const {
              quadrant, qCoords, size, imageOrigin, xySwap, rotate,
            } = props;
            const { qx, qy } = qCoords;
          Severity: Minor
          Found in frontend/farm_designer/map/layers/images/map_image.tsx - About 1 hr to fix

            Consider simplifying this complex logical expression.
            Open

                    if (imagePosition) {
                      const { width, height, transformOrigin } = imagePosition;
                      const transform = this.props.disableTranslation ?
                        imagePosition.transform.replace(/translate\(.*?\)/g, "")
                        : imagePosition.transform;
            Severity: Major
            Found in frontend/farm_designer/map/layers/images/map_image.tsx - About 40 mins to fix

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

              export const mapImagePositionData = (props: MapImagePositionDataProps):
                MapImagePositionData | undefined => {
                const { cameraCalibrationData, alreadyRotated, noRotation } = props;
                const imageRotated = alreadyRotated && !noRotation;
                const parsed = parseCalibrationData(cameraCalibrationData);
              Severity: Minor
              Found in frontend/farm_designer/map/layers/images/map_image.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 generateTransform has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              const generateTransform = (props: TransformProps): string => {
                const {
                  quadrant, qCoords, size, imageOrigin, xySwap, rotate,
                } = props;
                const { qx, qy } = qCoords;
              Severity: Minor
              Found in frontend/farm_designer/map/layers/images/map_image.tsx - About 25 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

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                shouldComponentUpdate(nextProps: MapImageProps, nextState: MapImageState) {
                  const propsChanged = !equals(this.props, nextProps);
                  const stateChanged = !equals(this.state, nextState);
                  return propsChanged || stateChanged;
                }
              Severity: Major
              Found in frontend/farm_designer/map/layers/images/map_image.tsx and 1 other location - About 1 hr to fix
              frontend/sequences/step_button_cluster.tsx on lines 212..219

              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 65.

              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

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                      || (Math.abs(size.height / 2 - calibrationCenter.x) < 5
                        && Math.abs(size.width / 2 - calibrationCenter.y) < 5));
              Severity: Major
              Found in frontend/farm_designer/map/layers/images/map_image.tsx and 1 other location - About 1 hr to fix
              frontend/farm_designer/map/layers/images/map_image.tsx on lines 47..48

              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 61.

              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

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                    && ((Math.abs(size.width / 2 - calibrationCenter.x) < 5
                      && Math.abs(size.height / 2 - calibrationCenter.y) < 5)
              Severity: Major
              Found in frontend/farm_designer/map/layers/images/map_image.tsx and 1 other location - About 1 hr to fix
              frontend/farm_designer/map/layers/images/map_image.tsx on lines 49..50

              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 61.

              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

              Further Reading

              Similar blocks of code found in 4 locations. Consider refactoring.
              Open

                const {
                  x, y, width, height, imageScale, imageOffsetX, imageOffsetY, imageOrigin,
                } = props;
              Severity: Major
              Found in frontend/farm_designer/map/layers/images/map_image.tsx and 3 other locations - About 40 mins to fix
              frontend/controls/move/bot_position_rows.tsx on lines 98..101
              frontend/devices/connectivity/connectivity.tsx on lines 70..74
              frontend/farm_designer/map/layers/tool_slots/tool_label.tsx on lines 67..69

              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 48.

              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

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                  return isNumber(calibrationCenter.x) && isNumber(calibrationCenter.y)
                    && isNumber(size.width) && isNumber(size.height)
                    && ((Math.abs(size.width / 2 - calibrationCenter.x) < 5
                      && Math.abs(size.height / 2 - calibrationCenter.y) < 5)
                      || (Math.abs(size.height / 2 - calibrationCenter.x) < 5
              Severity: Minor
              Found in frontend/farm_designer/map/layers/images/map_image.tsx and 1 other location - About 35 mins to fix
              frontend/farm_designer/map/layers/logs/logs_layer.tsx on lines 154..158

              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

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                      const imagePosition = mapImagePositionData({
                        x, y, width: imageWidth, height: imageHeight,
                        cameraCalibrationData, mapTransformProps, alreadyRotated,
                      });
              Severity: Minor
              Found in frontend/farm_designer/map/layers/images/map_image.tsx and 1 other location - About 35 mins to fix
              frontend/farm_designer/map/layers/plants/plant_actions.ts on lines 94..96

              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

              Further Reading

              There are no issues that match your filters.

              Category
              Status