|
| 1 | +--- |
| 2 | +pageClass: rule-details |
| 3 | +sidebarDepth: 0 |
| 4 | +title: vue/require-macro-variable-name |
| 5 | +description: require a certain macro variable name |
| 6 | +--- |
| 7 | +# vue/require-macro-variable-name |
| 8 | + |
| 9 | +> require a certain macro variable name |
| 10 | +
|
| 11 | +- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge> |
| 12 | +- :bulb: Some problems reported by this rule are manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). |
| 13 | + |
| 14 | +## :book: Rule Details |
| 15 | + |
| 16 | +This rule reports macro variables not corresponding to the specified name. |
| 17 | + |
| 18 | +<eslint-code-block :rules="{'vue/require-macro-variable-name': ['error']}"> |
| 19 | + |
| 20 | +```vue |
| 21 | +<!-- ✓ GOOD --> |
| 22 | +<script setup> |
| 23 | +const props = defineProps({ msg: String }) |
| 24 | +const emit = defineEmits(['update:msg']) |
| 25 | +</script> |
| 26 | +``` |
| 27 | + |
| 28 | +</eslint-code-block> |
| 29 | + |
| 30 | +<eslint-code-block :rules="{'vue/require-macro-variable-name': ['error']}"> |
| 31 | + |
| 32 | +```vue |
| 33 | +<!-- ✗ BAD --> |
| 34 | +<script setup> |
| 35 | +const propsDefined = defineProps({ msg: String }) |
| 36 | +const emitsDefined = defineEmits(['update:msg']) |
| 37 | +</script> |
| 38 | +``` |
| 39 | + |
| 40 | +</eslint-code-block> |
| 41 | + |
| 42 | +## :wrench: Options |
| 43 | + |
| 44 | +```json |
| 45 | +{ |
| 46 | + "vue/require-macro-variable-name": ["error", { |
| 47 | + "defineProps": "props", |
| 48 | + "defineEmits": "emit", |
| 49 | + "defineSlots": "slots", |
| 50 | + "useSlots": "slots", |
| 51 | + "useAttrs": "attrs" |
| 52 | + }] |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +- `defineProps` - The name of the macro variable for `defineProps`. default: `props` |
| 57 | +- `defineEmits` - The name of the macro variable for `defineEmits`. default: `emit` |
| 58 | +- `defineSlots` - The name of the macro variable for `defineSlots`. default: `slots` |
| 59 | +- `useSlots` - The name of the macro variable for `useSlots`. default: `slots` |
| 60 | +- `useAttrs` - The name of the macro variable for `useAttrs`. default: `attrs` |
| 61 | + |
| 62 | +### With custom macro variable names |
| 63 | + |
| 64 | +<eslint-code-block :rules="{'vue/require-macro-variable-name': ['error', { |
| 65 | + 'defineProps': 'propsCustom', |
| 66 | + 'defineEmits': 'emitCustom', |
| 67 | + 'defineSlots': 'slotsCustom', |
| 68 | + 'useSlots': 'slotsCustom', |
| 69 | + 'useAttrs': 'attrsCustom' |
| 70 | + }]}"> |
| 71 | + |
| 72 | +```vue |
| 73 | +<script setup> |
| 74 | +const slotsCustom = defineSlots() |
| 75 | +const attrsCustom = useAttrs() |
| 76 | +</script> |
| 77 | +``` |
| 78 | + |
| 79 | +</eslint-code-block> |
| 80 | + |
| 81 | +## :mag: Implementation |
| 82 | + |
| 83 | +- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/require-macro-variable-name.js) |
| 84 | +- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/require-macro-variable-name.js) |
0 commit comments