javascript - ESLint 和 Vue - 如何禁止使用 `$log`?

标签 javascript vue.js eslint

$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>

一些可能有帮助的附加信息:

最佳答案

在深入了解 no-restricted-syntaxvue/no-restricted-syntax 规则和 AST 之后,我终于得到了这个工作,这里是工作规则:

{
  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.",
      },
    ],
  },
}

关于javascript - ESLint 和 Vue - 如何禁止使用 `$log`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65434989/

相关文章:

javascript - 我如何在当前 JavaScript 片段中使用 'return this' 来满足调用者的链接而不破坏我的 ESLint 规则?

javascript - SVG 背景图像中的旋转条纹

vue.js - Vue路由器上的可选参数

vue.js - 为什么我的 `client-only` 组件在 nuxt 提示 `window is not defined` ?

vue.js - 不论vuetify中的文字如何,如何使卡中的底部按钮对齐?

reactjs - 防止直接 react 状态修改的 Eslint 规则

javascript - TitaniumStudio 不更新新文件

javascript - 如何使用javascript从句子中选择单词?

javascript - 如何允许用户单击标题部分的下一步按钮?

javascript - react 错误 : is declared but its value is never read. [6133]