Skip to content

Object rest spread inside prop definition crashes eslint #287

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

Closed
austindebruyn opened this issue Dec 9, 2017 · 2 comments
Closed

Object rest spread inside prop definition crashes eslint #287

austindebruyn opened this issue Dec 9, 2017 · 2 comments
Labels

Comments

@austindebruyn
Copy link

Tell us about your environment

  • ESLint Version: 4.13.0
  • eslint-plugin-vue Version: 4.0.0-beta.2
  • Node Version: 8.6.0

Please show your full configuration:

Here's a minimal repro: https://github.com/austindebruyn/eslintvuespread-repro

module.exports = {
  extends: [
    // add more generic rulesets here, such as:
    // 'eslint:recommended',
    'plugin:vue/essential',
    'plugin:vue/strongly-recommended'
  ],
  rules: {
    // override/add rules settings here, such as:
    // 'vue/no-unused-vars': 'error'
  }
}

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

Including a spread operator inside your prop delcaration makes the require-default-prop rule crash.

export default {
  name: 'TheComponent',
  props: {
    size: {
      type: String,
      ...oneOf(['sm', 'md', 'lg']),
      default: 'sm'
    }
  }
};

What did you expect to happen?
Not crash

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

Looks like the check here is a little too trusting.
I can open a fix, but I'm also not sure what the recommended behavior is. What I was trying to do (spread inside the prop) was a little wacky and I changed it, but eslint probably shouldn't just crash.

austin@oswald:~/projects/eslint-vue-spread-breaks$ ./node_modules/.bin/eslint test.jsx 
Cannot read property 'name' of undefined
TypeError: Cannot read property 'name' of undefined
    at prop.value.properties.find.p (/home/austin/projects/eslint-vue-spread-breaks/node_modules/eslint-plugin-vue/lib/rules/require-default-prop.js:52:25)
    at Array.find (native)
    at propHasDefault (/home/austin/projects/eslint-vue-spread-breaks/node_modules/eslint-plugin-vue/lib/rules/require-default-prop.js:52:10)
    at propsNode.value.properties.filter.filter.prop (/home/austin/projects/eslint-vue-spread-breaks/node_modules/eslint-plugin-vue/lib/rules/require-default-prop.js:70:44)
    at Array.filter (<anonymous>)
    at findPropsWithoutDefaultValue (/home/austin/projects/eslint-vue-spread-breaks/node_modules/eslint-plugin-vue/lib/rules/require-default-prop.js:65:10)
    at utils.executeOnVue (/home/austin/projects/eslint-vue-spread-breaks/node_modules/eslint-plugin-vue/lib/rules/require-default-prop.js:89:35)
    at ExportDefaultDeclaration:exit (/home/austin/projects/eslint-vue-spread-breaks/node_modules/eslint-plugin-vue/lib/utils/index.js:467:9)
    at listeners.(anonymous function).forEach.listener (/home/austin/projects/eslint-vue-spread-breaks/node_modules/eslint/lib/util/safe-emitter.js:47:58)
    at Array.forEach (<anonymous>)
@michalsnik
Copy link
Member

Hey @austindebruyn , thanks for posting this issue. Eslint shouldn't crash - it's true. We didn't handle this case before, as it's a little bit abstract and as you already said wacky, props definitions should be simple. If you have time we would appreciate a fix though :) Feel free to open a PR.

@michalsnik michalsnik added the bug label Dec 17, 2017
jaredhobbs added a commit to jaredhobbs/eslint-plugin-vue that referenced this issue Dec 19, 2017
check for key
michalsnik pushed a commit that referenced this issue Dec 19, 2017
* add test for prop default with object spread

* fixes #287:

check for key
@cmygray
Copy link

cmygray commented Mar 2, 2018

The same crash happens when I use spread operater inside of computed property.

‘’’
computed: {
email: {
get: ...mapGetters( //...
‘’’

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants