该配置使用 recommend 规则,然后定制了部分规则。
说明:
- 语气:强制 > 要求 == !禁止 > 尽量 > 推荐 == !不推荐;
- 🔧表示ESLint可以自动修复。
mustache-interpolation-spacing
vue/html-closing-bracket-newline
html-end-tags, html-self-closing
// ✗ bad
<foo myProp="prop"></foo>
// ✓ good
<foo my-prop="prop"></foo>
允许class
与:class
共存,style
与:style
共存。
// ✗ bad
<div foo="abc" :foo="def"></div>
// ✓ good
<div foo="abc"></div>
<div :foo="def"></div>
在v-for元素上使用v-if指令时,没有使用v-for中使用的变量,会发生警告。
// ✗ bad
<ol>
<li v-if="shown" v-for="item in items">{{item.message}}</li>
</ol>
// ✓ good
<ol>
<li v-for="item in items" v-if="item.shown">{{item.message}}</li>
</ol>
<ol v-if="shown">
<li v-for="item in items">{{item.message}}</li>
</ol>
valid-v-bind, valid-v-cloak, valid-v-if, valid-v-else-if, valid-v-else, valid-v-for, valid-v-html, valid-v-model, valid-v-on, valid-v-once, valid-v-pre, valid-v-show, valid-v-text
// ✗ bad
<div v-bind></div>
<div :aaa></div>
<div v-bind:aaa.bbb="foo"></div>
// ✓ good
<div v-bind="{ id: someProp, 'other-attr': otherProp }"></div>
<div v-bind:text-content.prop="text"></div>
<my-component :prop="someThing"></my-component>
<template>
中不能出现以下错误:
- 指令中的语法错误
- Mustache的语法错误
- HTML语法错误
// ✗ bad
<div>{{ foo. }}</div>
// ✓ good
<div>{{ foo.bar }}</div>
// ✗ bad
<template>
<div>hello</div>
<div>hello</div>
</template>
// ✓ good
<template>
<div>
<div>hello</div>
<div>hello</div>
</div>
</template>
// ✗ bad
<textarea>{{ message }}</textarea>
// ✓ good
<textarea v-model="message"></textarea>
// ✗ bad
<div v-for="x in list"></div>
// ✓ good
<div v-for="x in list" :key="x.id"></div>
// ✗ bad
<component></component>
// ✓ good
<component :is="type"></component>
// ✗ bad
export default {
props: {
foo: String,
},
computed: {
foo: {
get () {},
},
},
data: {
foo: null,
},
methods: {
foo () {},
},
};
// ✓ good
export default {
props: ['foo'],
computed: {
bar () {},
},
data () {
return {
baz: null,
};
},
methods: {
boo () {},
},
};
// ✗ bad
export default {
computed: {
foo () {
},
bar: function () {
}
}
}
// ✓ good
export default {
computed: {
foo () {
return true
},
bar: function () {
return;
}
}
}
no-side-effects-in-computed-properties
// ✗ bad
computed: {
fullName () {
this.firstName = 'lorem'; // <- side effect
return `${this.firstName} ${this.lastName}`;
},
reversedArray () {
return this.array.reverse(); // <- side effect
},
},
// ✓ good
computed: {
fullName () {
return `${this.firstName} ${this.lastName}`
},
reversedArray () {
return this.array.slice(0).reverse()
},
}
no-async-in-computed-properties
// ✗ bad
export default {
props: {
$el: String,
},
computed: {
$on: {
get () {},
},
},
data: {
_foo: null,
},
methods: {
$nextTick () {},
},
};
// ✗ bad
export default {
data: {
foo: 'bar',
},
};
// ✓ good
export default {
data () {
return {
foo: 'bar'
};
},
};