ESLint&Vue-如何禁止使用$ log? [英] ESLint & Vue - How to ban the use of `$log`?
本文介绍了ESLint&Vue-如何禁止使用$ log?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ log
的来源:
Vue.prototype.$log = console.log
要禁止的地方:
<template>
<!-- Place 1 -->
<div @click="$log">
<!-- Place 2 -->
{{ $log }}
<!-- Place 3 -->
{{ $log('foo') }}
</div>
</template>
<script>
import Vue from 'vue'
// Place 4
Vue.prototype.$log('foo')
export default {
created() {
// Place 5
this.$log('foo')
},
}
</script>
一些其他信息可能会有所帮助:
Some additional information that might help:
推荐答案
在研究了 no-restricted-syntax
, vue/no-restricted-syntax
规则和 AST
s,我终于可以正常工作了,这是工作规则:
After digging into no-restricted-syntax
, vue/no-restricted-syntax
rules, and AST
s, I finally got this working, here're the working rules:
{
rules: {
'no-restricted-syntax': [
'error',
{
selector: '[name=$log]',
message: "Using '$log' is not allowed.",
},
],
'vue/no-restricted-syntax': [
'error',
{
selector: '[name=$log]',
message: "Using '$log' is not allowed.",
},
],
},
}
这篇关于ESLint&Vue-如何禁止使用$ log?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文