marionebl/jogwheel

View on GitHub
source/library/init-player.js

Summary

Maintainability
A
3 hrs
Test Coverage

Function initPlayer has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export default function initPlayer(element, keyframes, options, render, window = global.window, document = global.document) {
    // Gracefully handle cases where element.animate is not defined
    if (typeof element.animate !== 'function') {
        const {HTMLElement = {}} = window;
        const {prototype: ElementPrototype = {}} = HTMLElement;
Severity: Minor
Found in source/library/init-player.js - About 1 hr to fix

    Function 'initPlayer' has too many parameters (6). Maximum allowed is 4.
    Open

    export default function initPlayer(element, keyframes, options, render, window = global.window, document = global.document) {
    Severity: Minor
    Found in source/library/init-player.js by eslint

    enforce a maximum number of parameters in function definitions (max-params)

    Functions that take numerous parameters can be difficult to read and write because it requires the memorization of what each parameter is, its type, and the order they should appear in. As a result, many coders adhere to a convention that caps the number of parameters a function can take.

    function foo (bar, baz, qux, qxx) { // four parameters, may be too many
        doSomething();
    }

    Rule Details

    This rule enforces a maximum number of parameters allowed in function definitions.

    Options

    This rule has a number or object option:

    • "max" (default 3) enforces a maximum number of parameters in function definitions

    Deprecated: The object property maximum is deprecated; please use the object property max instead.

    max

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

    /*eslint max-params: ["error", 3]*/
    /*eslint-env es6*/
    
    function foo (bar, baz, qux, qxx) {
        doSomething();
    }
    
    let foo = (bar, baz, qux, qxx) => {
        doSomething();
    };

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

    /*eslint max-params: ["error", 3]*/
    /*eslint-env es6*/
    
    function foo (bar, baz, qux) {
        doSomething();
    }
    
    let foo = (bar, baz, qux) => {
        doSomething();
    };

    Related Rules

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

    Function initPlayer has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    export default function initPlayer(element, keyframes, options, render, window = global.window, document = global.document) {
        // Gracefully handle cases where element.animate is not defined
        if (typeof element.animate !== 'function') {
            const {HTMLElement = {}} = window;
            const {prototype: ElementPrototype = {}} = HTMLElement;
    Severity: Minor
    Found in source/library/init-player.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 initPlayer has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    export default function initPlayer(element, keyframes, options, render, window = global.window, document = global.document) {
    Severity: Minor
    Found in source/library/init-player.js - About 45 mins to fix

      Empty block statement.
      Open

          if (process.env.NODE_ENV !== 'production') {
      Severity: Minor
      Found in source/library/init-player.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

      Comments should not begin with a lowercase character
      Open

      /**
      Severity: Minor
      Found in source/library/init-player.js by eslint

      enforce or disallow capitalization of the first letter of a comment (capitalized-comments)

      Comments are useful for leaving information for future developers. In order for that information to be useful and not distracting, it is sometimes desirable for comments to follow a particular style. One element of comment formatting styles is whether the first word of a comment should be capitalized or lowercase.

      In general, no comment style is any more or less valid than any others, but many developers would agree that a consistent style can improve a project's maintainability.

      Rule Details

      This rule aims to enforce a consistent style of comments across your codebase, specifically by either requiring or disallowing a capitalized letter as the first word character in a comment. This rule will not issue warnings when non-cased letters are used.

      By default, this rule will require a non-lowercase letter at the beginning of comments.

      Examples of incorrect code for this rule:

      /* eslint capitalized-comments: ["error"] */
      
      // lowercase comment

      Examples of correct code for this rule:

      // Capitalized comment
      
      // 1. Non-letter at beginning of comment
      
      // 丈 Non-Latin character at beginning of comment
      
      /* eslint semi:off */
      /* eslint-env node */
      /* eslint-disable */
      /* eslint-enable */
      /* istanbul ignore next */
      /* jscs:enable */
      /* jshint asi:true */
      /* global foo */
      /* globals foo */
      /* exported myVar */
      // eslint-disable-line
      // eslint-disable-next-line
      // https://github.com

      Options

      This rule has two options: a string value "always" or "never" which determines whether capitalization of the first word of a comment should be required or forbidden, and optionally an object containing more configuration parameters for the rule.

      Here are the supported object options:

      • ignorePattern: A string representing a regular expression pattern of words that should be ignored by this rule. If the first word of a comment matches the pattern, this rule will not report that comment.
        • Note that the following words are always ignored by this rule: ["jscs", "jshint", "eslint", "istanbul", "global", "globals", "exported"].
      • ignoreInlineComments: If this is true, the rule will not report on comments in the middle of code. By default, this is false.
      • ignoreConsecutiveComments: If this is true, the rule will not report on a comment which violates the rule, as long as the comment immediately follows another comment. By default, this is false.

      Here is an example configuration:

      {
          "capitalized-comments": [
              "error",
              "always",
              {
                  "ignorePattern": "pragma|ignored",
                  "ignoreInlineComments": true
              }
          ]
      }

      "always"

      Using the "always" option means that this rule will report any comments which start with a lowercase letter. This is the default configuration for this rule.

      Note that configuration comments and comments which start with URLs are never reported.

      Examples of incorrect code for this rule:

      /* eslint capitalized-comments: ["error", "always"] */
      
      // lowercase comment

      Examples of correct code for this rule:

      /* eslint capitalized-comments: ["error", "always"] */
      
      // Capitalized comment
      
      // 1. Non-letter at beginning of comment
      
      // 丈 Non-Latin character at beginning of comment
      
      /* eslint semi:off */
      /* eslint-env node */
      /* eslint-disable */
      /* eslint-enable */
      /* istanbul ignore next */
      /* jscs:enable */
      /* jshint asi:true */
      /* global foo */
      /* globals foo */
      /* exported myVar */
      // eslint-disable-line
      // eslint-disable-next-line
      // https://github.com

      "never"

      Using the "never" option means that this rule will report any comments which start with an uppercase letter.

      Examples of incorrect code with the "never" option:

      /* eslint capitalized-comments: ["error", "never"] */
      
      // Capitalized comment

      Examples of correct code with the "never" option:

      /* eslint capitalized-comments: ["error", "never"] */
      
      // lowercase comment
      
      // 1. Non-letter at beginning of comment
      
      // 丈 Non-Latin character at beginning of comment

      ignorePattern

      The ignorePattern object takes a string value, which is used as a regular expression applied to the first word of a comment.

      Examples of correct code with the "ignorePattern" option set to "pragma":

      /* eslint capitalized-comments: ["error", "always", { "ignorePattern": "pragma" }] */
      
      function foo() {
          /* pragma wrap(true) */
      }

      ignoreInlineComments

      Setting the ignoreInlineComments option to true means that comments in the middle of code (with a token on the same line as the beginning of the comment, and another token on the same line as the end of the comment) will not be reported by this rule.

      Examples of correct code with the "ignoreInlineComments" option set to true:

      /* eslint capitalized-comments: ["error", "always", { "ignoreInlineComments": true }] */
      
      function foo(/* ignored */ a) {
      }

      ignoreConsecutiveComments

      If the ignoreConsecutiveComments option is set to true, then comments which otherwise violate the rule will not be reported as long as they immediately follow another comment. This can be applied more than once.

      Examples of correct code with ignoreConsecutiveComments set to true:

      /* eslint capitalize-comments: ["error", "always", { "ignoreConsecutiveComments": true }] */
      
      // This comment is valid since it has the correct capitalization.
      // this comment is ignored since it follows another comment,
      // and this one as well because it follows yet another comment.
      
      /* Here is a block comment which has the correct capitalization, */
      /* but this one is ignored due to being consecutive; */
      /*
       * in fact, even if any of these are multi-line, that is fine too.
       */

      Examples of incorrect code with ignoreConsecutiveComments set to true:

      /* eslint capitalize-comments: ["error", "always", { "ignoreConsecutiveComments": true }] */
      
      // this comment is invalid, but only on this line.
      // this comment does NOT get reported, since it is a consecutive comment.

      Using Different Options for Line and Block Comments

      If you wish to have a different configuration for line comments and block comments, you can do so by using two different object configurations (note that the capitalization option will be enforced consistently for line and block comments):

      {
          "capitalized-comments": [
              "error",
              "always",
              {
                  "line": {
                      "ignorePattern": "pragma|ignored",
                  },
                  "block": {
                      "ignoreInlineComments": true,
                      "ignorePattern": "ignored"
                  }
              }
          ]
      }

      Examples of incorrect code with different line and block comment configuration:

      /* eslint capitalized-comments: ["error", "always", { "block": { "ignorePattern": "blockignore" } }] */
      
      // capitalized line comment, this is incorrect, blockignore does not help here
      /* lowercased block comment, this is incorrect too */

      Examples of correct code with different line and block comment configuration:

      /* eslint capitalized-comments: ["error", "always", { "block": { "ignorePattern": "blockignore" } }] */
      
      // Uppercase line comment, this is correct
      /* blockignore lowercase block comment, this is correct due to ignorePattern */

      When Not To Use It

      This rule can be disabled if you do not care about the grammatical style of comments in your codebase.

      Compatibility

      There are no issues that match your filters.

      Category
      Status