Function UNIQUE
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
exports.UNIQUE = function () {
var result = [];
for (var i = 0; i < arguments.length; ++i) {
var hasElement = false;
var element = arguments[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 REFERENCE
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
exports.REFERENCE = function (context, reference) {
if (!arguments.length) {
return error.error;
}
try {
- 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
Empty block statement. Open
} catch (error) {}
- Read upRead up
- Exclude checks
disallow empty block statements (no-empty)
Empty block statements, while not technically errors, usually occur due to refactoring that wasn't completed. They can cause confusion when reading code.
Rule Details
This rule disallows empty block statements. This rule ignores block statements which contain a comment (for example, in an empty catch
or finally
block of a try
statement to indicate that execution should continue regardless of errors).
Examples of incorrect code for this rule:
/*eslint no-empty: "error"*/
if (foo) {
}
while (foo) {
}
switch(foo) {
}
try {
doSomething();
} catch(ex) {
} finally {
}
Examples of correct code for this rule:
/*eslint no-empty: "error"*/
if (foo) {
// empty
}
while (foo) {
/* empty */
}
try {
doSomething();
} catch (ex) {
// continue regardless of error
}
try {
doSomething();
} finally {
/* continue regardless of error */
}
Options
This rule has an object option for exceptions:
-
"allowEmptyCatch": true
allows emptycatch
clauses (that is, which do not contain a comment)
allowEmptyCatch
Examples of additional correct code for this rule with the { "allowEmptyCatch": true }
option:
/* eslint no-empty: ["error", { "allowEmptyCatch": true }] */
try {
doSomething();
} catch (ex) {}
try {
doSomething();
}
catch (ex) {}
finally {
/* continue regardless of error */
}
When Not To Use It
If you intentionally use empty block statements then you can disable this rule.
Related Rules
- [no-empty-function](./no-empty-function.md) Source: http://eslint.org/docs/rules/
Value of 'error' may be overwritten in IE 8 and earlier. Open
} catch (error) {}
- Read upRead up
- Exclude checks
Disallow Shadowing of Variables Inside of catch (no-catch-shadow)
In IE 8 and earlier, the catch clause parameter can overwrite the value of a variable in the outer scope, if that variable has the same name as the catch clause parameter.
var err = "x";
try {
throw "problem";
} catch (err) {
}
console.log(err) // err is 'problem', not 'x'
Rule Details
This rule is aimed at preventing unexpected behavior in your program that may arise from a bug in IE 8 and earlier, in which the catch clause parameter can leak into outer scopes. This rule will warn whenever it encounters a catch clause parameter that has the same name as a variable in an outer scope.
Examples of incorrect code for this rule:
/*eslint no-catch-shadow: "error"*/
var err = "x";
try {
throw "problem";
} catch (err) {
}
function err() {
// ...
};
try {
throw "problem";
} catch (err) {
}
Examples of correct code for this rule:
/*eslint no-catch-shadow: "error"*/
var err = "x";
try {
throw "problem";
} catch (e) {
}
function err() {
// ...
};
try {
throw "problem";
} catch (e) {
}
When Not To Use It
If you do not need to support IE 8 and earlier, you should turn this rule off. Source: http://eslint.org/docs/rules/