Eslint-plugin-vue: Rule proposition: `no-dupe-keys`.

Created on 17 Jul 2017  路  4Comments  路  Source: vuejs/eslint-plugin-vue

There is many fields in vue instance/component where we can specify properties visible inside component, data, props, computed, methods.
Invalid Code:

export default {
  props: ['foo'],
  props: {
    foo: String  
  },
  computed: {
    foo () {
    }
  },
  data() {
    return {
      foo: null
    }
  },
  data: {
    foo: null
  },
  methods: {
    foo () {
    }
  }
}

Also there is few reserved names witch should not be overridden by vue instance:

  • properties: $data, $props, $el, $options, $parent, $root, $children, $slots, $scopedSlots, $refs, $isServer, $attrs, $listeners
  • methods: $watch, $set, $delete, $on, $once, $off, $emit, $mount, $forceUpdate, $nextTick, $destroy .....

also user should be able to specify his own reserved names to remove conflicts with used plugins.

accepted proposition new rule proposition work in progress

Most helpful comment

I like this proposition a lot, but.. I think this rule should be splitted into two rules.

  1. no-dupe-keys
  2. no-reservered-keys

So that each rule does only one thing. What do you think @mysticatea @armano2 ?

All 4 comments

Thank you for the proposal!

Sounds reasonable to me.
no-dupe-keys core rule cannot catch duplication of Vue's definition. We should catch it.

Also, the names which start with _ in data are reserved by Vue.js.

@mysticatea i think we should rename this rule to same as core no-dupe-keys instead of no-duplicate-field-names

Also, the names which start with _ in data are reserved by Vue.js.

馃憤 i didn't know that but i will add this.

I like this proposition a lot, but.. I think this rule should be splitted into two rules.

  1. no-dupe-keys
  2. no-reservered-keys

So that each rule does only one thing. What do you think @mysticatea @armano2 ?

eslint recommends to make functions to small chunks and split them to separate rules.

One rule should do one think

@michalsnik i like it 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

prograhammer picture prograhammer  路  3Comments

chrisvfritz picture chrisvfritz  路  3Comments

filipalacerda picture filipalacerda  路  4Comments

xiGUAwanOU picture xiGUAwanOU  路  3Comments

ydfzgyj picture ydfzgyj  路  4Comments