【问题标题】:ESLint & Vue - How to ban the use of `$log`?ESLint & Vue - 如何禁止使用`$log`?
【发布时间】:2021-04-02 17:00:52
【问题描述】:

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

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

【问题讨论】:

  • 澄清一下,您的意思是如何让 eslint 将 $log 标记为不允许,而不是如何禁用该函数的调用。我理解正确吗?
  • @apokryfos 是的,我们的目标是禁止所有 $log 使用。
  • @apokryfos 我已经搞定了。

标签: javascript vue.js eslint


【解决方案1】:

在深入研究了no-restricted-syntaxvue/no-restricted-syntaxASTs 规则之后,我终于得到了这个工作,这是工作规则:

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

【讨论】:

    猜你喜欢
    • 2019-06-25
    • 2016-12-09
    • 2018-08-13
    • 2016-09-06
    • 2020-10-07
    • 2020-11-10
    • 2019-07-16
    • 1970-01-01
    • 2017-04-20
    相关资源
    最近更新 更多