Skip to content

New rule vue/require-macro-variable-name #2188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
szulcus opened this issue May 23, 2023 · 2 comments · Fixed by #2198
Closed

New rule vue/require-macro-variable-name #2188

szulcus opened this issue May 23, 2023 · 2 comments · Fixed by #2198

Comments

@szulcus
Copy link

szulcus commented May 23, 2023

What rule do you want to change?
New config fields:

  • Require using a defined name for the define* variable (e.g. { "name": "props" })
  • Require name prefix in html (not for vue/define-emits-declaration e.g. { "prefix": true })

Does this change cause the rule to produce more or fewer warnings?
More (depends on configuration).

How will the change be implemented? (New option, new default behavior, etc.)?
The default behavior does not change the current behavior of the rule.

Please provide some example code that this change will affect:

"vue/define-props-declaration": ["error", "type-based", { "name": "props" } ]

interface Props {
  active: boolean;
}
// GOOD
const props = defineProps<Props>();
// BAD
const myProps = defineProps<Props>();

"vue/define-props-declaration": ["error", "type-based", { "prefix": true } ]

<template>
  <!-- GOOD-->
  {{ props.active }}
  <!-- BAD-->
  {{ active }}
  {{ $props.active }}
</template>

"vue/define-slots-declaration": ["error", "always", { "name": "slots", "prefix": true } ]

<template>
  <!-- GOOD-->
  {{ slots }}
  {{ slots.default }}
  <!-- BAD-->
  {{ $slots }}
  {{ $slots.default }}
</template>

"vue/define-attrs-declaration": ["error", "always", { "name": "attrs", "prefix": true } ]

<template>
  <!-- GOOD-->
  {{ attrs }}
  <!-- BAD-->
  {{ $attrs}}
</template>

What does the rule currently do for this code?
https://eslint.vuejs.org/rules/define-props-declaration.html

@FloEdelmann
Copy link
Member

Those are two different requests. The second one sounds like #2172; this should not be part of the vue/define-*-declaration rules.

The first one sounds good, but might also be better suited as a new rule (one for all, with good defaults). I suggest the name vue/require-macro-variable-name with one options object to customize the names. The default would be:

{
  defineProps: 'props',
  defineEmits: 'emit',
  defineSlots: 'slots',
  useSlots: 'slots',
  useAttrs: 'attrs',
}

@szulcus
Copy link
Author

szulcus commented May 23, 2023

@FloEdelmann I like your proposal :)

@szulcus szulcus changed the title Changes in vue/define-*-declaration New rule vue/require-macro-variable-name May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants