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.

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

See original GitHub issue

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: https://github.com/typescript-eslint/typescript-eslint/issues/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). https://github.com/acornjs/acorn/issues/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.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
mdjermanoviccommented, Mar 10, 2020

Actually, #12831 seems to work well by chance. The name of the function isRenamedImport is wrong if parser always creates two nodes, but the code inside works okay and prevents reporting the same location twice.

It is, however, difficult to think about and cover both variations with same code.

1reaction
mdjermanoviccommented, Mar 9, 2020

Then, I misread the estree spec while working on #12831 so we should probably fix that as well. Tests didn’t catch it because acorn creates just 1 node.

I was sure it’s the same node because there is no something like shorthand attribute, so it isn’t possible to distinguish between import { a } from "foo" and import { a as a } from "foo" without comparing locations.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Default camel case of property names in JSON serialization
I have a bunch of classes that will be serialized to JSON at some point and for the sake of following both ...
Read more >
CS 3110 OCaml Style Guide - Cornell Computer Science
Constructor names: The standard library uses CamelCase, and the language ... forcing a non-default parse of an expression, and grouping structures for ......
Read more >
Jackson JSON - @JsonInclude NON_DEFAULT Example
NON_DEFAULT) is used on the class level then default values of the fields are excluded. This is done by creating an instance of...
Read more >
C++ Core Guidelines - GitHub Pages
This document is a set of guidelines for using C++ well. The aim of this document is to help people to use modern...
Read more >
OMNeT++ - Simulation Manual - Index of - omnetpp.org
simple PriorityQueue extends Queue // wrong! still uses the Queue C++ class { } ... A non-default value assigned from NED cannot be...
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