Vue: Compatibility with linters's rules "no-new" and "no-undef"

Created on 2 Dec 2015  ·  2Comments  ·  Source: vuejs/vue

I'm using ESlint for code linting. When my Vue code goes like this:

var demo = new Vue({
  el: '#demo',
  data: {
    message: 'Hello Vue.js!'
  }
})

The linter will say "demo is defined but unused" because of this.

But if I write:

new Vue({
  el: '#demo',
  data: {
    message: 'Hello Vue.js!'
  }
})

The linter will say "do not use 'new' for side-effects" because of this.

It's okay if I can add an config file for the linter to my project. But when it comes to using an unconfigable linter, like Standard, the error will always be shown.

Is there any way to avoid this, or a new method in further versions? Like:

Vue.create({
  el: '#demo',
  data: {
    message: 'Hello Vue.js!'
  }
})

Most helpful comment

That is not Vue's concern if you are using an unconfigurable linter. You can just create that method yourself:

Vue.create = function (options) {
  return new Vue(options)
}

All 2 comments

That is not Vue's concern if you are using an unconfigurable linter. You can just create that method yourself:

Vue.create = function (options) {
  return new Vue(options)
}

You can always avoid warning by exporting the variable.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alenyu picture alenyu  ·  43Comments

ShuvoHabib picture ShuvoHabib  ·  40Comments

Akryum picture Akryum  ·  34Comments

smolinari picture smolinari  ·  116Comments

cherry-geqi picture cherry-geqi  ·  35Comments