[英]How to run es-lint rules on Vue component's external script files
I've added es-lint checks on Vue components but the script for the component not in the same file, I kept it as a separate file for all the components in the project.我在 Vue 组件上添加了 es-lint 检查,但该组件的脚本不在同一个文件中,我将它作为项目中所有组件的单独文件保存。 For Example, I've added
vue/order-in-components
rule in .eslintrc.js
which will throw an error if the component's script has the wrong order of hooks.例如,我在
.eslintrc.js
中添加了vue/order-in-components
规则,如果组件脚本的钩子顺序错误,则会引发错误。
export default {
name: 'Address',
props: {
isNewRegistration: {
type: Boolean,
required: true
}
},
data() {
return {
test: ''
}
}
}
export default {
name: 'Address',
// data should come after props
data() {
return {
test: ''
}
}
props: {
isNewRegistration: {
type: Boolean,
required: true
}
}
}
Order in components documentation: https://eslint.vuejs.org/rules/order-in-components.html在组件文档中订购: https://eslint.vuejs.org/rules/order-in-components.html
As I've added the component's script through the external file.因为我已经通过外部文件添加了组件的脚本。 These checks are not happening while we run
eslint --fix
当我们运行
eslint --fix
时,这些检查不会发生
Any solutions for this would be appreciated, Thanks in advance对此的任何解决方案将不胜感激,在此先感谢
I am not familiar with vue but have you tried using --ext
while running eslint like,我对 vue 不熟悉,但是您是否尝试过在运行 eslint 时使用
--ext
,例如,
eslint --ext .vue --ext .js src/
If you're using webpack template, add如果您使用的是 webpack 模板,请添加
preLoaders: { js: 'eslint-loader' }
to your vue-loader.conf.js file.到你的 vue-loader.conf.js 文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.