Showing 3,439 of 3,635 total issues
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/
Arrow function should not return assignment. Open
<ComponentToRender ref={ref => (result = ref)} {...props} index={1} />
- 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
const component = shallow(<MetadataTemplate {...props} />);
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Prefer named exports. Open
export default class NewTemplate extends RouteHandler {
- 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 templates from 'app/Templates/TemplatesAPI';
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Unexpected console statement. Open
console.warn = function (message) {
- Read upRead up
- Exclude checks
title: no-console ruletype: suggestion relatedrules: - no-alert
- no-debugger
In JavaScript that is designed to be executed in the browser, it's considered a best practice to avoid using methods on console
. Such messages are considered to be for debugging purposes and therefore not suitable to ship to the client. In general, calls using console
should be stripped before being pushed to production.
console.log("Made it here.");
console.error("That shouldn't have happened.");
Rule Details
This rule disallows calls or assignments to methods of the console
object.
Examples of incorrect code for this rule:
::: incorrect
/* eslint no-console: "error" */
console.log("Log a debug level message.");
console.warn("Log a warn level message.");
console.error("Log an error level message.");
console.log = foo();
:::
Examples of correct code for this rule:
::: correct
/* eslint no-console: "error" */
// custom console
Console.log("Hello world!");
:::
Options
This rule has an object option for exceptions:
-
"allow"
has an array of strings which are allowed methods of theconsole
object
Examples of additional correct code for this rule with a sample { "allow": ["warn", "error"] }
option:
::: correct
/* eslint no-console: ["error", { allow: ["warn", "error"] }] */
console.warn("Log a warn level message.");
console.error("Log an error level message.");
:::
When Not To Use It
If you're using Node.js, however, console
is used to output information to the user and so is not strictly used for debugging purposes. If you are developing for Node.js then you most likely do not want this rule enabled.
Another case where you might not use this rule is if you want to enforce console calls and not console overwrites. For example:
/* eslint no-console: ["error", { allow: ["warn"] }] */
console.error = function (message) {
throw new Error(message);
};
With the no-console
rule in the above example, ESLint will report an error. For the above example, you can disable the rule:
// eslint-disable-next-line no-console
console.error = function (message) {
throw new Error(message);
};
// or
console.error = function (message) { // eslint-disable-line no-console
throw new Error(message);
};
However, you might not want to manually add eslint-disable-next-line
or eslint-disable-line
. You can achieve the effect of only receiving errors for console calls with the no-restricted-syntax
rule:
{
"rules": {
"no-console": "off",
"no-restricted-syntax": [
"error",
{
"selector": "CallExpression[callee.object.name='console'][callee.property.name!=/^(log|warn|error|info|trace)$/]",
"message": "Unexpected property on console object was called"
}
]
}
}
Source: http://eslint.org/docs/rules/
Definition for rule 'node/no-restricted-import' was not found. Open
/** @type {import('tailwindcss').Config} */
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Prop spreading is forbidden Open
<SidePanel {...props}>
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Declare only one React component per file Open
const Header = ({ children }) => <div className="modal-header">{children}</div>;
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Export statements should appear at the end of the file Open
export class Thumbnail extends Component {
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Prefer named exports. Open
export default Thumbnail;
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Prefer named exports. Open
export default Warning;
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Prefer named exports. Open
export default Tip;
- 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
documents: PropTypes.object.isRequired,
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Prop type "object" is forbidden Open
connections: PropTypes.object,
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Prop type "object" is forbidden Open
thesauri: PropTypes.object,
- 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 { mockID } from 'shared/uniqueID';
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
propType "show" is not required, but has no corresponding defaultProps declaration. Open
show: PropTypes.bool,
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Prefer named exports. Open
export default connect(mapStateToProps, mapDispatchToProps)(MetadataForm);
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/