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

Duplicate key error on computed property from RegExp literals #8655

Closed
lleaff opened this issue May 26, 2017 · 3 comments
Closed

Duplicate key error on computed property from RegExp literals #8655

lleaff opened this issue May 26, 2017 · 3 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion works as intended The behavior described in this issue is working correctly

Comments

@lleaff
Copy link

lleaff commented May 26, 2017

Tell us about your environment

  • ESLint Version: v3.19.0
  • Node Version: v7.7.2
  • npm Version: 4.1.2

What parser (default, Babel-ESLint, etc.) are you using?
babel-eslint
Please show your full configuration:

module.exports = {
  "parser": "babel-eslint",

  "globals": {
    "React": true,
    "ReactDOM": true,
    "$": true,
    "_": true,
    "jQuery": true,
  },

  "env": {
    "es6": true,
    "node": true,
    "browser": true,
    "mocha": true,
  },

  "plugins": ["react"],

  "rules": {
    // "indent": [2, 2],
    "linebreak-style": [2, "unix"],
    "semi": [1, "always"], // Enfore semi-colons after statements
    "no-console": [0], // Disallow usage of console API (default 2)
    "no-unused-vars": [1,
      { "vars": "local", // local | all
        "argsIgnorePattern": "^_",
        "args": "after-used", // "after-used": Allow unused params if they come before a used param in the arg list
      }], // Warn against unused variables
    "comma-dangle": [1, "always-multiline"], // Disallow or enforce trailing comma in array literals, e.g.: "always-multiline"
    "no-cond-assign": [1], // Disallow `if (myVar = smth())`

    // eslint-plugin-react
    //------------------------------------------------------------
    "react/display-name": 0, // Prevent missing displayName in a React component definition
    "react/jsx-no-undef": 2, // Disallow undeclared variables in JSX
    "react/jsx-sort-props": 0, // Enforce props alphabetical sorting
    "react/jsx-uses-react": 2, // Prevent React to be incorrectly marked as unused
    "react/jsx-uses-vars": 2, // Prevent variables used in JSX to be incorrectly marked as unused
    "react/no-did-mount-set-state": 2, // Prevent usage of setState in componentDidMount
    "react/no-did-update-set-state": 2, // Prevent usage of setState in componentDidUpdate
    "react/no-multi-comp": 0, // Prevent multiple component definition per file
    "react/no-unknown-property": 2, // Prevent usage of unknown DOM property
    "react/prop-types": 0, // Prevent missing props validation in a React component definition (propTypes)
    "react/react-in-jsx-scope": 2, // Prevent missing React when using JSX
    "react/self-closing-comp": 2, // Prevent extra closing tags for components without children
    //"react/wrap-multilines": 2, // Prevent missing parentheses around multilines JSX // Disabled cause eslint doesn't find the rule (even tho it's documented)

  },

  "extends": ["eslint:recommended"],
};

What did you do? Please include the actual source code causing the issue.

const foo = {
  [/bar/]: '/bar/',
  [/foo/]: '/foo/',
};

What did you expect to happen?
No error as default toString implementation of RegExp produces different results from different RegExp literals.

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

  3:4  error    Duplicate key '[object Object]'  no-dupe-keys

✖ 1 problem (1 error, 0 warnings)


I don't know how practical this would be to implement, but since keys from array literals are correctly differentiated, I'm assuming this shouldn't be hard.

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label May 26, 2017
@soda0289
Copy link
Member

The prop value is cast to a string in the rule no-dupe-key

return String(prop.value);

I tested the code sample on the eslint demo, which uses the espree parser, and it works as expected. It could be that babel-eslint is not generating a RegExp object for the value of Literal nodes.

@soda0289
Copy link
Member

soda0289 commented May 26, 2017

This is a bug with babel-eslint. When they convert the RegExpLiteral they only set value to an empty Object {} and not to a RegExp Object.
https://github.com/babel/babel-eslint/blob/master/babylon-to-espree/toAST.js#L97

I fixed a similar bug in typescript-eslint-parser I can work on a fix for babel soon.

@soda0289 soda0289 added works as intended The behavior described in this issue is working correctly and removed triage An ESLint team member will look at this issue soon labels May 26, 2017
@soda0289
Copy link
Member

Fix landed in babel-eslint

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@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 Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion works as intended The behavior described in this issue is working correctly
Projects
None yet
Development

No branches or pull requests

3 participants