Arrow function has too many statements (20). Maximum allowed is 10. Open
it('should render the correct component', () => {
- 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/
Arrow function should not return assignment. Open
<ComponentToRender ref={ref => (result = ref)} {...props} index={0} />
- Read upRead up
- Exclude checks
title: no-return-assign
rule_type: suggestion
One of the interesting, and sometimes confusing, aspects of JavaScript is that assignment can happen at almost any point. Because of this, an errant equals sign can end up causing assignment when the true intent was to do a comparison. This is especially true when using a return
statement. For example:
function doSomething() {
return foo = bar + 2;
}
It is difficult to tell the intent of the return
statement here. It's possible that the function is meant to return the result of bar + 2
, but then why is it assigning to foo
? It's also possible that the intent was to use a comparison operator such as ==
and that this code is an error.
Because of this ambiguity, it's considered a best practice to not use assignment in return
statements.
Rule Details
This rule aims to eliminate assignments from return
statements. As such, it will warn whenever an assignment is found as part of return
.
Options
The rule takes one option, a string, which must contain one of the following values:
-
except-parens
(default): Disallow assignments unless they are enclosed in parentheses. -
always
: Disallow all assignments.
except-parens
This is the default option. It disallows assignments unless they are enclosed in parentheses.
Examples of incorrect code for the default "except-parens"
option:
::: incorrect
/*eslint no-return-assign: "error"*/
function doSomething() {
return foo = bar + 2;
}
function doSomething() {
return foo += 2;
}
const foo = (a, b) => a = b
const bar = (a, b, c) => (a = b, c == b)
function doSomething() {
return foo = bar && foo > 0;
}
:::
Examples of correct code for the default "except-parens"
option:
::: correct
/*eslint no-return-assign: "error"*/
function doSomething() {
return foo == bar + 2;
}
function doSomething() {
return foo === bar + 2;
}
function doSomething() {
return (foo = bar + 2);
}
const foo = (a, b) => (a = b)
const bar = (a, b, c) => ((a = b), c == b)
function doSomething() {
return (foo = bar) && foo > 0;
}
:::
always
This option disallows all assignments in return
statements.
All assignments are treated as problems.
Examples of incorrect code for the "always"
option:
::: incorrect
/*eslint no-return-assign: ["error", "always"]*/
function doSomething() {
return foo = bar + 2;
}
function doSomething() {
return foo += 2;
}
function doSomething() {
return (foo = bar + 2);
}
:::
Examples of correct code for the "always"
option:
::: correct
/*eslint no-return-assign: ["error", "always"]*/
function doSomething() {
return foo == bar + 2;
}
function doSomething() {
return foo === bar + 2;
}
:::
When Not To Use It
If you want to allow the use of assignment operators in a return
statement, then you can safely disable this rule.
Source: http://eslint.org/docs/rules/
Prop spreading is forbidden Open
component = shallow(<MetadataProperty {...props} />);
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Prop spreading is forbidden Open
component = shallow(<MetadataProperty {...props} />);
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Prop spreading is forbidden Open
<Source {...sourceProps} />
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Prop spreading is forbidden Open
<Target {...targetProps} {...actions} />
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Prop spreading is forbidden Open
<ComponentToRender ref={ref => (result = ref)} {...props} index={0} />
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Prop spreading is forbidden Open
<Target {...targetProps} {...actions} />
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Prop spreading is forbidden Open
<DNDComponent {...props} />
- 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
/**
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Prop spreading is forbidden Open
component = shallow(<MetadataProperty {...props} />);
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Prop spreading is forbidden Open
return <DecoratedComponent {...this.props} errors={{}} />;
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/