question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

no-console rule should document how to enforce calls only via no-restricted-syntax

See original GitHub issue

What rule do you want to change?

The no-console rule.

Does this change cause the rule to produce more or fewer warnings?

Fewer warnings.

How will the change be implemented? (New option, new default behavior, etc.)?

I’m thinking it would be default behavior, but could also be configured.

Please provide some example code that this change will affect:

In our development and test environments we have this snippet to suss out warnings in our Javascript:

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

What does the rule currently do for this code?

The rule currently reports Unexpected console statement.

What will the rule do after it’s changed?

It will not report any errors for assignment to console.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:18 (16 by maintainers)

github_iconTop GitHub Comments

2reactions
platinumazurecommented, Dec 21, 2016

I don’t think it’s worth changing the rule for this use case. Instead, you can use a disable comment to ignore the rule in this location.

Here are two ways you can do this:

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

// Or (equivalent)

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

Of course, you could also just use the no-console rule to statically detect all of your console.error invocations and replace them with error throwing, as needed. 😄

1reaction
platinumazurecommented, Aug 31, 2017

Editing the title of this issue to reflect the TSC decision.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-console - ESLint - Pluggable JavaScript Linter
This rule disallows calls or assignments to methods of the console object. Examples of incorrect code for this rule: /* eslint no-console: "error"...
Read more >
What if ESLint's configuration worked like elm-review?
I was curious to see how the configuration for ESLint would look ... In elm-review , the whole configuration is just this list...
Read more >
How to disable "unexpected console statement" in Node.js ...
Create a .eslintrc.js in the directory of your file, and put the following contents in it: module.exports = { rules: { 'no-console': 'off',...
Read more >
eslint-config-openstack/.eslintrc at master - OpenDev
# Disallow assigning of the exception parameter in a catch block. # http://eslint.org/docs/rules/no-ex-assign.
Read more >
List of available rules - ESLint - Pluggable JavaScript linter
These rules relate to possible syntax or logic errors in JavaScript code: for-direction. enforce “for” loop update clause moving the counter in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found