4

Origin of $log:

Vue.prototype.$log = console.log

Places to be banned:

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

3
  • To clarify, you mean how to get eslint to flag $log as not allowed, not how to disable the call of that function. Am I understanding this correctly? Commented Dec 24, 2020 at 6:57
  • @apokryfos Yes, the goal is to ban all $log usages. Commented Dec 24, 2020 at 7:20
  • @apokryfos I've got it working. Commented Dec 26, 2020 at 7:31

1 Answer 1

5

After digging into no-restricted-syntax, vue/no-restricted-syntax rules, and ASTs, 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.",
      },
    ],
  },
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.