Apollon77/smartmeter-obis

View on GitHub
lib/protocols/D0Protocol.js

Summary

Maintainability
A
1 hr
Test Coverage
C
75%

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;
Severity: Minor
Found in lib/protocols/D0Protocol.js - About 7 hrs to fix

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';
Severity: Minor
Found in lib/protocols/D0Protocol.js - About 4 hrs to fix

    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) {
    Severity: Minor
    Found in lib/protocols/D0Protocol.js - About 4 hrs to fix

    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) {
    Severity: Minor
    Found in lib/protocols/D0Protocol.js by eslint

    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" (default 10) 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':
    Severity: Major
    Found in lib/protocols/D0Protocol.js - About 3 hrs to fix

      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':
      Severity: Minor
      Found in lib/protocols/D0Protocol.js - About 3 hrs to fix

      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;
      Severity: Minor
      Found in lib/protocols/D0Protocol.js - About 2 hrs to fix

      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;
      Severity: Major
      Found in lib/protocols/D0Protocol.js - About 2 hrs to fix

        Function 'handleMessage' has too many statements (35). Maximum allowed is 30.
        Wontfix

        D0Protocol.prototype.handleMessage = function handleMessage(message) {
        Severity: Minor
        Found in lib/protocols/D0Protocol.js by eslint

        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" (default 10) 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) {
        Severity: Minor
        Found in lib/protocols/D0Protocol.js - About 2 hrs to fix

        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) {
        Severity: Minor
        Found in lib/protocols/D0Protocol.js - About 2 hrs to fix

          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;
          Severity: Minor
          Found in lib/protocols/D0Protocol.js - About 1 hr to fix

            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') {
            Severity: Minor
            Found in lib/protocols/D0Protocol.js - About 1 hr to fix

            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
            Severity: Minor
            Found in lib/protocols/D0Protocol.js - About 55 mins to fix

            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;
                        }
            Severity: Major
            Found in lib/protocols/D0Protocol.js - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Wontfix

                          if (this.options.debug === 2) this.options.logger('BAUD CHANGEOVER TO ' + this.commBaudrateChangeover + ' baud');
              Severity: Major
              Found in lib/protocols/D0Protocol.js - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Wontfix

                                if (self.options.debug === 2) self.options.logger('BAUD CHANGEOVER DONE');
                Severity: Major
                Found in lib/protocols/D0Protocol.js - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Wontfix

                                      if (value[0].indexOf('.')!==-1) value[0]=parseFloat(value[0]);
                                        else value[0]=parseInt(value[0],10);
                  Severity: Major
                  Found in lib/protocols/D0Protocol.js - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Wontfix

                                    if (error) {
                                        self.options.logger('EROR ON BAUD CHANGEOVER!');
                                    }
                    Severity: Major
                    Found in lib/protocols/D0Protocol.js - About 45 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                      return Buffer.from(message.substr(idx+regMessage[1].length+2));
                      Severity: Major
                      Found in lib/protocols/D0Protocol.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Wontfix

                                    return;
                        Severity: Major
                        Found in lib/protocols/D0Protocol.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Wontfix

                              return 0;
                          Severity: Major
                          Found in lib/protocols/D0Protocol.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Wontfix

                                    if (this.commBaudrateInitial !== this.commBaudrateChangeover) return 1; // We need to do a baudrate change
                            Severity: Major
                            Found in lib/protocols/D0Protocol.js - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Wontfix

                                  return null;
                              Severity: Major
                              Found in lib/protocols/D0Protocol.js - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                                return Buffer.from(message.substr(idx+regMessage[1].length+2));
                                Severity: Major
                                Found in lib/protocols/D0Protocol.js - About 30 mins to fix

                                  'idx' is already defined.
                                  Open

                                          var idx = message.indexOf(regMessage[1]);
                                  Severity: Minor
                                  Found in lib/protocols/D0Protocol.js by eslint

                                  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/

                                  There are no issues that match your filters.

                                  Category
                                  Status