yoctore/yocto-grunt-apidoc

View on GitHub

Showing 19 of 19 total issues

Function has a complexity of 17.
Open

  _.each(jsonApiDoc.apidoc.methods, function (method) {
Severity: Minor
Found in src/generator.js by eslint

Limit Cyclomatic Complexity (complexity)

Cyclomatic complexity measures the number of linearly independent paths through a program's source code. This rule allows setting a cyclomatic complexity threshold.

function a(x) {
    if (true) {
        return x; // 1st path
    } else if (false) {
        return x+1; // 2nd path
    } else {
        return 4; // 3rd path
    }
}

Rule Details

This rule is aimed at reducing code complexity by capping the amount of cyclomatic complexity allowed in a program. As such, it will warn when the cyclomatic complexity crosses the configured threshold (default is 20).

Examples of incorrect code for a maximum of 2:

/*eslint complexity: ["error", 2]*/

function a(x) {
    if (true) {
        return x;
    } else if (false) {
        return x+1;
    } else {
        return 4; // 3rd path
    }
}

Examples of correct code for a maximum of 2:

/*eslint complexity: ["error", 2]*/

function a(x) {
    if (true) {
        return x;
    } else {
        return 4;
    }
}

Options

Optionally, you may specify a max object property:

"complexity": ["error", 2]

is equivalent to

"complexity": ["error", { "max": 2 }]

Deprecated: the object property maximum is deprecated. Please use the property max instead.

When Not To Use It

If you can't determine an appropriate complexity limit for your code, then it's best to disable this rule.

Further Reading

Related Rules

  • [max-depth](max-depth.md)
  • [max-len](max-len.md)
  • [max-nested-callbacks](max-nested-callbacks.md)
  • [max-params](max-params.md)
  • [max-statements](max-statements.md) Source: http://eslint.org/docs/rules/

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

  _.each(jsonApiDoc.apidoc.methods, function (method) {
Severity: Minor
Found in src/generator.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 createApiFile has 63 lines of code (exceeds 25 allowed). Consider refactoring.
Open

Generator.prototype.createApiFile = function (theTemplate, jsonModel, jsonApiDoc, destFile) {

  var commentFile = '';

  // Retrieve each methods on jsonApiDoc for generate an bloc with all necessary values
Severity: Major
Found in src/generator.js - About 2 hrs to fix

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

            dataError += '  ' + keys + ' : ' +
            (_.isString(model.apiErrorExample.example.content[keys]) ? '"' + valueError +
            '"' : valueError) + (j >= lenghtContentError ? '\n' : ',\n');
    Severity: Major
    Found in src/generator.js and 1 other location - About 1 hr to fix
    src/generator.js on lines 206..208

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 73.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

            dataSuccess += '  ' + k + ' : ' +
            (_.isString(model.apiSuccessExample.example.content[k]) ? '"' + value + '"' : value) +
            (i >= lenghtContent ? '' : ',\n');
    Severity: Major
    Found in src/generator.js and 1 other location - About 1 hr to fix
    src/generator.js on lines 236..238

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 73.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        if (!_.isUndefined(model.apiErrorExample) && !_.isUndefined(model.apiErrorExample.example) &&
        !_.isUndefined(model.apiErrorExample.example.content)) {
    
          var dataError = '{\n';
    
    
    Severity: Major
    Found in src/generator.js and 1 other location - About 1 hr to fix
    src/generator.js on lines 156..215

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 64.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        if (!_.isUndefined(model.apiSuccessExample) &&
        !_.isUndefined(model.apiSuccessExample.example) &&
        !_.isUndefined(model.apiSuccessExample.example.content)) {
    
          var properties = '    {\n';
    Severity: Major
    Found in src/generator.js and 1 other location - About 1 hr to fix
    src/generator.js on lines 218..245

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 64.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Function startProcess has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    Generator.prototype.startProcess = function (src, docs, destFile, done, grunt) {
    
      // Save grunt instance
      this.grunt = grunt;
    
    
    Severity: Minor
    Found in src/generator.js - About 1 hr to fix

      Function exports has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      module.exports = function(grunt) {
      
        // Project configuration.
        grunt.initConfig({
      
      
      Severity: Minor
      Found in Gruntfile.js - About 1 hr to fix

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                var value = _.isObject(model.apiSuccessExample.example.content[k]) ? 'Object' :
                model.apiSuccessExample.example.content[k];
        Severity: Major
        Found in src/generator.js and 1 other location - About 1 hr to fix
        src/generator.js on lines 232..233

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 55.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                var valueError = _.isObject(model.apiErrorExample.example.content[keys]) ? 'Object' :
                model.apiErrorExample.example.content[keys];
        Severity: Major
        Found in src/generator.js and 1 other location - About 1 hr to fix
        src/generator.js on lines 192..193

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 55.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Function startProcess has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        Generator.prototype.startProcess = function (src, docs, destFile, done, grunt) {
        Severity: Minor
        Found in src/generator.js - About 35 mins to fix

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

                    if (_.isArray(model.model.properties[key].type)) {
                      type = '[ ' + type + ' ]';
                    }
          Severity: Minor
          Found in src/generator.js and 1 other location - About 35 mins to fix
          src/generator.js on lines 198..200

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 46.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

                    if (_.isArray(model.apiSuccessExample.example.content[k])) {
                      properties  = ' [\n' + properties + '  ]\n';
                    }
          Severity: Minor
          Found in src/generator.js and 1 other location - About 35 mins to fix
          src/generator.js on lines 173..175

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 46.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Use path.join() or path.resolve() instead of + to create paths.
          Open

            var lineReader  = new LineByLineReader(__dirname + '/template/methods');
          Severity: Minor
          Found in src/generator.js by eslint

          Disallow string concatenation when using __dirname and __filename (no-path-concat)

          In Node.js, the __dirname and __filename global variables contain the directory path and the file path of the currently executing script file, respectively. Sometimes, developers try to use these variables to create paths to other files, such as:

          var fullPath = __dirname + "/foo.js";

          However, there are a few problems with this. First, you can't be sure what type of system the script is running on. Node.js can be run on any computer, including Windows, which uses a different path separator. It's very easy, therefore, to create an invalid path using string concatenation and assuming Unix-style separators. There's also the possibility of having double separators, or otherwise ending up with an invalid path.

          In order to avoid any confusion as to how to create the correct path, Node.js provides the path module. This module uses system-specific information to always return the correct value. So you can rewrite the previous example as:

          var fullPath = path.join(__dirname, "foo.js");

          This example doesn't need to include separators as path.join() will do it in the most appropriate manner. Alternately, you can use path.resolve() to retrieve the fully-qualified path:

          var fullPath = path.resolve(__dirname, "foo.js");

          Both path.join() and path.resolve() are suitable replacements for string concatenation wherever file or directory paths are being created.

          Rule Details

          This rule aims to prevent string concatenation of directory paths in Node.js

          Examples of incorrect code for this rule:

          /*eslint no-path-concat: "error"*/
          
          var fullPath = __dirname + "/foo.js";
          
          var fullPath = __filename + "/foo.js";

          Examples of correct code for this rule:

          /*eslint no-path-concat: "error"*/
          
          var fullPath = dirname + "/foo.js";

          When Not To Use It

          If you want to allow string concatenation of path names. Source: http://eslint.org/docs/rules/

          The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.
          Open

                for (var keys in model.apiErrorExample.example.content) {
          Severity: Minor
          Found in src/generator.js by eslint

          Require Guarding for-in (guard-for-in)

          Looping over objects with a for in loop will include properties that are inherited through the prototype chain. This behavior can lead to unexpected items in your for loop.

          for (key in foo) {
              doSomething(key);
          }

          Note that simply checking foo.hasOwnProperty(key) is likely to cause an error in some cases; see [no-prototype-builtins](no-prototype-builtins.md).

          Rule Details

          This rule is aimed at preventing unexpected behavior that could arise from using a for in loop without filtering the results in the loop. As such, it will warn when for in loops do not filter their results with an if statement.

          Examples of incorrect code for this rule:

          /*eslint guard-for-in: "error"*/
          
          for (key in foo) {
              doSomething(key);
          }

          Examples of correct code for this rule:

          /*eslint guard-for-in: "error"*/
          
          for (key in foo) {
              if (Object.prototype.hasOwnProperty.call(foo, key)) {
                  doSomething(key);
              }
              if ({}.hasOwnProperty.call(foo, key)) {
                  doSomething(key);
              }
          }

          Related Rules

          • [no-prototype-builtins](no-prototype-builtins.md)

          Further Reading

          The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.
          Open

                for (var key in model.model.properties) {
          Severity: Minor
          Found in src/generator.js by eslint

          Require Guarding for-in (guard-for-in)

          Looping over objects with a for in loop will include properties that are inherited through the prototype chain. This behavior can lead to unexpected items in your for loop.

          for (key in foo) {
              doSomething(key);
          }

          Note that simply checking foo.hasOwnProperty(key) is likely to cause an error in some cases; see [no-prototype-builtins](no-prototype-builtins.md).

          Rule Details

          This rule is aimed at preventing unexpected behavior that could arise from using a for in loop without filtering the results in the loop. As such, it will warn when for in loops do not filter their results with an if statement.

          Examples of incorrect code for this rule:

          /*eslint guard-for-in: "error"*/
          
          for (key in foo) {
              doSomething(key);
          }

          Examples of correct code for this rule:

          /*eslint guard-for-in: "error"*/
          
          for (key in foo) {
              if (Object.prototype.hasOwnProperty.call(foo, key)) {
                  doSomething(key);
              }
              if ({}.hasOwnProperty.call(foo, key)) {
                  doSomething(key);
              }
          }

          Related Rules

          • [no-prototype-builtins](no-prototype-builtins.md)

          Further Reading

          Empty block statement.
          Open

              } catch (e) {
          Severity: Minor
          Found in src/generator.js by eslint

          disallow empty block statements (no-empty)

          Empty block statements, while not technically errors, usually occur due to refactoring that wasn't completed. They can cause confusion when reading code.

          Rule Details

          This rule disallows empty block statements. This rule ignores block statements which contain a comment (for example, in an empty catch or finally block of a try statement to indicate that execution should continue regardless of errors).

          Examples of incorrect code for this rule:

          /*eslint no-empty: "error"*/
          
          if (foo) {
          }
          
          while (foo) {
          }
          
          switch(foo) {
          }
          
          try {
              doSomething();
          } catch(ex) {
          
          } finally {
          
          }

          Examples of correct code for this rule:

          /*eslint no-empty: "error"*/
          
          if (foo) {
              // empty
          }
          
          while (foo) {
              /* empty */
          }
          
          try {
              doSomething();
          } catch (ex) {
              // continue regardless of error
          }
          
          try {
              doSomething();
          } finally {
              /* continue regardless of error */
          }

          Options

          This rule has an object option for exceptions:

          • "allowEmptyCatch": true allows empty catch clauses (that is, which do not contain a comment)

          allowEmptyCatch

          Examples of additional correct code for this rule with the { "allowEmptyCatch": true } option:

          /* eslint no-empty: ["error", { "allowEmptyCatch": true }] */
          try {
              doSomething();
          } catch (ex) {}
          
          try {
              doSomething();
          }
          catch (ex) {}
          finally {
              /* continue regardless of error */
          }

          When Not To Use It

          If you intentionally use empty block statements then you can disable this rule.

          Related Rules

          The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.
          Open

                for (var k in model.apiSuccessExample.example.content) {
          Severity: Minor
          Found in src/generator.js by eslint

          Require Guarding for-in (guard-for-in)

          Looping over objects with a for in loop will include properties that are inherited through the prototype chain. This behavior can lead to unexpected items in your for loop.

          for (key in foo) {
              doSomething(key);
          }

          Note that simply checking foo.hasOwnProperty(key) is likely to cause an error in some cases; see [no-prototype-builtins](no-prototype-builtins.md).

          Rule Details

          This rule is aimed at preventing unexpected behavior that could arise from using a for in loop without filtering the results in the loop. As such, it will warn when for in loops do not filter their results with an if statement.

          Examples of incorrect code for this rule:

          /*eslint guard-for-in: "error"*/
          
          for (key in foo) {
              doSomething(key);
          }

          Examples of correct code for this rule:

          /*eslint guard-for-in: "error"*/
          
          for (key in foo) {
              if (Object.prototype.hasOwnProperty.call(foo, key)) {
                  doSomething(key);
              }
              if ({}.hasOwnProperty.call(foo, key)) {
                  doSomething(key);
              }
          }

          Related Rules

          • [no-prototype-builtins](no-prototype-builtins.md)

          Further Reading

          Severity
          Category
          Status
          Source
          Language