Skip to content

Commit

Permalink
Docs: show console call with no-restricted-syntax (fixes eslint#7806)
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorHom committed Oct 1, 2017
1 parent 434d9e2 commit b1949c1
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions docs/rules/no-console.md
Expand Up @@ -49,6 +49,45 @@ console.error("Log an error level message.");

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:

```js
console.error = function (message) {
throw new Error(message);
};
```

With the `no-console` rule, this will receive a warning/error. For the above example, you can disable the rule:

```js
// 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:

```json
{
"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

* [no-alert](no-alert.md)
Expand Down

0 comments on commit b1949c1

Please sign in to comment.