ESLint plugin for vue-types and eslint-plugin-vue
This plugin should be used alongside eslint-plugin-vue to validate usages of vue-types on prop definitions (see this issue for details).
- eslint-plugin-vue
^4.4.0
- ESLint
>=3.18.0
.>=4.7.0
to useeslint --fix
.>=4.14.0
to use withbabel-eslint
.
- Node.js
>=4.0.0
npm install --save-dev eslint eslint-plugin-vue eslint-plugin-vue-types
This plugin provides the following eslint-plugin-vue rule:
vue-types/require-default-prop
: extendsvue/require-default-prop
allowingVueTypes
methods.
In your eslint configuration add plugin:vue-types/strongly-recommended
after any plugin:vue/*
preset.
module.exports = {
extends: [
// ...
'plugin:vue/strongly-recommended'
'plugin:vue-types/strongly-recommended'
],
//...
}
By default vue-types/require-default-prop
will not report vue-types
when used with the VueTypes
namespace.
import VueTypes from 'vue-types'
const theme = VueTypes.oneOf(['dark', 'light'])
export default {
props: {
name: VueTypes.string, // <-- not an error
theme, // <-- error
}
}
To prevent this error you can wrap custom definition in a namespace and add it to the plugin's whitelist:
// .eslint.rc.js
module.exports = {
extends: [
// ...
'plugin:vue/strongly-recommended'
'plugin:vue-types/strongly-recommended'
],
settings: {
'vue-types/namespace': ['VueTypes', 'AppTypes']
}
}
import VueTypes from 'vue-types'
const AppTypes = {
theme: VueTypes.oneOf(['dark', 'light'])
}
export default {
props: {
name: VueTypes.string, // <-- not an error
theme: AppTypes.theme, // <-- not an error
}
}
Copyright (c) 2018 Marco Solazzi