Showing 3,439 of 3,635 total issues
Missing an explicit type attribute for button Open
<button
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Prefer named exports. Open
export default ViewerRoute;
- 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
export const SET_REFERENCES = 'SET_REFERENCES';
- 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 { actions as formActions } from 'react-redux-form';
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Unexpected require(). Open
Mark = require('mark.js');
- Read upRead up
- Exclude checks
title: global-require
rule_type: suggestion
This rule was deprecated in ESLint v7.0.0. Please use the corresponding rule in eslint-plugin-n
.
In Node.js, module dependencies are included using the require()
function, such as:
var fs = require("fs");
While require()
may be called anywhere in code, some style guides prescribe that it should be called only in the top level of a module to make it easier to identify dependencies. For instance, it's arguably harder to identify dependencies when they are deeply nested inside of functions and other statements:
function foo() {
if (condition) {
var fs = require("fs");
}
}
Since require()
does a synchronous load, it can cause performance problems when used in other locations.
Further, ES6 modules mandate that import
and export
statements can only occur in the top level of the module's body.
Rule Details
This rule requires all calls to require()
to be at the top level of the module, similar to ES6 import
and export
statements, which also can occur only at the top level.
Examples of incorrect code for this rule:
::: incorrect
/*eslint global-require: "error"*/
/*eslint-env es6*/
// calling require() inside of a function is not allowed
function readFile(filename, callback) {
var fs = require("fs");
fs.readFile(filename, callback);
}
// conditional requires like this are also not allowed
if (DEBUG) {
require("debug");
}
// a require() in a switch statement is also flagged
switch (x) {
case "1":
require("1");
break;
}
// you may not require() inside an arrow function body
var getModule = (name) => require(name);
// you may not require() inside of a function body as well
function getModule(name) {
return require(name);
}
// you may not require() inside of a try/catch block
try {
require(unsafeModule);
} catch (e) {
console.log(e);
}
:::
Examples of correct code for this rule:
::: correct
/*eslint global-require: "error"*/
// all these variations of require() are ok
require("x");
var y = require("y");
var z;
z = require("z").initialize();
// requiring a module and using it in a function is ok
var fs = require("fs");
function readFile(filename, callback) {
fs.readFile(filename, callback);
}
// you can use a ternary to determine which module to require
var logger = DEBUG ? require("dev-logger") : require("logger");
// if you want you can require() at the end of your module
function doSomethingA() {}
function doSomethingB() {}
var x = require("x"),
z = require("z");
:::
When Not To Use It
If you have a module that must be initialized with information that comes from the file-system or if a module is only used in very rare situations and will cause significant overhead to load it may make sense to disable the rule. If you need to require()
an optional dependency inside of a try
/catch
, you can disable this rule for just that dependency using the // eslint-disable-line global-require
comment.
Source: http://eslint.org/docs/rules/
Definition for rule 'node/no-restricted-import' was not found. Open
import { createSelector } from 'reselect';
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Prop spreading is forbidden Open
component = shallow(<Translate {...props}>Search</Translate>);
- 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 api from 'app/utils/api';
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Prop spreading is forbidden Open
component = shallow(<Connection {...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
import { advancedSort } from '../advancedSort';
- 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 configureMockStore from 'redux-mock-store';
- 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 { fromJS as Immutable } from 'immutable';
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
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/
Prop type "object" is forbidden Open
relationTypes: PropTypes.object,
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Prefer named exports. Open
export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(Document);
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Expected to return a value at the end of function. Open
return function () {
- 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/
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/
Expected 'this' to be used by class method 'handleOver'. Open
handleOver() {}
- Read upRead up
- Exclude checks
title: class-methods-use-this ruletype: suggestion furtherreading: - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/static
If a class method does not use this
, it can sometimes be made into a static function. If you do convert the method into a static function, instances of the class that call that particular method have to be converted to a static call as well (MyClass.callStaticMethod()
)
It's possible to have a class method which doesn't use this
, such as:
class A {
constructor() {
this.a = "hi";
}
print() {
console.log(this.a);
}
sayHi() {
console.log("hi");
}
}
let a = new A();
a.sayHi(); // => "hi"
In the example above, the sayHi
method doesn't use this
, so we can make it a static method:
class A {
constructor() {
this.a = "hi";
}
print() {
console.log(this.a);
}
static sayHi() {
console.log("hi");
}
}
A.sayHi(); // => "hi"
Also note in the above examples that if you switch a method to a static method, instances of the class that call the static method (let a = new A(); a.sayHi();
) have to be updated to being a static call (A.sayHi();
) instead of having the instance of the class call the method
Rule Details
This rule is aimed to flag class methods that do not use this
.
Examples of incorrect code for this rule:
::: incorrect
/*eslint class-methods-use-this: "error"*/
/*eslint-env es6*/
class A {
foo() {
console.log("Hello World"); /*error Expected 'this' to be used by class method 'foo'.*/
}
}
:::
Examples of correct code for this rule:
::: correct
/*eslint class-methods-use-this: "error"*/
/*eslint-env es6*/
class A {
foo() {
this.bar = "Hello World"; // OK, this is used
}
}
class A {
constructor() {
// OK. constructor is exempt
}
}
class A {
static foo() {
// OK. static methods aren't expected to use this.
}
static {
// OK. static blocks are exempt.
}
}
:::
Options
This rule has two options:
-
"exceptMethods"
allows specified method names to be ignored with this rule. -
"enforceForClassFields"
enforces that functions used as instance field initializers utilizethis
. (default:true
)
exceptMethods
"class-methods-use-this": [<enabled>, { "exceptMethods": [<...exceptions>] }]</enabled>
The "exceptMethods"
option allows you to pass an array of method names for which you would like to ignore warnings. For example, you might have a spec from an external library that requires you to overwrite a method as a regular function (and not as a static method) and does not use this
inside the function body. In this case, you can add that method to ignore in the warnings.
Examples of incorrect code for this rule when used without "exceptMethods"
:
::: incorrect
/*eslint class-methods-use-this: "error"*/
class A {
foo() {
}
}
:::
Examples of correct code for this rule when used with exceptMethods:
::: correct
/*eslint class-methods-use-this: ["error", { "exceptMethods": ["foo", "#bar"] }] */
class A {
foo() {
}
#bar() {
}
}
:::
enforceForClassFields
"class-methods-use-this": [<enabled>, { "enforceForClassFields": true | false }]</enabled>
The enforceForClassFields
option enforces that arrow functions and function expressions used as instance field initializers utilize this
. (default: true
)
Examples of incorrect code for this rule with the { "enforceForClassFields": true }
option (default):
::: incorrect
/*eslint class-methods-use-this: ["error", { "enforceForClassFields": true }] */
class A {
foo = () => {}
}
:::
Examples of correct code for this rule with the { "enforceForClassFields": true }
option (default):
::: correct
/*eslint class-methods-use-this: ["error", { "enforceForClassFields": true }] */
class A {
foo = () => {this;}
}
:::
Examples of correct code for this rule with the { "enforceForClassFields": false }
option:
::: correct
/*eslint class-methods-use-this: ["error", { "enforceForClassFields": false }] */
class A {
foo = () => {}
}
::: Source: http://eslint.org/docs/rules/
Definition for rule 'node/no-restricted-import' was not found. Open
import referencesAPI from 'app/Viewer/referencesAPI';
- 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 { actions } from 'app/BasicReducer';
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/