Function onnotificationclick
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
self.onnotificationclick = function(event) {
var link, origin, href;
if (
typeof event.notification.data.link !== 'undefined' &&
Function onnotificationclick
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
self.onnotificationclick = function(event) {
var link, origin, href;
if (
typeof event.notification.data.link !== '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
The Function constructor is eval. Open
var func = new Function(funcStr);
- Read upRead up
- Exclude checks
Disallow Function Constructor (no-new-func)
It's possible to create functions in JavaScript using the Function
constructor, such as:
var x = new Function("a", "b", "return a + b");
This is considered by many to be a bad practice due to the difficulty in debugging and reading these types of functions.
Rule Details
This error is raised to highlight the use of a bad practice. By passing a string to the Function constructor, you are requiring the engine to parse that string much in the way it has to when you call the eval
function.
Examples of incorrect code for this rule:
/*eslint no-new-func: "error"*/
var x = new Function("a", "b", "return a + b");
var x = Function("a", "b", "return a + b");
Examples of correct code for this rule:
/*eslint no-new-func: "error"*/
var x = function (a, b) {
return a + b;
};
When Not To Use It
In more advanced cases where you really need to use the Function
constructor.
Source: http://eslint.org/docs/rules/