Skip to content

[camelcase] false positive when parsing object pattern with a default value, and using a non-default parser. #13021

@bradzacher

Description

@bradzacher

Tell us about your environment

  • ESLint Version: 6.7.0
  • Node Version: 12

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

Please show your full configuration:

Configuration
{
  rules: {
    camelcase: ['error', {
      "properties": "never",
      "ignoreDestructuring": true
    }],
  },
}

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

Context: typescript-eslint/typescript-eslint#1686
A user of typescript-eslint received a linting error with the following code, even though it should be covered by the options above.

  const res = {a_b:123}
  const {a_b=0} = res
//       ^^^ Error Identifier 'a_b' is not in camel case

This error occurs when parsing with typescript-eslint, and not with the default parser.
Thinking this was a bug in the typescript-eslint parser, I did some digging, and it turns out that the acorn reuses the AST node in two places (i.e. the two a_b Identifiers are referentially equal).
acornjs/acorn#928

This causes the parent references to be set incorrectly, as the node's parent will be that of whichever node was traversed last.

Logging this here because:

  • the rule doesn't work with the "correct" parent pointers,
  • the rule will have to be updated for when the bug in acorn is fixed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThere is consensus among the team that this change meets the criteria for inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussionblockedThis change can't be completed until another issue is resolvedbugESLint is working incorrectlyruleRelates to ESLint's core rules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions