Skip to content

vue/require-default-prop not picking up property name #776

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
MathieuDerelle opened this issue Jan 15, 2019 · 3 comments
Closed

vue/require-default-prop not picking up property name #776

MathieuDerelle opened this issue Jan 15, 2019 · 3 comments

Comments

@MathieuDerelle
Copy link

Tell us about your environment

  • ESLint version: 5.12.0
  • eslint-plugin-vue version: 5.1.0
  • Node version: 8.11.4

Please show your full configuration:

module.exports = {
  root: true,
  env: {
    browser: true,
    node: true
  },
  parserOptions: {
    parser: 'babel-eslint'
  },
  extends: [
    'standard',
    'plugin:vue/recommended'
  ],
  // required to lint *.vue files
  plugins: [
    'vue'
  ],
  // add your custom rules here
  rules: {
    'no-console':  process.env.NODE_ENV === 'production' ? 'error' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',

    "no-multi-spaces": "off",
    "key-spacing": "off",
    "comma-dangle": ["warn", "always-multiline"],

    "vue/max-attributes-per-line": ["warn", {
      "singleline": 3,
      "multiline": {
        "max": 1,
        "allowFirstLine": false
      }
    }],
  },
  globals: {
    CORE_API_BASE_URL: false,
  },
}

What did you do?

<script>
export default {
	props: {
	    tallStyle: Object,
	    'inverse': Boolean,
	    'actions': Array,
	}
}
</script>

What did you expect to happen?

The warnings should show the property names "tallStyle" and "actions"

What actually happened?

  95:5   warning  Prop 'tallStyle' requires default value to be set  vue/require-default-prop
  97:5   warning  Prop 'undefined' requires default value to be set  vue/require-default-prop
@MathieuDerelle MathieuDerelle changed the title vue/require-default-prop not extracting property name vue/require-default-prop not picking up property name Jan 15, 2019
@ota-meshi
Copy link
Member

I think that the problem will be solved if you change as follows.

<script>
export default {
	props: {
	    tallStyle: {
	      type: Object,
	      default() {
	        return undefined // The default value you want to set.
	      }
	    },
	    'inverse': Boolean,
	    'actions': {
	      type: Array,
	      default() {
	        return [] // The default value you want to set.
	      }
	    }
	}
}
</script>

https://vuejs.org/v2/guide/components-props.html#Prop-Validation

@armano2
Copy link
Contributor

armano2 commented Jan 31, 2019

@ota-meshi issue is with resolving name of property, right now its undefined

in https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/require-default-prop.js#L148

instead of

propName: prop.key.name

we should do

propName: utils.getStaticPropertyName(prop.key)

feel free to submit pr with this i'm out of time now

@ota-meshi
Copy link
Member

@armano2 Thank you for pointing that out.
I misunderstood.

I fixed a similar problem a little while ago, but I think that it is correct not to specify the key as below.

propName: utils.getStaticPropertyName(prop)

I will fix this.

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

No branches or pull requests

3 participants