ethereum/mist

View on GitHub
interface/client/templates/webviewEvents.js

Summary

Maintainability
A
1 hr
Test Coverage

Unexpected console statement.
Open

  console.log(e.type, tabId, url);

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

Unexpected console statement.
Open

  console.log(e.type, currentTabId, e);

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

Unexpected console statement.
Open

  console.log(e.type, tabId, url);

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

    if ((find = History.findOne({ url: url }))) {
      History.update(find._id, { $set: { timestamp: moment().unix() } });
    } else {
      History.insert({
        name: title,
Severity: Minor
Found in interface/client/templates/webviewEvents.js and 1 other location - About 40 mins to fix
interface/client/templates/webviewEvents.js on lines 74..96

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

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 (
      (find = _.find(LastVisitedPages.find().fetch(), function(historyEntry) {
        if (!historyEntry.url) {
          return;
        }
Severity: Minor
Found in interface/client/templates/webviewEvents.js and 1 other location - About 40 mins to fix
interface/client/templates/webviewEvents.js on lines 99..108

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

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