glittershark/reactable

View on GitHub
src/reactable/table.jsx

Summary

Maintainability
F
4 days
Test Coverage

File table.jsx has 434 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import React from 'react';
import { filterPropsFrom } from './lib/filter_props_from';
import { extractDataFrom } from './lib/extract_data_from';
import { isUnsafe } from './unsafe';
import { Thead } from './thead';
Severity: Minor
Found in src/reactable/table.jsx - About 6 hrs to fix

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

        render() {
            let children = [];
            let columns;
            let userColumnsSpecified = false;
            let showHeaders = typeof this.props.hideTableHeader === 'undefined';
    Severity: Major
    Found in src/reactable/table.jsx - About 5 hrs to fix

      Function getCurrentSort has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
      Open

          getCurrentSort(column) {
              let columnName, sortDirection;
      
              if (column instanceof Object) {
                  if (typeof(column.column) !== 'undefined') {
      Severity: Minor
      Found in src/reactable/table.jsx - About 3 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 a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

          render() {
              let children = [];
              let columns;
              let userColumnsSpecified = false;
              let showHeaders = typeof this.props.hideTableHeader === 'undefined';
      Severity: Minor
      Found in src/reactable/table.jsx - About 3 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 applyFilter has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          applyFilter(filter, children) {
              // Helper function to apply filter text to a list of table rows
              filter = filter.toLowerCase();
              let matchedChildren = [];
      
      
      Severity: Minor
      Found in src/reactable/table.jsx - About 3 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 parseChildData has 59 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          parseChildData(props) {
              let data = [], tfoot;
      
              // Transform any children back to a data array
              if (typeof(props.children) !== 'undefined') {
      Severity: Major
      Found in src/reactable/table.jsx - About 2 hrs to fix

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

            initializeFilters(props) {
                this._filterable = {};
                // Transform filterable properties into a more friendly list
                for (let i in props.filterable) {
                    let column = props.filterable[i];
        Severity: Minor
        Found in src/reactable/table.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 initializeSorts has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            initializeSorts(props) {
                this._sortable = {};
                // Transform sortable properties into a more friendly list
                for (let i in props.sortable) {
                    let column = props.sortable[i];
        Severity: Minor
        Found in src/reactable/table.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 getCurrentSort has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            getCurrentSort(column) {
                let columnName, sortDirection;
        
                if (column instanceof Object) {
                    if (typeof(column.column) !== 'undefined') {
        Severity: Minor
        Found in src/reactable/table.jsx - About 1 hr to fix

          Function sortByCurrentSort has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              sortByCurrentSort() {
                  // Apply a sort function according to the current sort in the state.
                  // This allows us to perform a default sort even on a non sortable column.
                  let currentSort = this.state.currentSort;
          
          
          Severity: Minor
          Found in src/reactable/table.jsx - About 1 hr to fix

            Avoid deeply nested control flow statements.
            Open

                                        if (
                                            columns.find(function(element) {
                                            return element.key === column.key;
                                        }) === undefined
                                        ) {
            Severity: Major
            Found in src/reactable/table.jsx - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if (this._filterable[filterColumn](extractDataFrom(data, filterColumn).toString(), filter)) {
                                          matchedChildren.push(children[i]);
                                          break;
                                      }
              Severity: Major
              Found in src/reactable/table.jsx - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                        if (extractDataFrom(data, filterColumn).toString().toLowerCase().indexOf(filter) > -1) {
                                            matchedChildren.push(children[i]);
                                            break;
                                        }
                Severity: Major
                Found in src/reactable/table.jsx - About 45 mins to fix

                  Avoid too many return statements within this function.
                  Open

                                      return this._sortable[currentSort.column](keyB, keyA);
                  Severity: Major
                  Found in src/reactable/table.jsx - About 30 mins to fix

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

                        onSort(column) {
                            // Don't perform sort on unsortable columns
                            if (typeof(this._sortable[column]) === 'undefined') {
                                return;
                            }
                    Severity: Minor
                    Found in src/reactable/table.jsx - 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

                                     onPageChange={page => {
                                         this.setState({ currentPage: page });
                                         if (this.props.onPageChange) {
                                            this.props.onPageChange(page)
                                         }
                    Severity: Major
                    Found in src/reactable/table.jsx and 1 other location - About 1 hr to fix
                    src/reactable/table.jsx on lines 488..493

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

                    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

                                           onFilter={filter => {
                                         this.setState({ filter: filter });
                                         if (this.props.onFilter) {
                                            this.props.onFilter(filter)
                                         }
                    Severity: Major
                    Found in src/reactable/table.jsx and 1 other location - About 1 hr to fix
                    src/reactable/table.jsx on lines 513..518

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

                    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