Function prepareResult
has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring. Wontfix
D0Protocol.prototype.prepareResult = function prepareResult(data) {
var splitted = data.split(')');
var result = {};
var currentObis = null;
- 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
File D0Protocol.js
has 373 lines of code (exceeds 250 allowed). Consider refactoring. Wontfix
/* jshint -W097 */
// jshint strict:true
/*jslint node: true */
/*jslint esversion: 6 */
'use strict';
Function handleMessage
has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring. Wontfix
D0Protocol.prototype.handleMessage = function handleMessage(message) {
if (this.options.debug === 2) this.options.logger('CURRENT PROCESS STEP ' + this.communicationState + ' IN HANDLEMESSAGE');
message = message.toString();
var regMessage;
if (this.communicationState === 2) {
- 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 'prepareResult' has too many statements (47). Maximum allowed is 30. Wontfix
D0Protocol.prototype.prepareResult = function prepareResult(data) {
- Read upRead up
- Exclude checks
enforce a maximum number of statements allowed in function blocks (max-statements)
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:
/*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:
/*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;
};
}
ignoreTopLevelFunctions
Examples of additional correct code for this rule with the { "max": 10 }, { "ignoreTopLevelFunctions": true }
options:
/*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;
}
Related Rules
- [complexity](complexity.md)
- [max-depth](max-depth.md)
- [max-len](max-len.md)
- [max-nested-callbacks](max-nested-callbacks.md)
- [max-params](max-params.md) Source: http://eslint.org/docs/rules/
Function handleSignOnResponseMessage
has 83 lines of code (exceeds 25 allowed). Consider refactoring. Wontfix
D0Protocol.prototype.handleSignOnResponseMessage = function handleSignOnResponseMessage(dataString) {
if (dataString.charAt(0) === '/') {
this.deviceManufacturer = dataString.substring(1,4);
switch (dataString.charAt(4)) {
case 'A':
Function handleSignOnResponseMessage
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Wontfix
D0Protocol.prototype.handleSignOnResponseMessage = function handleSignOnResponseMessage(dataString) {
if (dataString.charAt(0) === '/') {
this.deviceManufacturer = dataString.substring(1,4);
switch (dataString.charAt(4)) {
case 'A':
- 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 getNextMessage
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Wontfix
D0Protocol.prototype.getNextMessage = function getNextMessage(commObj, callback) {
if (this.options.debug === 2) this.options.logger('CURRENT PROCESS STEP ' + this.communicationState + ' IN GETNEXTMESSAGE');
var init = '';
if (this.communicationState === 0) {
this.communicationState = 1;
- 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 prepareResult
has 72 lines of code (exceeds 25 allowed). Consider refactoring. Wontfix
D0Protocol.prototype.prepareResult = function prepareResult(data) {
var splitted = data.split(')');
var result = {};
var currentObis = null;
Function 'handleMessage' has too many statements (35). Maximum allowed is 30. Wontfix
D0Protocol.prototype.handleMessage = function handleMessage(message) {
- Read upRead up
- Exclude checks
enforce a maximum number of statements allowed in function blocks (max-statements)
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:
/*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:
/*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;
};
}
ignoreTopLevelFunctions
Examples of additional correct code for this rule with the { "max": 10 }, { "ignoreTopLevelFunctions": true }
options:
/*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;
}
Related Rules
- [complexity](complexity.md)
- [max-depth](max-depth.md)
- [max-len](max-len.md)
- [max-nested-callbacks](max-nested-callbacks.md)
- [max-params](max-params.md) Source: http://eslint.org/docs/rules/
Function checkMessage
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Wontfix
D0Protocol.prototype.checkMessage = function checkMessage(message) {
if (this.options.debug === 2) this.options.logger('CURRENT PROCESS STEP ' + this.communicationState + ' IN CHECKMESSAGE');
message = message.toString();
var regMessage;
if (this.communicationState === 2 || this.communicationState === 0) {
- 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 handleMessage
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Wontfix
D0Protocol.prototype.handleMessage = function handleMessage(message) {
if (this.options.debug === 2) this.options.logger('CURRENT PROCESS STEP ' + this.communicationState + ' IN HANDLEMESSAGE');
message = message.toString();
var regMessage;
if (this.communicationState === 2) {
Function getNextMessage
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Wontfix
D0Protocol.prototype.getNextMessage = function getNextMessage(commObj, callback) {
if (this.options.debug === 2) this.options.logger('CURRENT PROCESS STEP ' + this.communicationState + ' IN GETNEXTMESSAGE');
var init = '';
if (this.communicationState === 0) {
this.communicationState = 1;
Function callUserCallback
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Wontfix
D0Protocol.prototype.callUserCallback = function callUserCallback(err, data) {
if (err) {
if (this.options.debug !== 0) this.options.logger(err);
}
if (typeof this.storeCallback === 'function') {
- 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 messagesToSend
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Wontfix
D0Protocol.prototype.messagesToSend = function messagesToSend() {
if (this.communicationState === 0) return 2; // init case, need to send WakeUp and Signon-message
if (this.communicationState === 1) return 1; // init case, need to send one Signon-message (should never happen)
if (this.communicationState === 3) {
if (this.commMode === 'C' || this.commMode === 'E') return 2; // Mode with Ack AND Baudrate-Change afterwards
- 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
Avoid deeply nested control flow statements. Open
if (!commObj || typeof commObj.update !== 'function') {
this.callUserCallback(new Error('Serialport instance needed for baudrate changeover'), null);
callback('');
return;
}
Avoid deeply nested control flow statements. Wontfix
if (this.options.debug === 2) this.options.logger('BAUD CHANGEOVER TO ' + this.commBaudrateChangeover + ' baud');
Avoid deeply nested control flow statements. Wontfix
if (self.options.debug === 2) self.options.logger('BAUD CHANGEOVER DONE');
Avoid deeply nested control flow statements. Wontfix
if (value[0].indexOf('.')!==-1) value[0]=parseFloat(value[0]);
else value[0]=parseInt(value[0],10);
Avoid deeply nested control flow statements. Wontfix
if (error) {
self.options.logger('EROR ON BAUD CHANGEOVER!');
}
Avoid too many return
statements within this function. Open
return Buffer.from(message.substr(idx+regMessage[1].length+2));
Avoid too many return
statements within this function. Wontfix
return;
Avoid too many return
statements within this function. Wontfix
return 0;
Avoid too many return
statements within this function. Wontfix
if (this.commBaudrateInitial !== this.commBaudrateChangeover) return 1; // We need to do a baudrate change
Avoid too many return
statements within this function. Wontfix
return null;
Avoid too many return
statements within this function. Open
return Buffer.from(message.substr(idx+regMessage[1].length+2));
'idx' is already defined. Open
var idx = message.indexOf(regMessage[1]);
- Read upRead up
- Exclude checks
disallow variable redeclaration (no-redeclare)
In JavaScript, it's possible to redeclare the same variable name using var
. This can lead to confusion as to where the variable is actually declared and initialized.
Rule Details
This rule is aimed at eliminating variables that have multiple declarations in the same scope.
Examples of incorrect code for this rule:
/*eslint no-redeclare: "error"*/
var a = 3;
var a = 10;
Examples of correct code for this rule:
/*eslint no-redeclare: "error"*/
var a = 3;
// ...
a = 10;
Options
This rule takes one optional argument, an object with a boolean property "builtinGlobals"
. It defaults to false
.
If set to true
, this rule also checks redeclaration of built-in globals, such as Object
, Array
, Number
...
builtinGlobals
Examples of incorrect code for the { "builtinGlobals": true }
option:
/*eslint no-redeclare: ["error", { "builtinGlobals": true }]*/
var Object = 0;
Examples of incorrect code for the { "builtinGlobals": true }
option and the browser
environment:
/*eslint no-redeclare: ["error", { "builtinGlobals": true }]*/
/*eslint-env browser*/
var top = 0;
The browser
environment has many built-in global variables (for example, top
). Some of built-in global variables cannot be redeclared.
Source: http://eslint.org/docs/rules/