Method 'render' has too many statements (13). Maximum allowed is 10. Open
render() {
- Read upRead up
- Exclude checks
title: max-statements ruletype: suggestion relatedrules: - complexity - max-depth - max-len - max-lines - max-lines-per-function - max-nested-callbacks
- max-params
The max-statements
rule allows you to specify the maximum number of statements allowed in a function.
function foo() {
var bar = 1; // one statement
var baz = 2; // two statements
var qux = 3; // three statements
}
Rule Details
This rule enforces a maximum number of statements allowed in function blocks.
Options
This rule has a number or object option:
-
"max"
(default10
) enforces a maximum number of statements allows in function blocks
Deprecated: The object property maximum
is deprecated; please use the object property max
instead.
This rule has an object option:
-
"ignoreTopLevelFunctions": true
ignores top-level functions
max
Examples of incorrect code for this rule with the default { "max": 10 }
option:
::: incorrect
/*eslint max-statements: ["error", 10]*/
/*eslint-env es6*/
function foo() {
var foo1 = 1;
var foo2 = 2;
var foo3 = 3;
var foo4 = 4;
var foo5 = 5;
var foo6 = 6;
var foo7 = 7;
var foo8 = 8;
var foo9 = 9;
var foo10 = 10;
var foo11 = 11; // Too many.
}
let foo = () => {
var foo1 = 1;
var foo2 = 2;
var foo3 = 3;
var foo4 = 4;
var foo5 = 5;
var foo6 = 6;
var foo7 = 7;
var foo8 = 8;
var foo9 = 9;
var foo10 = 10;
var foo11 = 11; // Too many.
};
:::
Examples of correct code for this rule with the default { "max": 10 }
option:
::: correct
/*eslint max-statements: ["error", 10]*/
/*eslint-env es6*/
function foo() {
var foo1 = 1;
var foo2 = 2;
var foo3 = 3;
var foo4 = 4;
var foo5 = 5;
var foo6 = 6;
var foo7 = 7;
var foo8 = 8;
var foo9 = 9;
var foo10 = 10;
return function () {
// The number of statements in the inner function does not count toward the
// statement maximum.
return 42;
};
}
let foo = () => {
var foo1 = 1;
var foo2 = 2;
var foo3 = 3;
var foo4 = 4;
var foo5 = 5;
var foo6 = 6;
var foo7 = 7;
var foo8 = 8;
var foo9 = 9;
var foo10 = 10;
return function () {
// The number of statements in the inner function does not count toward the
// statement maximum.
return 42;
};
}
:::
Note that this rule does not apply to class static blocks, and that statements in class static blocks do not count as statements in the enclosing function.
Examples of correct code for this rule with { "max": 2 }
option:
::: correct
/*eslint max-statements: ["error", 2]*/
function foo() {
let one;
let two = class {
static {
let three;
let four;
let five;
if (six) {
let seven;
let eight;
let nine;
}
}
};
}
:::
ignoreTopLevelFunctions
Examples of additional correct code for this rule with the { "max": 10 }, { "ignoreTopLevelFunctions": true }
options:
::: correct
/*eslint max-statements: ["error", 10, { "ignoreTopLevelFunctions": true }]*/
function foo() {
var foo1 = 1;
var foo2 = 2;
var foo3 = 3;
var foo4 = 4;
var foo5 = 5;
var foo6 = 6;
var foo7 = 7;
var foo8 = 8;
var foo9 = 9;
var foo10 = 10;
var foo11 = 11;
}
::: Source: http://eslint.org/docs/rules/
Function render
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
render() {
const { reference } = this.props;
let itemClass = '';
const disabled = this.props.targetDoc && typeof reference.reference === '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
Expected to return a value at the end of method 'relationType'. Open
relationType(id) {
- Read upRead up
- Exclude checks
title: consistent-return
rule_type: suggestion
Unlike statically-typed languages which enforce that a function returns a specified type of value, JavaScript allows different code paths in a function to return different types of values.
A confusing aspect of JavaScript is that a function returns undefined
if any of the following are true:
- it does not execute a
return
statement before it exits - it executes
return
which does not specify a value explicitly - it executes
return undefined
- it executes
return void
followed by an expression (for example, a function call) - it executes
return
followed by any other expression which evaluates toundefined
If any code paths in a function return a value explicitly but some code path do not return a value explicitly, it might be a typing mistake, especially in a large function. In the following example:
- a code path through the function returns a Boolean value
true
- another code path does not return a value explicitly, therefore returns
undefined
implicitly
function doSomething(condition) {
if (condition) {
return true;
} else {
return;
}
}
Rule Details
This rule requires return
statements to either always or never specify values. This rule ignores function definitions where the name begins with an uppercase letter, because constructors (when invoked with the new
operator) return the instantiated object implicitly if they do not return another object explicitly.
Examples of incorrect code for this rule:
::: incorrect
/*eslint consistent-return: "error"*/
function doSomething(condition) {
if (condition) {
return true;
} else {
return;
}
}
function doSomething(condition) {
if (condition) {
return true;
}
}
:::
Examples of correct code for this rule:
::: correct
/*eslint consistent-return: "error"*/
function doSomething(condition) {
if (condition) {
return true;
} else {
return false;
}
}
function Foo() {
if (!(this instanceof Foo)) {
return new Foo();
}
this.a = 0;
}
:::
Options
This rule has an object option:
-
"treatUndefinedAsUnspecified": false
(default) always either specify values or returnundefined
implicitly only. -
"treatUndefinedAsUnspecified": true
always either specify values or returnundefined
explicitly or implicitly.
treatUndefinedAsUnspecified
Examples of incorrect code for this rule with the default { "treatUndefinedAsUnspecified": false }
option:
::: incorrect
/*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": false }]*/
function foo(callback) {
if (callback) {
return void callback();
}
// no return statement
}
function bar(condition) {
if (condition) {
return undefined;
}
// no return statement
}
:::
Examples of incorrect code for this rule with the { "treatUndefinedAsUnspecified": true }
option:
::: incorrect
/*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": true }]*/
function foo(callback) {
if (callback) {
return void callback();
}
return true;
}
function bar(condition) {
if (condition) {
return undefined;
}
return true;
}
:::
Examples of correct code for this rule with the { "treatUndefinedAsUnspecified": true }
option:
::: correct
/*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": true }]*/
function foo(callback) {
if (callback) {
return void callback();
}
// no return statement
}
function bar(condition) {
if (condition) {
return undefined;
}
// no return statement
}
:::
When Not To Use It
If you want to allow functions to have different return
behavior depending on code branching, then it is safe to disable this rule.
Source: http://eslint.org/docs/rules/
JSX props should not use .bind() Open
onClick={this.clickReference.bind(this, reference)}
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Anchor used as a button. Anchors are primarily expected to navigate. Use the button element instead. Learn more: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/docs/rules/anchor-is-valid.md Open
<a
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
JSX props should not use .bind() Open
onMouseEnter={this.props.highlightReference.bind(null, reference._id)}
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Definition for rule 'node/no-restricted-import' was not found. Open
import PropTypes from 'prop-types';
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Prop type "object" is forbidden Open
relationTypes: PropTypes.object,
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Prop type "object" is forbidden Open
reference: PropTypes.object.isRequired,
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Prefer named exports. Open
export default connect(mapStateToProps, mapDispatchToProps)(withContext(Connection));
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
JSX props should not use .bind() Open
onMouseLeave={this.props.highlightReference.bind(null, null)}
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
propType "activateReference" is not required, but has no corresponding defaultProps declaration. Open
activateReference: PropTypes.func,
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
propType "referencesSection" is not required, but has no corresponding defaultProps declaration. Open
referencesSection: PropTypes.string,
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
propType "toggleReferences" is not required, but has no corresponding defaultProps declaration. Open
toggleReferences: PropTypes.func,
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
propType "readOnly" is not required, but has no corresponding defaultProps declaration. Open
readOnly: PropTypes.bool,
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Prop type "object" is forbidden Open
targetRange: PropTypes.object,
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
propType "deleteReference" is not required, but has no corresponding defaultProps declaration. Open
deleteReference: PropTypes.func,
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
propType "relationTypes" is not required, but has no corresponding defaultProps declaration. Open
relationTypes: PropTypes.object,
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
propType "targetRange" is not required, but has no corresponding defaultProps declaration. Open
targetRange: PropTypes.object,
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
propType "selectReference" is not required, but has no corresponding defaultProps declaration. Open
selectReference: PropTypes.func,
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/