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

Rule proposal: Restrict function props

Open ECrownofFire opened this issue 2 years ago • 0 comments

Please describe what the rule should do:

Restrict using functions as props and encourage using events instead.

Options for exceptions could be useful for cases such as sorting or formatting (e.g. with a name pattern/regex). In TypeScript it could be useful to allow non-void functions.

What category should the rule belong to?

  • [ ] Enforces code style (layout)
  • [ ] Warns about a potential error (problem)
  • [x] Suggests an alternate way of doing something (suggestion)
  • [ ] Other (please specify:)

Provide 2-3 code examples that this rule should warn about:

// <script setup>
defineProps<{
  func: () => void;
}>();

defineProps({
  func: Function,
});

Additional context Some code styles consider passing functions as props, particularly void functions, an anti-pattern in Vue.

ECrownofFire avatar Sep 05 '23 19:09 ECrownofFire