ethereum/mist

View on GitHub
modules/preloader/include/mistAPI.js

Summary

Maintainability
F
3 days
Test Coverage

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

module.exports = () => {
  let queue = [];
  const prefix = 'entry_';
  const MIST_SUBMENU_LIMIT = 100;

Severity: Major
Found in modules/preloader/include/mistAPI.js - About 5 hrs to fix

    Function exports has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
    Open

    module.exports = () => {
      let queue = [];
      const prefix = 'entry_';
      const MIST_SUBMENU_LIMIT = 100;
    
    
    Severity: Minor
    Found in modules/preloader/include/mistAPI.js - About 5 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 add has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          add(id, options, callback) {
            const args = Array.prototype.slice.call(arguments);
            callback = _.isFunction(args[args.length - 1]) ? args.pop() : null;
            options = _.isObject(args[args.length - 1]) ? args.pop() : null;
            id =
    Severity: Minor
    Found in modules/preloader/include/mistAPI.js - About 1 hr to fix

      'setInterval' is not defined.
      Open

        setInterval(() => {
      Severity: Minor
      Found in modules/preloader/include/mistAPI.js by eslint

      Disallow Undeclared Variables (no-undef)

      This rule can help you locate potential ReferenceErrors resulting from misspellings of variable and parameter names, or accidental implicit globals (for example, from forgetting the var keyword in a for loop initializer).

      Rule Details

      Any reference to an undeclared variable causes a warning, unless the variable is explicitly mentioned in a /*global ...*/ comment, or specified in the globals key in the configuration file. A common use case for these is if you intentionally use globals that are defined elsewhere (e.g. in a script sourced from HTML).

      Examples of incorrect code for this rule:

      /*eslint no-undef: "error"*/
      
      var a = someFunction();
      b = 10;

      Examples of correct code for this rule with global declaration:

      /*global someFunction b:true*/
      /*eslint no-undef: "error"*/
      
      var a = someFunction();
      b = 10;

      The b:true syntax in /*global */ indicates that assignment to b is correct.

      Examples of incorrect code for this rule with global declaration:

      /*global b*/
      /*eslint no-undef: "error"*/
      
      b = 10;

      By default, variables declared in /*global */ are read-only, therefore assignment is incorrect.

      Options

      • typeof set to true will warn for variables used inside typeof check (Default false).

      typeof

      Examples of correct code for the default { "typeof": false } option:

      /*eslint no-undef: "error"*/
      
      if (typeof UndefinedIdentifier === "undefined") {
          // do something ...
      }

      You can use this option if you want to prevent typeof check on a variable which has not been declared.

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

      /*eslint no-undef: ["error", { "typeof": true }] */
      
      if(typeof a === "string"){}

      Examples of correct code for the { "typeof": true } option with global declaration:

      /*global a*/
      /*eslint no-undef: ["error", { "typeof": true }] */
      
      if(typeof a === "string"){}

      Environments

      For convenience, ESLint provides shortcuts that pre-define global variables exposed by popular libraries and runtime environments. This rule supports these environments, as listed in [Specifying Environments](../user-guide/configuring.md#specifying-environments). A few examples are given below.

      browser

      Examples of correct code for this rule with browser environment:

      /*eslint no-undef: "error"*/
      /*eslint-env browser*/
      
      setTimeout(function() {
          alert("Hello");
      });

      Node.js

      Examples of correct code for this rule with node environment:

      /*eslint no-undef: "error"*/
      /*eslint-env node*/
      
      var fs = require("fs");
      module.exports = function() {
          console.log(fs);
      };

      When Not To Use It

      If explicit declaration of global variables is not to your taste.

      Compatibility

      This rule provides compatibility with treatment of global variables in JSHint and JSLint. Source: http://eslint.org/docs/rules/

      Unexpected console statement.
      Open

          console.log('uiAction_windowMessage', type, error, value);
      Severity: Minor
      Found in modules/preloader/include/mistAPI.js by eslint

      disallow the use of console (no-console)

      In JavaScript that is designed to be executed in the browser, it's considered a best practice to avoid using methods on console. Such messages are considered to be for debugging purposes and therefore not suitable to ship to the client. In general, calls using console should be stripped before being pushed to production.

      console.log("Made it here.");
      console.error("That shouldn't have happened.");

      Rule Details

      This rule disallows calls to methods of the console object.

      Examples of incorrect code for this rule:

      /*eslint no-console: "error"*/
      
      console.log("Log a debug level message.");
      console.warn("Log a warn level message.");
      console.error("Log an error level message.");

      Examples of correct code for this rule:

      /*eslint no-console: "error"*/
      
      // custom console
      Console.log("Hello world!");

      Options

      This rule has an object option for exceptions:

      • "allow" has an array of strings which are allowed methods of the console object

      Examples of additional correct code for this rule with a sample { "allow": ["warn", "error"] } option:

      /*eslint no-console: ["error", { allow: ["warn", "error"] }] */
      
      console.warn("Log a warn level message.");
      console.error("Log an error level message.");

      When Not To Use It

      If you're using Node.js, however, console is used to output information to the user and so is not strictly used for debugging purposes. If you are developing for Node.js then you most likely do not want this rule enabled.

      Another case where you might not use this rule is if you want to enforce console calls and not console overwrites. For example:

      /*eslint no-console: ["error", { allow: ["warn"] }] */
      console.error = function (message) {
        throw new Error(message);
      };

      With the no-console rule in the above example, ESLint will report an error. For the above example, you can disable the rule:

      // eslint-disable-next-line no-console
      console.error = function (message) {
        throw new Error(message);
      };
      
      // or
      
      console.error = function (message) {  // eslint-disable-line no-console
        throw new Error(message);
      };

      However, you might not want to manually add eslint-disable-next-line or eslint-disable-line. You can achieve the effect of only receiving errors for console calls with the no-restricted-syntax rule:

      {
          "rules": {
              "no-restricted-syntax": [
                  "error",
                  {
                      "selector": "CallExpression[callee.object.name='console'][callee.property.name=/^(log|warn|error|info|trace)$/]",
                      "message": "Unexpected property on console object was called"
                  }
              ]
          }
      }

      Related Rules

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

            select(id) {
              const filteredId = prefix + filterId(id);
              queue.push({ action: 'selectMenu', id: filteredId });
      
              for (const e in this.entries) {
      Severity: Major
      Found in modules/preloader/include/mistAPI.js and 1 other location - About 4 hrs to fix
      modules/preloader/injected/mistAPI.js on lines 213..222

      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 113.

      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

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

        const filterId = str => {
          const filteredStr = String(str);
          let newStr = '';
          if (filteredStr) {
            for (let i = 0; i < filteredStr.length; i += 1) {
      Severity: Major
      Found in modules/preloader/include/mistAPI.js and 1 other location - About 3 hrs to fix
      modules/preloader/injected/mistAPI.js on lines 34..45

      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 99.

      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

            remove(id) {
              const filteredId = prefix + filterId(id);
      
              delete this.entries[filteredId];
      
      
      Severity: Major
      Found in modules/preloader/include/mistAPI.js and 1 other location - About 1 hr to fix
      modules/preloader/injected/mistAPI.js on lines 197..206

      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 61.

      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

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

          if (mist.menu.entries[id] && mist.menu.entries[id].callback) {
            mist.menu.entries[id].callback();
          }
      Severity: Major
      Found in modules/preloader/include/mistAPI.js and 1 other location - About 1 hr to fix
      modules/preloader/injected/mistAPI.js on lines 251..253

      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 61.

      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

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

            if (callback) {
              if (!this.callbacks.connectAccount) {
                this.callbacks.connectAccount = [];
              }
              this.callbacks.connectAccount.push(callback);
      Severity: Major
      Found in modules/preloader/include/mistAPI.js and 1 other location - About 1 hr to fix
      modules/preloader/injected/mistAPI.js on lines 61..66

      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 59.

      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

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

              const entry = {
                id: filteredId || 'mist_defaultId',
                position: options.position,
                selected: !!options.selected,
                name: options.name,
      Severity: Major
      Found in modules/preloader/include/mistAPI.js and 1 other location - About 1 hr to fix
      modules/preloader/injected/mistAPI.js on lines 157..163

      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 57.

      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 (
                !(filteredId in this.entries) &&
                Object.keys(this.entries).length >= MIST_SUBMENU_LIMIT
              ) {
                return false;
      Severity: Minor
      Found in modules/preloader/include/mistAPI.js and 1 other location - About 50 mins to fix
      modules/preloader/injected/mistAPI.js on lines 150..155

      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

        const filterAdd = options => {
          if (!(options instanceof Object)) {
            return false;
          }
      
      
      Severity: Minor
      Found in modules/preloader/include/mistAPI.js and 1 other location - About 35 mins to fix
      modules/preloader/injected/mistAPI.js on lines 25..31

      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 41.

      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

              callback = _.isFunction(args[args.length - 1]) ? args.pop() : null;
      Severity: Minor
      Found in modules/preloader/include/mistAPI.js and 1 other location - About 30 mins to fix
      modules/preloader/include/mistAPI.js on lines 120..120

      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 40.

      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

              options = _.isObject(args[args.length - 1]) ? args.pop() : null;
      Severity: Minor
      Found in modules/preloader/include/mistAPI.js and 1 other location - About 30 mins to fix
      modules/preloader/include/mistAPI.js on lines 119..119

      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 40.

      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

      There are no issues that match your filters.

      Category
      Status