tsg-ut/mnemo

View on GitHub
lib/validator.js

Summary

Maintainability
D
1 day
Test Coverage

Function validateSubmission has 112 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports.validateSubmission = (submission) => {
    if (typeof submission.stage !== 'string') {
        return {pass: false, message: 'stage data is missing'};
    }

Severity: Major
Found in lib/validator.js - About 4 hrs to fix

    Function validateSubmission has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

    module.exports.validateSubmission = (submission) => {
        if (typeof submission.stage !== 'string') {
            return {pass: false, message: 'stage data is missing'};
        }
    
    
    Severity: Minor
    Found in lib/validator.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

    Line 9 exceeds the maximum line length of 100.
    Open

    // https://github.com/tsg-ut/mnemo/wiki/%E3%82%B9%E3%82%B3%E3%82%A2%E3%81%AE%E4%BB%95%E6%A7%98#%E8%A8%88%E7%AE%97%E5%BC%8F
    Severity: Minor
    Found in lib/validator.js by eslint

    enforce a maximum line length (max-len)

    Very long lines of code in any language can be difficult to read. In order to aid in readability and maintainability many coders have developed a convention to limit lines of code to X number of characters (traditionally 80 characters).

    var foo = { "bar": "This is a bar.", "baz": { "qux": "This is a qux" }, "difficult": "to read" }; // very long

    Rule Details

    This rule enforces a maximum line length to increase code readability and maintainability. The length of a line is defined as the number of Unicode characters in the line.

    Options

    This rule has a number or object option:

    • "code" (default 80) enforces a maximum line length
    • "tabWidth" (default 4) specifies the character width for tab characters
    • "comments" enforces a maximum line length for comments; defaults to value of code
    • "ignorePattern" ignores lines matching a regular expression; can only match a single line and need to be double escaped when written in YAML or JSON
    • "ignoreComments": true ignores all trailing comments and comments on their own line
    • "ignoreTrailingComments": true ignores only trailing comments
    • "ignoreUrls": true ignores lines that contain a URL
    • "ignoreStrings": true ignores lines that contain a double-quoted or single-quoted string
    • "ignoreTemplateLiterals": true ignores lines that contain a template literal
    • "ignoreRegExpLiterals": true ignores lines that contain a RegExp literal

    code

    Examples of incorrect code for this rule with the default { "code": 80 } option:

    /*eslint max-len: ["error", 80]*/
    
    var foo = { "bar": "This is a bar.", "baz": { "qux": "This is a qux" }, "difficult": "to read" };

    Examples of correct code for this rule with the default { "code": 80 } option:

    /*eslint max-len: ["error", 80]*/
    
    var foo = {
      "bar": "This is a bar.",
      "baz": { "qux": "This is a qux" },
      "easier": "to read"
    };

    tabWidth

    Examples of incorrect code for this rule with the default { "tabWidth": 4 } option:

    /*eslint max-len: ["error", 80, 4]*/
    
    \t  \t  var foo = { "bar": "This is a bar.", "baz": { "qux": "This is a qux" } };

    Examples of correct code for this rule with the default { "tabWidth": 4 } option:

    /*eslint max-len: ["error", 80, 4]*/
    
    \t  \t  var foo = {
    \t  \t  \t  \t  "bar": "This is a bar.",
    \t  \t  \t  \t  "baz": { "qux": "This is a qux" }
    \t  \t  };

    comments

    Examples of incorrect code for this rule with the { "comments": 65 } option:

    /*eslint max-len: ["error", { "comments": 65 }]*/
    
    /**
     * This is a comment that violates the maximum line length we have specified
    **/

    ignoreComments

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

    /*eslint max-len: ["error", { "ignoreComments": true }]*/
    
    /**
     * This is a really really really really really really really really really long comment
    **/

    ignoreTrailingComments

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

    /*eslint max-len: ["error", { "ignoreTrailingComments": true }]*/
    
    var foo = 'bar'; // This is a really really really really really really really long comment

    ignoreUrls

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

    /*eslint max-len: ["error", { "ignoreUrls": true }]*/
    
    var url = 'https://www.example.com/really/really/really/really/really/really/really/long';

    ignoreStrings

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

    /*eslint max-len: ["error", { "ignoreStrings": true }]*/
    
    var longString = 'this is a really really really really really long string!';

    ignoreTemplateLiterals

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

    /*eslint max-len: ["error", { "ignoreTemplateLiterals": true }]*/
    
    var longTemplateLiteral = `this is a really really really really really long template literal!`;

    ignoreRegExpLiterals

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

    /*eslint max-len: ["error", { "ignoreRegExpLiterals": true }]*/
    
    var longRegExpLiteral = /this is a really really really really really long regular expression!/;

    ignorePattern

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

    /*eslint max-len: ["error", { "ignorePattern": "^\\s*var\\s.+=\\s*require\\s*\\(/" }]*/
    
    var dep = require('really/really/really/really/really/really/really/really/long/module');

    Related Rules

    • [complexity](complexity.md)
    • [max-depth](max-depth.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 message has 28 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            const message = (() => {
                if (!arrayEquals(Object.keys(block), ['x', 'y', 'type', 'rotate'])) {
                    return `keys of block ${index} are invalid`;
                }
    
    
    Severity: Minor
    Found in lib/validator.js - About 1 hr to fix

      Avoid too many return statements within this function.
      Open

              return {pass: false, message: 'positions of blocks are not unique'};
      Severity: Major
      Found in lib/validator.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                    return {pass: false, message: 'used blocks are not matching to the stage'};
        Severity: Major
        Found in lib/validator.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                      return {pass: false, message: 'used blocks are not matching to the stage'};
          Severity: Major
          Found in lib/validator.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                            return `y position of block ${index} exceeds the board size`;
            Severity: Major
            Found in lib/validator.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return {pass: false, message: error};
              Severity: Major
              Found in lib/validator.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                                return `type of block ${index} is unknown`;
                Severity: Major
                Found in lib/validator.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                                  return `rotation of block ${index} is invalid`;
                  Severity: Major
                  Found in lib/validator.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                        return {pass: true, clocks: maxClock, blocks: board.weighedBlockCount};
                    Severity: Major
                    Found in lib/validator.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                      return `type of block ${index} should be a string`;
                      Severity: Major
                      Found in lib/validator.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

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

                          Avoid too many return statements within this function.
                          Open

                                      return {pass: false, message: 'the board cannot clear the stage'};
                          Severity: Major
                          Found in lib/validator.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                            return `rotation of block ${index} should be an integer`;
                            Severity: Major
                            Found in lib/validator.js - About 30 mins to fix

                              Definition for rule 'getter-return' was not found
                              Open

                              const assert = require('assert');
                              Severity: Minor
                              Found in lib/validator.js by eslint

                              For more information visit Source: http://eslint.org/docs/rules/

                              Definition for rule 'react/no-will-update-set-state' was not found
                              Open

                              const assert = require('assert');
                              Severity: Minor
                              Found in lib/validator.js by eslint

                              For more information visit Source: http://eslint.org/docs/rules/

                              Definition for rule 'no-buffer-constructor' was not found
                              Open

                              const assert = require('assert');
                              Severity: Minor
                              Found in lib/validator.js by eslint

                              For more information visit Source: http://eslint.org/docs/rules/

                              Definition for rule 'switch-colon-spacing' was not found
                              Open

                              const assert = require('assert');
                              Severity: Minor
                              Found in lib/validator.js by eslint

                              For more information visit Source: http://eslint.org/docs/rules/

                              Definition for rule 'for-direction' was not found
                              Open

                              const assert = require('assert');
                              Severity: Minor
                              Found in lib/validator.js by eslint

                              For more information visit Source: http://eslint.org/docs/rules/

                              Definition for rule 'semi-style' was not found
                              Open

                              const assert = require('assert');
                              Severity: Minor
                              Found in lib/validator.js by eslint

                              For more information visit Source: http://eslint.org/docs/rules/

                              There are no issues that match your filters.

                              Category
                              Status