eslint-plugin-vue icon indicating copy to clipboard operation
eslint-plugin-vue copied to clipboard

Allow emits in vue/no-unused-properties rule

Open VasylRolique opened this issue 2 years ago • 2 comments

I've already check open propositions and there no such suggestion

What rule do you want to change? -> vue/no-unused-properties

Does this change cause the rule to produce more or fewer warnings? -> more warnings

How will the change be implemented? (New option, new default behavior, etc.)? -> Would be nice to add 'emits' group into this rule.

Please provide some example code that this change will affect:

<!-- ✓ GOOD -->
<template>
  <div></div>
</template>
<script>
  export default {
    emits: ['count'],
    methods: { 
        setCount () {
             this.$emit('count', newCount) 
        }
     }
  }
</script>


<!-- ✗ BAD (`count` property not used) -->
<template>
  <div></div>
</template>
<script>
  export default {
    emits: ['count'],
  }
</script>

What does the rule currently do for this code? -> nothing with emits

What will the rule do after it's changed? -> It will detect unused emits declaration

VasylRolique avatar May 20 '22 07:05 VasylRolique

I don't think it should be part of the vue/no-unused-properties rule, because emitting an event is not the same as using a property/variable.

But I do like the suggested rule. Maybe it should rather be part of the vue/require-explicit-emits rule, maybe with an option reportUnusedEmitDeclarations?

Or it could be a new rule vue/no-unused-emit-declarations (or similar).

FloEdelmann avatar May 20 '22 14:05 FloEdelmann

I think it makes sense to create a new rule 👍

ota-meshi avatar May 23 '22 10:05 ota-meshi

Hello @ota-meshi @FloEdelmann

Is it possible to handle the following cases in the proposed rule?

1

<script>
  const allEmits = ['foo', 'bar'];
  export default {
      emits: allEmits,
  })
</script>

2

<script>
  const sharedEmits = ['foo', 'bar'];
  export default {
      emits: [...sharedEmits, 'baz'],
  })
</script>

3

<script>
  import sharedEmits from 'sharedEmits';
  export default {
      emits: [...sharedEmits, 'baz'],
  })
</script>

4

<script>
  const allEmits = {
    foo: 'foo',
    bar: 'bar',
  }
  export default {
      emits: Object.values(allEmits),
  })
</script>

ItMaga avatar Jan 15 '23 22:01 ItMaga

@ItMaga Probably all of them are too much effort at the moment. I'd start with only checking events that are defined in the emits section (or defineEmits). Later, those special cases could be added, but let's keep the scope small for now.

FloEdelmann avatar Jun 22 '23 11:06 FloEdelmann

Hello,

What's the status of this rule? The idea is still to implement it?

Thanks in advance!

cesaralvrz avatar Oct 19 '23 12:10 cesaralvrz

Currently, as far as I know, nobody is actively working on it. But since the issue is still open and has the accepted proposition label, it is open for submissions. If anyone would like to work on this, feel free to submit a PR!

FloEdelmann avatar Oct 19 '23 12:10 FloEdelmann