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

Rule Proposal: Ensure prop.type is an Object #323

Closed
richardtallent opened this issue Jan 3, 2018 · 2 comments
Closed

Rule Proposal: Ensure prop.type is an Object #323

richardtallent opened this issue Jan 3, 2018 · 2 comments

Comments

@richardtallent
Copy link

Please describe what the rule should do:

Ensure that the type key for a property is passed as an Object, not as a string.

What category of rule is this? (place an "X" next to just one item)

[ ] Enforces code style
[x] Warns about a potential error
[ ] Suggests an alternate way of doing something
[ ] Other (please specify:)

Provide 2-3 code examples that this rule will warn about:

props: {
	myFieldWithBadType: {
		type: "Object",
		default: function() {
			return {}
		},
	},
	myOtherFieldWithBadType: {
		type: "Number",
		default: 1,
	},
}

Why should this rule be included in ESLint (instead of a plugin)?

Passing a string to type rather than the name of the type results in a rather opaque error message from deep in the bowels of Vue, and it's an easy mistake to make.

@michalsnik
Copy link
Member

This is an interesting proposal @richardtallent It might indeed be useful for newcomers that learn Vue 👍

@chrisvfritz
Copy link
Contributor

chrisvfritz commented Jul 31, 2018

I like this! Though note that constructors rather than objects should be allowed. It would go in essentials and a more complete list of situations to warn about might be:

import Foo from './foo'
const Bar = ''

// ...

props: {
  a: 'Object',
  b: { type: 'Number' },
  c: `String`,
  d: Foo + ''
  e: Bar,
  f: 1,
  g: true,
  h: { type: {} },
}

michalsnik added a commit that referenced this issue Aug 13, 2018
* Add no-string-prop-type rule - basic implementation

* Rename rule

* Add more tests, update docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants