grommet/grommet

View on GitHub
src/js/components/Button/StyledButtonKind.js

Summary

Maintainability
D
2 days
Test Coverage

File StyledButtonKind.js has 270 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import styled, { css } from 'styled-components';

import {
  activeStyle,
  disabledStyle,
Severity: Minor
Found in src/js/components/Button/StyledButtonKind.js - About 2 hrs to fix

    Function padFromTheme has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    const padFromTheme = (size = 'medium', theme, themeObj, kind, iconOnly) => {
      if (size && iconOnly && themeObj?.size?.[size]?.iconOnly?.pad) {
        const pad = themeObj?.size?.[size]?.iconOnly?.pad;
    
        return {
    Severity: Minor
    Found in src/js/components/Button/StyledButtonKind.js - About 1 hr to fix

      Function padFromTheme has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      const padFromTheme = (size = 'medium', theme, themeObj, kind, iconOnly) => {
        if (size && iconOnly && themeObj?.size?.[size]?.iconOnly?.pad) {
          const pad = themeObj?.size?.[size]?.iconOnly?.pad;
      
          return {
      Severity: Minor
      Found in src/js/components/Button/StyledButtonKind.js - About 55 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 hoverIndicatorStyle has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      const hoverIndicatorStyle = ({ hoverIndicator, theme }) => {
        const themishObj = {};
        if (hoverIndicator === true || hoverIndicator === 'background')
          themishObj.background = theme.global.hover.background;
        else if (hoverIndicator.color || hoverIndicator.background) {
      Severity: Minor
      Found in src/js/components/Button/StyledButtonKind.js - 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 kindStyle has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      const kindStyle = ({
        busy,
        colorValue,
        hasIcon,
        hasLabel,
      Severity: Minor
      Found in src/js/components/Button/StyledButtonKind.js - 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 undefined;
      Severity: Major
      Found in src/js/components/Button/StyledButtonKind.js - About 30 mins to fix

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

          ${(props) =>
            !props.plain &&
            props.theme.button.transition &&
            `
            transition-property: ${props.theme.button.transition.properties.join(',')};
        Severity: Major
        Found in src/js/components/Button/StyledButtonKind.js and 1 other location - About 3 hrs to fix
        src/js/components/Button/StyledButton.js on lines 226..233

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

        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

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

            if (obj) {
              styles.push(kindPartStyles(obj, theme, colorValue));
              if (obj.border && obj.border.width && pad && !obj.padding) {
                // Adjust padding from the button.size or just top button.padding
                // to deal with the kind's border width. But don't override any
        Severity: Major
        Found in src/js/components/Button/StyledButtonKind.js and 1 other location - About 2 hrs to fix
        src/js/components/Button/StyledButtonKind.js on lines 146..154

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

        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

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

            if (obj) {
              styles.push(kindPartStyles(obj, theme, colorValue));
              if (obj.border && obj.border.width && pad && !obj.padding) {
                // Adjust padding from the button.size or just top button.padding
                // to deal with the kind's border width. But don't override any
        Severity: Major
        Found in src/js/components/Button/StyledButtonKind.js and 1 other location - About 2 hrs to fix
        src/js/components/Button/StyledButtonKind.js on lines 160..168

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

        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 fillStyle = (fillContainer) => {
          if (fillContainer === 'horizontal') {
            return 'width: 100%;';
          }
          if (fillContainer === 'vertical') {
        Severity: Major
        Found in src/js/components/Button/StyledButtonKind.js and 2 other locations - About 1 hr to fix
        src/js/components/Button/StyledButton.js on lines 118..134
        src/js/utils/styles.js on lines 203..217

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

        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

        })`
          display: inline-block;
          box-sizing: border-box;
          cursor: pointer;
          font: inherit;
        Severity: Minor
        Found in src/js/components/Button/StyledButtonKind.js and 1 other location - About 40 mins to fix
        src/js/components/Grid/StyledGrid.js on lines 217..245

        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

        const kindStyle = ({
          busy,
          colorValue,
          hasIcon,
          hasLabel,
        Severity: Minor
        Found in src/js/components/Button/StyledButtonKind.js and 1 other location - About 40 mins to fix
        src/js/components/DataChart/Detail.js on lines 27..207

        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

        const StyledButtonKind = styled.button.withConfig({
          // don't let kind attribute leak to DOM
          // https://styled-components.com/docs/api#shouldforwardprop
          shouldForwardProp: (prop, defaultValidatorFn) =>
            !['kind'].includes(prop) && defaultValidatorFn(prop),
        Severity: Minor
        Found in src/js/components/Button/StyledButtonKind.js and 1 other location - About 40 mins to fix
        src/js/components/Layer/StyledLayer.js on lines 774..808

        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

              horizontal:
                theme.global.edgeSize[theme.button.padding.horizontal] ||
                theme.button.padding.horizontal,
        Severity: Minor
        Found in src/js/components/Button/StyledButtonKind.js and 1 other location - About 30 mins to fix
        src/js/components/Button/StyledButtonKind.js on lines 66..68

        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

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

              vertical:
                theme.global.edgeSize[theme.button.padding.vertical] ||
                theme.button.padding.vertical,
        Severity: Minor
        Found in src/js/components/Button/StyledButtonKind.js and 1 other location - About 30 mins to fix
        src/js/components/Button/StyledButtonKind.js on lines 69..71

        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