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';
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';
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') {
- Read upRead up
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';
- Read upRead up
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 = [];
- Read upRead up
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') {
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];
- Read upRead up
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];
- Read upRead up
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') {
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;
Avoid deeply nested control flow statements. Open
if (
columns.find(function(element) {
return element.key === column.key;
}) === undefined
) {
Avoid deeply nested control flow statements. Open
if (this._filterable[filterColumn](extractDataFrom(data, filterColumn).toString(), filter)) {
matchedChildren.push(children[i]);
break;
}
Avoid deeply nested control flow statements. Open
if (extractDataFrom(data, filterColumn).toString().toLowerCase().indexOf(filter) > -1) {
matchedChildren.push(children[i]);
break;
}
Avoid too many return
statements within this function. Open
return this._sortable[currentSort.column](keyB, keyA);
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;
}
- Read upRead up
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)
}
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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)
}
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76