FarmBot/Farmbot-Web-App

View on GitHub
frontend/settings/fbos_settings/fbos_details.tsx

Summary

Maintainability
C
1 day
Test Coverage

File fbos_details.tsx has 387 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import React from "react";
import { Saucer, FBSelect, Help, Popover } from "../../ui";
import { updateConfig } from "../../devices/actions";
import { last, isNumber, isString } from "lodash";
import { Content, ToolTips } from "../../constants";
Severity: Minor
Found in frontend/settings/fbos_settings/fbos_details.tsx - About 5 hrs to fix

    Function FbosDetails has 51 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function FbosDetails(props: FbosDetailsProps) {
      const { informational_settings } = props.bot.hardware;
      const {
        env, commit, target, node_name, firmware_version, firmware_commit,
        soc_temp, wifi_level, uptime, memory_usage, disk_usage, throttled,
    Severity: Major
    Found in frontend/settings/fbos_settings/fbos_details.tsx - About 2 hrs to fix

      Function convertUptime has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      export const convertUptime = (seconds: number, abrv = false) => {
        if (seconds >= 172800) {
          return `${Math.round(seconds / 86400)} ${t("days")}`;
        } else if (seconds >= 7200) {
          return `${Math.round(seconds / 3600)} ${t("hours")}`;
      Severity: Minor
      Found in frontend/settings/fbos_settings/fbos_details.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

      Avoid too many return statements within this function.
      Open

          return "green";
      Severity: Major
      Found in frontend/settings/fbos_settings/fbos_details.tsx - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

            return "yellow";
        Severity: Major
        Found in frontend/settings/fbos_settings/fbos_details.tsx - About 30 mins to fix

          Function colorFromTemp has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          export const colorFromTemp = (temp: number | undefined): string => {
            if (!isNumber(temp)) {
              return "gray";
            }
            if (temp < 0) {
          Severity: Minor
          Found in frontend/settings/fbos_settings/fbos_details.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

            if (percent < 20) {
              return "gray";
            } else if (percent < 68) {
              return "red";
            } else if (percent < 84) {
          Severity: Minor
          Found in frontend/settings/fbos_settings/fbos_details.tsx and 1 other location - About 50 mins to fix
          frontend/settings/fbos_settings/fbos_details.tsx on lines 27..35

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

          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

            } else if (temp < 10) {
              return "blue";
            } else if (temp > 75) {
              return "red";
            } else if (temp > 60) {
          Severity: Minor
          Found in frontend/settings/fbos_settings/fbos_details.tsx and 1 other location - About 50 mins to fix
          frontend/settings/fbos_settings/fbos_details.tsx on lines 121..129

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

          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 3 locations. Consider refactoring.
          Open

          const THROTTLE_COLOR_KEY = () => ({
            red: t("Active"),
            yellow: t("Occurred"),
            green: t("Ok"),
            gray: t("Unknown"),
          Severity: Minor
          Found in frontend/settings/fbos_settings/fbos_details.tsx and 2 other locations - About 35 mins to fix
          frontend/settings/fbos_settings/fbos_details.tsx on lines 132..137
          frontend/settings/fbos_settings/fbos_details.tsx on lines 253..258

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

          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 3 locations. Consider refactoring.
          Open

          const WIFI_COLOR_KEY = () => ({
            gray: t("too weak"),
            red: t("weak"),
            yellow: t("ok"),
            green: t("good"),
          Severity: Minor
          Found in frontend/settings/fbos_settings/fbos_details.tsx and 2 other locations - About 35 mins to fix
          frontend/settings/fbos_settings/fbos_details.tsx on lines 246..251
          frontend/settings/fbos_settings/fbos_details.tsx on lines 253..258

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

          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 3 locations. Consider refactoring.
          Open

          const VOLTAGE_COLOR_KEY = () => ({
            red: t("Low"),
            yellow: t("Ok"),
            green: t("Good"),
            gray: t("Unknown"),
          Severity: Minor
          Found in frontend/settings/fbos_settings/fbos_details.tsx and 2 other locations - About 35 mins to fix
          frontend/settings/fbos_settings/fbos_details.tsx on lines 132..137
          frontend/settings/fbos_settings/fbos_details.tsx on lines 246..251

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

          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