Apollon77/smartmeter-obis

View on GitHub
lib/transports/SerialRequestResponseTransport.js

Summary

Maintainability
C
7 hrs
Test Coverage
B
85%

Function init has 185 lines of code (exceeds 25 allowed). Consider refactoring.
Wontfix

SerialRequestResponseTransport.prototype.init = function init() {
    this.protocol.initState(); // init State from protocol instance

    var self = this;
    if (!this.serialComm) {
Severity: Major
Found in lib/transports/SerialRequestResponseTransport.js - About 7 hrs to fix

    Function has too many statements (57). Maximum allowed is 30.
    Open

            this.serialComm.on('data', function (data) {

    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/

    File SerialRequestResponseTransport.js has 337 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/transports/SerialRequestResponseTransport.js - About 4 hrs to fix

      Function process has 57 lines of code (exceeds 25 allowed). Consider refactoring.
      Wontfix

      SerialRequestResponseTransport.prototype.process = function process() {
          this.protocol.initState();
          this.currentData = null;
          this.currentDataOffset = 0;
          var self = this;
      Severity: Major
      Found in lib/transports/SerialRequestResponseTransport.js - About 2 hrs to fix

        Function scheduleNextRun has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Wontfix

        SerialRequestResponseTransport.prototype.scheduleNextRun = function scheduleNextRun() {
            if (!this.stopRequests) {
                if (this.requestTimer) {
                    clearTimeout(this.requestTimer);
                    this.requestTimer = null;
        Severity: Minor
        Found in lib/transports/SerialRequestResponseTransport.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 finalizeMessageHandling has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                        function finalizeMessageHandling() {
                            if (self.options.debug === 2) self.options.logger('RESUME READING SERIALPORT IN FINALIZE');
                            if (self.serialComm && !self.stopRequests) self.serialComm.resume(); // we want to read continously
        
                            if (self.options.debug === 2) self.options.logger('SET MESSAGE TIMEOUT TIMER: ' + self.options.transportSerialMessageTimeout);
        Severity: Minor
        Found in lib/transports/SerialRequestResponseTransport.js - About 1 hr to fix

          Function sendOutMessages has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                          function sendOutMessages(messagesToSend) {
                              if (messagesToSend > 0) {
                                  self.protocol.getNextMessage(self.serialComm, function(nextData) {
                                      if (self.options.debug === 2) self.options.logger('TO SEND ' + messagesToSend + ': ' + nextData);
                                      if (typeof nextData === 'string' || typeof nextData === 'object') {
          Severity: Minor
          Found in lib/transports/SerialRequestResponseTransport.js - About 1 hr to fix

            Function SerialRequestResponseTransport has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Wontfix

            function SerialRequestResponseTransport(options, protocol) {
                this.options = options;
                this.protocol = protocol;
                this.serialConnected = false;
                this.serialComm = undefined;
            Severity: Minor
            Found in lib/transports/SerialRequestResponseTransport.js - About 1 hr to fix

              Function scheduleNextRun has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              SerialRequestResponseTransport.prototype.scheduleNextRun = function scheduleNextRun() {
                  if (!this.stopRequests) {
                      if (this.requestTimer) {
                          clearTimeout(this.requestTimer);
                          this.requestTimer = null;
              Severity: Minor
              Found in lib/transports/SerialRequestResponseTransport.js - About 1 hr to fix

                Function stop has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                SerialRequestResponseTransport.prototype.stop = function stop(callback) {
                    if (this.options.debug === 2) this.options.logger('STOP');
                    this.stopRequests = true;
                    if (this.requestTimer) {
                        clearTimeout(this.requestTimer);
                Severity: Minor
                Found in lib/transports/SerialRequestResponseTransport.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 (err) {
                                                    self.options.logger('ERROR CLOSING SERIALPORT: ' + err);
                                                }
                Severity: Major
                Found in lib/transports/SerialRequestResponseTransport.js - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                                  if (self.serialComm && nextData.length > 0) {
                                                      self.serialComm.write(nextData, function () {
                                                          self.serialComm.drain(function() {
                                                              if (self.options.debug === 2) self.options.logger('DONE SEND ' + messagesToSend);
                                                              setTimeout(function() {
                  Severity: Major
                  Found in lib/transports/SerialRequestResponseTransport.js - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                    if (self.options.debug === 2) self.options.logger('DELETE all data (' + self.currentDataOffset + ') because of Buffer overrun missed data');
                    Severity: Major
                    Found in lib/transports/SerialRequestResponseTransport.js - About 45 mins to fix

                      Function SerialRequestResponseTransport has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                      Wontfix

                      function SerialRequestResponseTransport(options, protocol) {
                          this.options = options;
                          this.protocol = protocol;
                          this.serialConnected = false;
                          this.serialComm = undefined;
                      Severity: Minor
                      Found in lib/transports/SerialRequestResponseTransport.js - About 45 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 too many return statements within this function.
                      Open

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

                        Avoid too many return statements within this function.
                        Open

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

                          Expected an assignment or function call and instead saw an expression.
                          Open

                                                                  self.serialComm && self.serialComm.drain(function() {

                          Disallow Unused Expressions (no-unused-expressions)

                          An unused expression which has no effect on the state of the program indicates a logic error.

                          For example, n + 1; is not a syntax error, but it might be a typing mistake where a programmer meant an assignment statement n += 1; instead.

                          Rule Details

                          This rule aims to eliminate unused expressions which have no effect on the state of the program.

                          This rule does not apply to function calls or constructor calls with the new operator, because they could have side effects on the state of the program.

                          var i = 0;
                          function increment() { i += 1; }
                          increment(); // return value is unused, but i changed as a side effect
                          
                          var nThings = 0;
                          function Thing() { nThings += 1; }
                          new Thing(); // constructed object is unused, but nThings changed as a side effect

                          This rule does not apply to directives (which are in the form of literal string expressions such as "use strict"; at the beginning of a script, module, or function).

                          Sequence expressions (those using a comma, such as a = 1, b = 2) are always considered unused unless their return value is assigned or used in a condition evaluation, or a function call is made with the sequence expression value.

                          Options

                          This rule, in its default state, does not require any arguments. If you would like to enable one or more of the following you may pass an object with the options set as follows:

                          • allowShortCircuit set to true will allow you to use short circuit evaluations in your expressions (Default: false).
                          • allowTernary set to true will enable you to use ternary operators in your expressions similarly to short circuit evaluations (Default: false).
                          • allowTaggedTemplates set to true will enable you to use tagged template literals in your expressions (Default: false).

                          These options allow unused expressions only if all of the code paths either directly change the state (for example, assignment statement) or could have side effects (for example, function call).

                          Examples of incorrect code for the default { "allowShortCircuit": false, "allowTernary": false } options:

                          /*eslint no-unused-expressions: "error"*/
                          
                          0
                          
                          if(0) 0
                          
                          {0}
                          
                          f(0), {}
                          
                          a && b()
                          
                          a, b()
                          
                          c = a, b;
                          
                          a() && function namedFunctionInExpressionContext () {f();}
                          
                          (function anIncompleteIIFE () {});
                          
                          injectGlobal`body{ color: red; }`

                          Note that one or more string expression statements (with or without semi-colons) will only be considered as unused if they are not in the beginning of a script, module, or function (alone and uninterrupted by other statements). Otherwise, they will be treated as part of a "directive prologue", a section potentially usable by JavaScript engines. This includes "strict mode" directives.

                          "use strict";
                          "use asm"
                          "use stricter";
                          "use babel"
                          "any other strings like this in the prologue";

                          Examples of correct code for the default { "allowShortCircuit": false, "allowTernary": false } options:

                          /*eslint no-unused-expressions: "error"*/
                          
                          {} // In this context, this is a block statement, not an object literal
                          
                          {myLabel: someVar} // In this context, this is a block statement with a label and expression, not an object literal
                          
                          function namedFunctionDeclaration () {}
                          
                          (function aGenuineIIFE () {}());
                          
                          f()
                          
                          a = 0
                          
                          new C
                          
                          delete a.b
                          
                          void a

                          allowShortCircuit

                          Examples of incorrect code for the { "allowShortCircuit": true } option:

                          /*eslint no-unused-expressions: ["error", { "allowShortCircuit": true }]*/
                          
                          a || b

                          Examples of correct code for the { "allowShortCircuit": true } option:

                          /*eslint no-unused-expressions: ["error", { "allowShortCircuit": true }]*/
                          
                          a && b()
                          a() || (b = c)

                          allowTernary

                          Examples of incorrect code for the { "allowTernary": true } option:

                          /*eslint no-unused-expressions: ["error", { "allowTernary": true }]*/
                          
                          a ? b : 0
                          a ? b : c()

                          Examples of correct code for the { "allowTernary": true } option:

                          /*eslint no-unused-expressions: ["error", { "allowTernary": true }]*/
                          
                          a ? b() : c()
                          a ? (b = c) : d()

                          allowShortCircuit and allowTernary

                          Examples of correct code for the { "allowShortCircuit": true, "allowTernary": true } options:

                          /*eslint no-unused-expressions: ["error", { "allowShortCircuit": true, "allowTernary": true }]*/
                          
                          a ? b() || (c = d) : e()

                          allowTaggedTemplates

                          Examples of incorrect code for the { "allowTaggedTemplates": true } option:

                          /*eslint no-unused-expressions: ["error", { "allowTaggedTemplates": true }]*/
                          
                          `some untagged template string`;

                          Examples of correct code for the { "allowTaggedTemplates": true } option:

                          /*eslint no-unused-expressions: ["error", { "allowTaggedTemplates": true }]*/
                          
                          tag`some tagged template string`;

                          Source: http://eslint.org/docs/rules/

                          Expected return with your callback function.
                          Open

                                      if (callback) callback();

                          Enforce Return After Callback (callback-return)

                          The callback pattern is at the heart of most I/O and event-driven programming in JavaScript.

                          function doSomething(err, callback) {
                              if (err) {
                                  return callback(err);
                              }
                              callback();
                          }

                          To prevent calling the callback multiple times it is important to return anytime the callback is triggered outside of the main function body. Neglecting this technique often leads to issues where you do something more than once. For example, in the case of an HTTP request, you may try to send HTTP headers more than once leading Node.js to throw a Can't render headers after they are sent to the client. error.

                          Rule Details

                          This rule is aimed at ensuring that callbacks used outside of the main function block are always part-of or immediately preceding a return statement. This rule decides what is a callback based on the name of the function being called.

                          Options

                          The rule takes a single option - an array of possible callback names - which may include object methods. The default callback names are callback, cb, next.

                          Default callback names

                          Examples of incorrect code for this rule with the default ["callback", "cb", "next"] option:

                          /*eslint callback-return: "error"*/
                          
                          function foo(err, callback) {
                              if (err) {
                                  callback(err);
                              }
                              callback();
                          }

                          Examples of correct code for this rule with the default ["callback", "cb", "next"] option:

                          /*eslint callback-return: "error"*/
                          
                          function foo(err, callback) {
                              if (err) {
                                  return callback(err);
                              }
                              callback();
                          }

                          Supplied callback names

                          Examples of incorrect code for this rule with the option ["done", "send.error", "send.success"]:

                          /*eslint callback-return: ["error", ["done", "send.error", "send.success"]]*/
                          
                          function foo(err, done) {
                              if (err) {
                                  done(err);
                              }
                              done();
                          }
                          
                          function bar(err, send) {
                              if (err) {
                                  send.error(err);
                              }
                              send.success();
                          }

                          Examples of correct code for this rule with the option ["done", "send.error", "send.success"]:

                          /*eslint callback-return: ["error", ["done", "send.error", "send.success"]]*/
                          
                          function foo(err, done) {
                              if (err) {
                                  return done(err);
                              }
                              done();
                          }
                          
                          function bar(err, send) {
                              if (err) {
                                  return send.error(err);
                              }
                              send.success();
                          }

                          Known Limitations

                          Because it is difficult to understand the meaning of a program through static analysis, this rule has limitations:

                          • false negatives when this rule reports correct code, but the program calls the callback more than one time (which is incorrect behavior)
                          • false positives when this rule reports incorrect code, but the program calls the callback only one time (which is correct behavior)

                          Passing the callback by reference

                          The static analysis of this rule does not detect that the program calls the callback if it is an argument of a function (for example, setTimeout).

                          Example of a false negative when this rule reports correct code:

                          /*eslint callback-return: "error"*/
                          
                          function foo(err, callback) {
                              if (err) {
                                  setTimeout(callback, 0); // this is bad, but WILL NOT warn
                              }
                              callback();
                          }

                          Triggering the callback within a nested function

                          The static analysis of this rule does not detect that the program calls the callback from within a nested function or an immediately-invoked function expression (IIFE).

                          Example of a false negative when this rule reports correct code:

                          /*eslint callback-return: "error"*/
                          
                          function foo(err, callback) {
                              if (err) {
                                  process.nextTick(function() {
                                      return callback(); // this is bad, but WILL NOT warn
                                  });
                              }
                              callback();
                          }

                          If/else statements

                          The static analysis of this rule does not detect that the program calls the callback only one time in each branch of an if statement.

                          Example of a false positive when this rule reports incorrect code:

                          /*eslint callback-return: "error"*/
                          
                          function foo(err, callback) {
                              if (err) {
                                  callback(err); // this is fine, but WILL warn
                              } else {
                                  callback();    // this is fine, but WILL warn
                              }
                          }

                          When Not To Use It

                          There are some cases where you might want to call a callback function more than once. In those cases this rule may lead to incorrect behavior. In those cases you may want to reserve a special name for those callbacks and not include that in the list of callbacks that trigger warnings.

                          Further Reading

                          Related Rules

                          Expected return with your callback function.
                          Open

                                  if (callback) callback();

                          Enforce Return After Callback (callback-return)

                          The callback pattern is at the heart of most I/O and event-driven programming in JavaScript.

                          function doSomething(err, callback) {
                              if (err) {
                                  return callback(err);
                              }
                              callback();
                          }

                          To prevent calling the callback multiple times it is important to return anytime the callback is triggered outside of the main function body. Neglecting this technique often leads to issues where you do something more than once. For example, in the case of an HTTP request, you may try to send HTTP headers more than once leading Node.js to throw a Can't render headers after they are sent to the client. error.

                          Rule Details

                          This rule is aimed at ensuring that callbacks used outside of the main function block are always part-of or immediately preceding a return statement. This rule decides what is a callback based on the name of the function being called.

                          Options

                          The rule takes a single option - an array of possible callback names - which may include object methods. The default callback names are callback, cb, next.

                          Default callback names

                          Examples of incorrect code for this rule with the default ["callback", "cb", "next"] option:

                          /*eslint callback-return: "error"*/
                          
                          function foo(err, callback) {
                              if (err) {
                                  callback(err);
                              }
                              callback();
                          }

                          Examples of correct code for this rule with the default ["callback", "cb", "next"] option:

                          /*eslint callback-return: "error"*/
                          
                          function foo(err, callback) {
                              if (err) {
                                  return callback(err);
                              }
                              callback();
                          }

                          Supplied callback names

                          Examples of incorrect code for this rule with the option ["done", "send.error", "send.success"]:

                          /*eslint callback-return: ["error", ["done", "send.error", "send.success"]]*/
                          
                          function foo(err, done) {
                              if (err) {
                                  done(err);
                              }
                              done();
                          }
                          
                          function bar(err, send) {
                              if (err) {
                                  send.error(err);
                              }
                              send.success();
                          }

                          Examples of correct code for this rule with the option ["done", "send.error", "send.success"]:

                          /*eslint callback-return: ["error", ["done", "send.error", "send.success"]]*/
                          
                          function foo(err, done) {
                              if (err) {
                                  return done(err);
                              }
                              done();
                          }
                          
                          function bar(err, send) {
                              if (err) {
                                  return send.error(err);
                              }
                              send.success();
                          }

                          Known Limitations

                          Because it is difficult to understand the meaning of a program through static analysis, this rule has limitations:

                          • false negatives when this rule reports correct code, but the program calls the callback more than one time (which is incorrect behavior)
                          • false positives when this rule reports incorrect code, but the program calls the callback only one time (which is correct behavior)

                          Passing the callback by reference

                          The static analysis of this rule does not detect that the program calls the callback if it is an argument of a function (for example, setTimeout).

                          Example of a false negative when this rule reports correct code:

                          /*eslint callback-return: "error"*/
                          
                          function foo(err, callback) {
                              if (err) {
                                  setTimeout(callback, 0); // this is bad, but WILL NOT warn
                              }
                              callback();
                          }

                          Triggering the callback within a nested function

                          The static analysis of this rule does not detect that the program calls the callback from within a nested function or an immediately-invoked function expression (IIFE).

                          Example of a false negative when this rule reports correct code:

                          /*eslint callback-return: "error"*/
                          
                          function foo(err, callback) {
                              if (err) {
                                  process.nextTick(function() {
                                      return callback(); // this is bad, but WILL NOT warn
                                  });
                              }
                              callback();
                          }

                          If/else statements

                          The static analysis of this rule does not detect that the program calls the callback only one time in each branch of an if statement.

                          Example of a false positive when this rule reports incorrect code:

                          /*eslint callback-return: "error"*/
                          
                          function foo(err, callback) {
                              if (err) {
                                  callback(err); // this is fine, but WILL warn
                              } else {
                                  callback();    // this is fine, but WILL warn
                              }
                          }

                          When Not To Use It

                          There are some cases where you might want to call a callback function more than once. In those cases this rule may lead to incorrect behavior. In those cases you may want to reserve a special name for those callbacks and not include that in the list of callbacks that trigger warnings.

                          Further Reading

                          Related Rules

                          Move function declaration to function body root.
                          Wontfix

                                          function sendOutMessages(messagesToSend) {

                          disallow variable or function declarations in nested blocks (no-inner-declarations)

                          In JavaScript, prior to ES6, a function declaration is only allowed in the first level of a program or the body of another function, though parsers sometimes erroneously accept them elsewhere. This only applies to function declarations; named or anonymous function expressions can occur anywhere an expression is permitted.

                          // Good
                          function doSomething() { }
                          
                          // Bad
                          if (test) {
                              function doSomethingElse () { }
                          }
                          
                          function anotherThing() {
                              var fn;
                          
                              if (test) {
                          
                                  // Good
                                  fn = function expression() { };
                          
                                  // Bad
                                  function declaration() { }
                              }
                          }

                          A variable declaration is permitted anywhere a statement can go, even nested deeply inside other blocks. This is often undesirable due to variable hoisting, and moving declarations to the root of the program or function body can increase clarity. Note that block bindings (let, const) are not hoisted and therefore they are not affected by this rule.

                          /*eslint-env es6*/
                          
                          // Good
                          var foo = 42;
                          
                          // Good
                          if (foo) {
                              let bar1;
                          }
                          
                          // Bad
                          while (test) {
                              var bar2;
                          }
                          
                          function doSomething() {
                              // Good
                              var baz = true;
                          
                              // Bad
                              if (baz) {
                                  var quux;
                              }
                          }

                          Rule Details

                          This rule requires that function declarations and, optionally, variable declarations be in the root of a program or the body of a function.

                          Options

                          This rule has a string option:

                          • "functions" (default) disallows function declarations in nested blocks
                          • "both" disallows function and var declarations in nested blocks

                          functions

                          Examples of incorrect code for this rule with the default "functions" option:

                          /*eslint no-inner-declarations: "error"*/
                          
                          if (test) {
                              function doSomething() { }
                          }
                          
                          function doSomethingElse() {
                              if (test) {
                                  function doAnotherThing() { }
                              }
                          }

                          Examples of correct code for this rule with the default "functions" option:

                          /*eslint no-inner-declarations: "error"*/
                          
                          function doSomething() { }
                          
                          function doSomethingElse() {
                              function doAnotherThing() { }
                          }
                          
                          if (test) {
                              asyncCall(id, function (err, data) { });
                          }
                          
                          var fn;
                          if (test) {
                              fn = function fnExpression() { };
                          }

                          both

                          Examples of incorrect code for this rule with the "both" option:

                          /*eslint no-inner-declarations: ["error", "both"]*/
                          
                          if (test) {
                              var foo = 42;
                          }
                          
                          function doAnotherThing() {
                              if (test) {
                                  var bar = 81;
                              }
                          }

                          Examples of correct code for this rule with the "both" option:

                          /*eslint no-inner-declarations: "error"*/
                          /*eslint-env es6*/
                          
                          var bar = 42;
                          
                          if (test) {
                              let baz = 43;
                          }
                          
                          function doAnotherThing() {
                              var baz = 81;
                          }

                          When Not To Use It

                          The function declaration portion rule will be rendered obsolete when block-scoped functions land in ES6, but until then, it should be left on to enforce valid constructions. Disable checking variable declarations when using [block-scoped-var](block-scoped-var.md) or if declaring variables in nested blocks is acceptable despite hoisting. Source: http://eslint.org/docs/rules/

                          Move function declaration to function body root.
                          Wontfix

                                          function finalizeMessageHandling() {

                          disallow variable or function declarations in nested blocks (no-inner-declarations)

                          In JavaScript, prior to ES6, a function declaration is only allowed in the first level of a program or the body of another function, though parsers sometimes erroneously accept them elsewhere. This only applies to function declarations; named or anonymous function expressions can occur anywhere an expression is permitted.

                          // Good
                          function doSomething() { }
                          
                          // Bad
                          if (test) {
                              function doSomethingElse () { }
                          }
                          
                          function anotherThing() {
                              var fn;
                          
                              if (test) {
                          
                                  // Good
                                  fn = function expression() { };
                          
                                  // Bad
                                  function declaration() { }
                              }
                          }

                          A variable declaration is permitted anywhere a statement can go, even nested deeply inside other blocks. This is often undesirable due to variable hoisting, and moving declarations to the root of the program or function body can increase clarity. Note that block bindings (let, const) are not hoisted and therefore they are not affected by this rule.

                          /*eslint-env es6*/
                          
                          // Good
                          var foo = 42;
                          
                          // Good
                          if (foo) {
                              let bar1;
                          }
                          
                          // Bad
                          while (test) {
                              var bar2;
                          }
                          
                          function doSomething() {
                              // Good
                              var baz = true;
                          
                              // Bad
                              if (baz) {
                                  var quux;
                              }
                          }

                          Rule Details

                          This rule requires that function declarations and, optionally, variable declarations be in the root of a program or the body of a function.

                          Options

                          This rule has a string option:

                          • "functions" (default) disallows function declarations in nested blocks
                          • "both" disallows function and var declarations in nested blocks

                          functions

                          Examples of incorrect code for this rule with the default "functions" option:

                          /*eslint no-inner-declarations: "error"*/
                          
                          if (test) {
                              function doSomething() { }
                          }
                          
                          function doSomethingElse() {
                              if (test) {
                                  function doAnotherThing() { }
                              }
                          }

                          Examples of correct code for this rule with the default "functions" option:

                          /*eslint no-inner-declarations: "error"*/
                          
                          function doSomething() { }
                          
                          function doSomethingElse() {
                              function doAnotherThing() { }
                          }
                          
                          if (test) {
                              asyncCall(id, function (err, data) { });
                          }
                          
                          var fn;
                          if (test) {
                              fn = function fnExpression() { };
                          }

                          both

                          Examples of incorrect code for this rule with the "both" option:

                          /*eslint no-inner-declarations: ["error", "both"]*/
                          
                          if (test) {
                              var foo = 42;
                          }
                          
                          function doAnotherThing() {
                              if (test) {
                                  var bar = 81;
                              }
                          }

                          Examples of correct code for this rule with the "both" option:

                          /*eslint no-inner-declarations: "error"*/
                          /*eslint-env es6*/
                          
                          var bar = 42;
                          
                          if (test) {
                              let baz = 43;
                          }
                          
                          function doAnotherThing() {
                              var baz = 81;
                          }

                          When Not To Use It

                          The function declaration portion rule will be rendered obsolete when block-scoped functions land in ES6, but until then, it should be left on to enforce valid constructions. Disable checking variable declarations when using [block-scoped-var](block-scoped-var.md) or if declaring variables in nested blocks is acceptable despite hoisting. Source: http://eslint.org/docs/rules/

                          There are no issues that match your filters.

                          Category
                          Status