grommet/grommet

View on GitHub
src/js/components/Chart/Chart.js

Summary

Maintainability
F
1 wk
Test Coverage

Function Chart has a Cognitive Complexity of 123 (exceeds 5 allowed). Consider refactoring.
Open

  (
    {
      a11yTitle,
      bounds: boundsProp,
      color,
Severity: Minor
Found in src/js/components/Chart/Chart.js - About 2 days 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

File Chart.js has 648 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import React, { useContext, useEffect, useMemo, useState } from 'react';

import { ThemeContext } from 'styled-components';
import { useLayoutEffect } from '../../utils/use-isomorphic-layout-effect';
import { defaultProps } from '../../default-props';
Severity: Major
Found in src/js/components/Chart/Chart.js - About 1 day to fix

    Function renderArea has 47 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        const renderArea = () => {
          let d = '';
          (values || [])
            .filter(({ value }) => value[1] !== undefined)
            .forEach(({ value }, index) => {
    Severity: Minor
    Found in src/js/components/Chart/Chart.js - About 1 hr to fix

      Function renderLine has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          const renderLine = () => {
            let d = '';
            let d2 = '';
            (values || [])
              .filter(({ value }) => value[1] !== undefined)
      Severity: Minor
      Found in src/js/components/Chart/Chart.js - About 1 hr to fix

        Function inset has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            const inset = useMemo(() => {
              const result = { top: 0, left: 0, bottom: 0, right: 0 };
              if (pad) {
                if (pad.horizontal) {
                  const padSize = parseMetricToNum(
        Severity: Minor
        Found in src/js/components/Chart/Chart.js - About 1 hr to fix

          Function size has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              const size = useMemo(() => {
                const gapWidth = gap
                  ? parseMetricToNum(theme.global.edgeSize[gap] || gap)
                  : strokeWidth;
          
          
          Severity: Minor
          Found in src/js/components/Chart/Chart.js - About 1 hr to fix

            Function renderPoint has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                      const renderPoint = (valueX, valueY) => {
                        const props = { ...hoverProps, ...clickProps, ...valueRest };
                        const [x, y] = valueCoords(valueX, valueY);
                        const [cx, cy] = valueToCoordinate(x, y);
                        const off = width / 2;
            Severity: Minor
            Found in src/js/components/Chart/Chart.js - About 1 hr to fix

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

                        const [endX, endY] = valueCoords(
                          value[0],
                          value.length === 2
                            ? Math.max(
                                Math.min(0, horizontal ? bounds.x.max : bounds.y.max),
              Severity: Major
              Found in src/js/components/Chart/Chart.js and 1 other location - About 2 hrs to fix
              src/js/components/Chart/Chart.js on lines 283..291

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

              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 [startX, startY] = valueCoords(
                          value[0],
                          value.length === 2
                            ? Math.min(
                                Math.max(0, horizontal ? bounds.x.min : bounds.y.min),
              Severity: Major
              Found in src/js/components/Chart/Chart.js and 1 other location - About 2 hrs to fix
              src/js/components/Chart/Chart.js on lines 292..300

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

              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

                    if (sizeHeight === 'full' || sizeHeight === 'fill') {
                      [, height] = containerSize;
                    } else if (sizeHeight === 'auto') {
                      height = autoSize;
                    } else {
              Severity: Major
              Found in src/js/components/Chart/Chart.js and 1 other location - About 2 hrs to fix
              src/js/components/Chart/Chart.js on lines 143..149

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

              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

                    if (sizeWidth === 'full' || sizeWidth === 'fill') {
                      [width] = containerSize;
                    } else if (sizeWidth === 'auto') {
                      width = autoSize;
                    } else {
              Severity: Major
              Found in src/js/components/Chart/Chart.js and 1 other location - About 2 hrs to fix
              src/js/components/Chart/Chart.js on lines 158..164

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

              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

                      if (pad.horizontal) {
                        const padSize = parseMetricToNum(
                          theme.global.edgeSize[pad.horizontal] || pad.horizontal,
                        );
                        result.left = padSize;
              Severity: Major
              Found in src/js/components/Chart/Chart.js and 1 other location - About 1 hr to fix
              src/js/components/Chart/Chart.js on lines 74..80

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

              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

                      if (pad.vertical) {
                        const padSize = parseMetricToNum(
                          theme.global.edgeSize[pad.vertical] || pad.vertical,
                        );
                        result.top = padSize;
              Severity: Major
              Found in src/js/components/Chart/Chart.js and 1 other location - About 1 hr to fix
              src/js/components/Chart/Chart.js on lines 67..73

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

              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 (pattern === 'stripesHorizontal') {
                      content = (
                        <path
                          d={`M 0 ${unit} L ${double} ${unit}`}
                          stroke={pColor}
              Severity: Major
              Found in src/js/components/Chart/Chart.js and 1 other location - About 1 hr to fix
              src/js/components/Chart/Chart.js on lines 662..688

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

              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 (pattern === 'stripesVertical') {
                      content = (
                        <path
                          d={`M ${unit} 0 L ${unit} ${double}`}
                          stroke={pColor}
              Severity: Major
              Found in src/js/components/Chart/Chart.js and 1 other location - About 1 hr to fix
              src/js/components/Chart/Chart.js on lines 654..688

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

              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

                      if (pad.end) {
                        result.right = parseMetricToNum(
                          theme.global.edgeSize[pad.end] || pad.end,
                        );
                      }
              Severity: Minor
              Found in src/js/components/Chart/Chart.js and 1 other location - About 45 mins to fix
              src/js/components/Chart/Chart.js on lines 81..85

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

              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

                      if (pad.start) {
                        result.left = parseMetricToNum(
                          theme.global.edgeSize[pad.start] || pad.start,
                        );
                      }
              Severity: Minor
              Found in src/js/components/Chart/Chart.js and 1 other location - About 45 mins to fix
              src/js/components/Chart/Chart.js on lines 86..90

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

              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

                      x:
                        (size.width - (inset.left + inset.right)) /
                        (bounds.x.max - bounds.x.min),
              Severity: Minor
              Found in src/js/components/Chart/Chart.js and 1 other location - About 40 mins to fix
              src/js/components/Chart/Chart.js on lines 184..186

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

              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

                      y:
                        (size.height - (inset.top + inset.bottom)) /
                        (bounds.y.max - bounds.y.min),
              Severity: Minor
              Found in src/js/components/Chart/Chart.js and 1 other location - About 40 mins to fix
              src/js/components/Chart/Chart.js on lines 181..183

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

              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 (pattern === 'circles') {
                      content = <circle cx={unit} cy={unit} r={half} fill={pColor} />;
                    } else if (pattern === 'stripesHorizontal') {
                      content = (
                        <path
              Severity: Minor
              Found in src/js/components/Chart/Chart.js and 1 other location - About 30 mins to fix
              src/js/components/DataFilter/DataFilter.js on lines 206..232

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

              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