department-of-veterans-affairs/vets-website

View on GitHub
src/platform/forms-system/src/js/fields/AutosuggestField.jsx

Summary

Maintainability
F
1 wk
Test Coverage

Function render has 99 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  render() {
    const { idSchema, formContext, formData, uiSchema, schema } = this.props;
    const id = idSchema.$id;

    // wrap matching text in a <span> element
Severity: Major
Found in src/platform/forms-system/src/js/fields/AutosuggestField.jsx - About 3 hrs to fix

    File AutosuggestField.jsx has 294 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import React from 'react';
    import PropTypes from 'prop-types';
    import Downshift from 'downshift';
    import classNames from 'classnames';
    import set from '../../../../utilities/data/set';
    Severity: Minor
    Found in src/platform/forms-system/src/js/fields/AutosuggestField.jsx - About 3 hrs to fix

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

        render() {
          const { idSchema, formContext, formData, uiSchema, schema } = this.props;
          const id = idSchema.$id;
      
          // wrap matching text in a <span> element
      Severity: Minor
      Found in src/platform/forms-system/src/js/fields/AutosuggestField.jsx - 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 getInput has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      function getInput(input, uiSchema, schema) {
        if (input && input.widget === 'autosuggest') {
          return input.label;
        }
      
      
      Severity: Minor
      Found in src/platform/forms-system/src/js/fields/AutosuggestField.jsx - 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

      Avoid too many return statements within this function.
      Open

        return '';
      Severity: Major
      Found in src/platform/forms-system/src/js/fields/AutosuggestField.jsx - About 30 mins to fix

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

                <Downshift
                  onChange={this.handleChange}
                  onInputValueChange={this.handleInputValueChange}
                  inputValue={this.state.input}
                  selectedItem={this.state.input}
        Severity: Major
        Found in src/platform/forms-system/src/js/fields/AutosuggestField.jsx and 1 other location - About 2 days to fix
        src/applications/pre-need-integration/components/AutosugggestField.jsx on lines 255..313

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

        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

          constructor(props) {
            super(props);
            const { uiSchema, schema, formData } = props;
            const input = getInput(formData, uiSchema, schema);
            const uiOptions = uiSchema['ui:options'];
        Severity: Major
        Found in src/platform/forms-system/src/js/fields/AutosuggestField.jsx and 1 other location - About 1 day to fix
        src/applications/pre-need-integration/components/AutosugggestField.jsx on lines 42..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 246.

        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

        AutosuggestField.propTypes = {
          schema: PropTypes.object.isRequired,
          onBlur: PropTypes.func.isRequired,
          onChange: PropTypes.func.isRequired,
          formContext: PropTypes.shape({
        Severity: Major
        Found in src/platform/forms-system/src/js/fields/AutosuggestField.jsx and 1 other location - About 1 day to fix
        src/applications/pre-need-integration/components/AutosugggestField.jsx on lines 334..358

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

        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

          handleInputValueChange = inputValue => {
            if (inputValue !== this.state.input) {
              const uiOptions = this.props.uiSchema['ui:options'];
              if (uiOptions.queryForResults) {
                this.debouncedGetOptions(inputValue);
        Severity: Major
        Found in src/platform/forms-system/src/js/fields/AutosuggestField.jsx and 1 other location - About 1 day to fix
        src/applications/pre-need-integration/components/AutosugggestField.jsx on lines 162..187

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

        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

          getItemFromInput = (inputValue, suggestions, uiOptions) => {
            let item = { widget: 'autosuggest', label: inputValue };
            // once the input is long enough, check for exactly matching strings so that we don't
            // force a user to click on an item when they've typed an exact match of a label
            if (inputValue && inputValue.length > 3) {
        Severity: Major
        Found in src/platform/forms-system/src/js/fields/AutosuggestField.jsx and 1 other location - About 7 hrs to fix
        src/applications/pre-need-integration/components/AutosugggestField.jsx on lines 134..160

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

        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

        function getInput(input, uiSchema, schema) {
          if (input && input.widget === 'autosuggest') {
            return input.label;
          }
        
        
        Severity: Major
        Found in src/platform/forms-system/src/js/fields/AutosuggestField.jsx and 1 other location - About 7 hrs to fix
        src/applications/pre-need-integration/components/AutosugggestField.jsx on lines 14..39

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

        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

          setOptions = options => {
            if (!this.unmounted) {
              const suggestions = this.getSuggestions(options, this.state.input);
              this.setState({
                options,
        Severity: Major
        Found in src/platform/forms-system/src/js/fields/AutosuggestField.jsx and 1 other location - About 6 hrs to fix
        src/applications/pre-need-integration/components/AutosugggestField.jsx on lines 89..107

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

        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 (formContext.reviewMode) {
              const readOnlyData = <span>{getInput(formData, uiSchema, schema)}</span>;
        
              // If this is an non-object field then the label will
              // be included by ReviewFieldTemplate
        Severity: Major
        Found in src/platform/forms-system/src/js/fields/AutosuggestField.jsx and 1 other location - About 4 hrs to fix
        src/applications/pre-need-integration/components/AutosugggestField.jsx on lines 236..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 122.

        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 highLightMatchingText = query => {
              if (value.length > 2) {
                return query
                  .split(caseInsensitiveMatch)
                  .map(
        Severity: Major
        Found in src/platform/forms-system/src/js/fields/AutosuggestField.jsx and 1 other location - About 2 hrs to fix
        src/applications/pre-need-integration/components/AutosugggestField.jsx on lines 218..234

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

        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

          handleChange = selectedItem => {
            const value = this.getFormData(selectedItem);
            this.props.onChange(value);
            if (this.state.input !== selectedItem.label) {
              this.setState({
        Severity: Major
        Found in src/platform/forms-system/src/js/fields/AutosuggestField.jsx and 1 other location - About 2 hrs to fix
        src/applications/pre-need-integration/components/AutosugggestField.jsx on lines 189..197

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

        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

          getFormData = suggestion => {
            if (this.useEnum) {
              return suggestion.id;
            }
        
        
        src/applications/pre-need-integration/components/AutosugggestField.jsx on lines 121..132

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

        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

          getOptions = inputValue => {
            const { getOptions } = this.props.uiSchema['ui:options'];
            if (getOptions) {
              getOptions(inputValue).then(this.setOptions);
            }
        src/applications/pre-need-integration/components/AutosugggestField.jsx on lines 82..87

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

        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

          getSuggestions = (options, value) => {
            if (value) {
              const uiOptions = this.props.uiSchema['ui:options'];
              return sortListByFuzzyMatch(value, options).slice(
                0,
        src/applications/pre-need-integration/components/AutosugggestField.jsx on lines 109..119

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

        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