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

Rule id-blacklist incorrectly flags object property reassignments #12787

Closed
MaffooBristol opened this issue Jan 14, 2020 · 4 comments
Closed
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 bug ESLint is working incorrectly good first issue Good for people who haven't worked on ESLint before help wanted The team would welcome a contribution from the community for this issue rule Relates to ESLint's core rules

Comments

@MaffooBristol
Copy link

Tell us about your environment

  • ESLint Version: 6.8.0
  • Node Version: 10.15.3
  • npm Version: 6.11.3

What parser (default, Babel-ESLint, etc.) are you using?
babel-eslint

Please show your full configuration:

Configuration
extends: airbnb
parser: babel-eslint
rules:
  space-before-function-paren: 2
  brace-style: [2, 'stroustrup']
  arrow-body-style: 0
  no-underscore-dangle: 0
  class-methods-use-this: 1
  consistent-return: 0
  no-unused-vars: 1
  no-bitwise: 0
  no-plusplus: 0
  linebreak-style: 0
  arrow-parens: [2, 'always']
  no-useless-escape: 0
  curly: [2, 'all']
  no-lonely-if: 1
  semi: 2
  max-len: [1, { code: 120, ignoreComments: true }]
  prefer-destructuring: 1
  lines-between-class-members: 0
  object-curly-newline: 0
  indent: 1
  jsx-a11y/anchor-is-valid: [ 'error', {
    components: [ 'Link' ],
    specialLink: [ 'to' ]
  }]
  jsx-a11y/click-events-have-key-events: 0
  jsx-a11y/no-static-element-interactions: 0
  jsx-a11y/no-noninteractive-tabindex: 0
  react/prefer-stateless-function: 1
  react/no-unused-state: 1
  react/state-in-constructor: [1, "never"]
  react/jsx-one-expression-per-line: 0
  react/prop-types: 0 # This should be enabled at some point
  react/jsx-indent: 1
  import/no-extraneous-dependencies: ["error", {"devDependencies": ["test/**/*.js"]}]
  jsx-a11y/label-has-associated-control: [ 2, {
    depth: 1,
  }]
  react/forbid-component-props: ["error", {"forbid": ["style", "className"]}]
  react/forbid-dom-props: ["error", {"forbid": ["style", "className"]}]
  react/jsx-sort-props: ["error", {"callbacksLast": true, "reservedFirst": true, "shorthandFirst": true, "noSortAlphabetically": true}]
  id-blacklist: [1, "data", "err", "e", "cb", "callback"]
env:
  browser: true
  node: true
  es6: true

Highlight:

id-blacklist: [1, "data", "err", "e", "cb", "callback"]

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

const { data: user } = await axios.post('/api/auth', loginCredentials);
if (!user) {
  throw new Error('Error fetching authentication data');
}
npx eslint --ext .js --ext .jsx src/

What did you expect to happen?
The data property shouldn't be flagged here because it's coming from the axios request and there's nothing I can do about it. I'm converting the value response.data to the variable user. However it highlights it as being as if I were assigning the data variable.

What actually happened? Please include the actual, raw output from ESLint.

45:15  warning  Identifier 'data' is blacklisted  id-blacklist

Are you willing to submit a pull request to fix this bug?
I would but I'm not sure how as I've never delved into the eslint source!

@MaffooBristol MaffooBristol added bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels Jan 14, 2020
@MaffooBristol
Copy link
Author

Equivalent code that doesn't flag anything but does the same thing:

const authResponse = await axios.post('/api/auth', loginCredentials);
const { user } = authResponse.data;

@MaffooBristol
Copy link
Author

Additionally it has issues with optional chaining syntax:

if (error.response?.data?.error) { // Warns use of data
  return error.response.data.error;
}

@aladdin-add aladdin-add added evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Jan 14, 2020
@aladdin-add
Copy link
Member

it seems a bug to me, as the docs say:

It will not catch blacklisted identifiers that are:

  • function calls (so you can still use functions you do not have control over)
  • object properties (so you can still use objects you do not have control over)

re optional chaining, please follow #12642

@kaicataldo
Copy link
Member

I am able to reproduce this using our demo.

This seems doubly broken to me, since the the identifier is being renamed. We should update this rule to not warn on object destructured identifiers.

@kaicataldo kaicataldo added accepted There is consensus among the team that this change meets the criteria for inclusion good first issue Good for people who haven't worked on ESLint before help wanted The team would welcome a contribution from the community for this issue and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Jan 14, 2020
montmanu pushed a commit to montmanu/eslint that referenced this issue Mar 4, 2020
…slint#12792)

* Fix: Ignore destructured object property reassignments. (fixes eslint#12787)

* Updated to ignore blacklisted id's in ObjectPattern nodes.

* Remove console.log.

* Added tests for nested destructuring and destructuring function parameters.

* Fix typo.

* Undo accidentally auto-fixed comment indent.
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jul 17, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Jul 17, 2020
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 bug ESLint is working incorrectly good first issue Good for people who haven't worked on ESLint before help wanted The team would welcome a contribution from the community for this issue rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

3 participants