Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no-console warns on assignment #14793

Closed
sachinraja opened this issue Jul 12, 2021 · 2 comments · Fixed by #14901
Closed

no-console warns on assignment #14793

sachinraja opened this issue Jul 12, 2021 · 2 comments · Fixed by #14901
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion documentation Relates to ESLint's documentation rule Relates to ESLint's core rules
Projects

Comments

@sachinraja
Copy link

sachinraja commented Jul 12, 2021

Tell us about your environment

  • ESLint Version: v7.30.0
  • Node Version: v16.4.0
  • npm Version: v7.18.1
  • Operating System: linux 5.8.0-58-generic

What parser (default, @babel/eslint-parser, @typescript-eslint/parser, etc.) are you using?
@typescript-eslint/parser

Please show your full configuration:

Configuration
module.exports = {
  parserOptions: {
      ecmaVersion: 6
  },
  rules: {
    "no-console": "warn",
  },
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

console.log = jest.fn()
npx eslint .

What did you expect to happen?
The no-console rule should detect that this is an assignment and not a call. In the rule details it says "This rule disallows calls to methods of the console object."

What actually happened? Please copy-paste the actual, raw output from ESLint.
warning Unexpected console statement no-console

Steps to reproduce this issue:

  1. in your eslint configuration add no-console: 'warn' to your rules.
  2. in your code, set console.log = null

Are you willing to submit a pull request to fix this bug?
yes

@sachinraja sachinraja added bug ESLint is working incorrectly repro:needed labels Jul 12, 2021
@eslint-github-bot eslint-github-bot bot added this to Needs Triage in Triage Jul 12, 2021
@mdjermanovic mdjermanovic moved this from Needs Triage to Triaging in Triage Jul 13, 2021
@mdjermanovic
Copy link
Member

Hi @sachinraja, thanks for the issue!

console.log = jest.fn()

This was already discussed in #7806, and it was eventually decided that this behavior shouldn't be changed.

If you want to disallow only method calls, you can use the no-restricted-syntax rule, as described in When Not To Use It section of no-console docs ("Another case where you might not use this rule is if you want to enforce console calls and not console overwrites...").

In the rule details it says "This rule disallows calls to methods of the console object."

You're right, this sounds misleading. I'm marking this issue as an accepted documentation change.

@mdjermanovic mdjermanovic moved this from Triaging to Ready to Implement in Triage Jul 13, 2021
@mdjermanovic mdjermanovic added accepted There is consensus among the team that this change meets the criteria for inclusion documentation Relates to ESLint's documentation rule Relates to ESLint's core rules and removed bug ESLint is working incorrectly repro:needed labels Jul 13, 2021
@coderaiser

This comment has been minimized.

Triage automation moved this from Ready to Implement to Complete Aug 9, 2021
bmish added a commit to bmish/eslint that referenced this issue Aug 11, 2021
* master:
  Chore: Add rel/abs path tests in `no-restricted-{imports/modules}` rules (eslint#14910)
  Upgrade: Debug 4.0.1 > 4.3.2 (eslint#14892)
  Chore: add assertions on reporting location in `semi` (eslint#14899)
  Fix: no-useless-computed-key edge cases with class fields (refs eslint#14857) (eslint#14903)
  Upgrade: `js-yaml` to v4 (eslint#14890)
  Fix: prefer-destructuring PrivateIdentifier false positive (refs eslint#14857) (eslint#14897)
  Fix: dot-notation false positive with private identifier (refs eslint#14857) (eslint#14898)
  Sponsors: Sync README with website
  Sponsors: Sync README with website
  Docs: improve rule details for `no-console` (fixes eslint#14793) (eslint#14901)
  Update: check class fields in no-extra-parens (refs eslint#14857) (eslint#14906)
  Docs: add class fields in no-multi-assign documentation (refs eslint#14857) (eslint#14907)
  Docs: add class fields in func-names documentation (refs eslint#14857) (eslint#14908)
  Upgrade: `eslint-visitor-keys` to v3 (eslint#14902)
  Upgrade: `markdownlint` dev dependencies (eslint#14883)
  Upgrade: @humanwhocodes/config-array to 0.6 (eslint#14891)
  Chore: Specify Node 14.x for Verify Files CI job (eslint#14896)
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Feb 6, 2022
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion documentation Relates to ESLint's documentation rule Relates to ESLint's core rules
Projects
Archived in project
Triage
Complete
Development

Successfully merging a pull request may close this issue.

3 participants