diff --git a/docs/rules/define-props-destructuring.md b/docs/rules/define-props-destructuring.md new file mode 100644 index 000000000..e3c2b2745 --- /dev/null +++ b/docs/rules/define-props-destructuring.md @@ -0,0 +1,98 @@ +--- +pageClass: rule-details +sidebarDepth: 0 +title: vue/define-props-destructuring +description: enforce consistent style for props destructuring +since: v10.1.0 +--- + +# vue/define-props-destructuring + +> enforce consistent style for props destructuring + +## :book: Rule Details + +This rule enforces a consistent style for handling Vue 3 Composition API props, allowing you to choose between requiring destructuring or prohibiting it. + +By default, the rule requires you to use destructuring syntax when using `defineProps` instead of storing props in a variable and warns against combining `withDefaults` with destructuring. + + + +```vue + +``` + + + +The rule applies to both JavaScript and TypeScript props: + + + +```vue + +``` + + + +## :wrench: Options + +```js +{ + "vue/define-props-destructuring": ["error", { + "destructure": "always" | "never" + }] +} +``` + +- `destructure` - Sets the destructuring preference for props + - `"always"` (default) - Requires destructuring when using `defineProps` and warns against using `withDefaults` with destructuring + - `"never"` - Requires using a variable to store props and prohibits destructuring + +### `"destructure": "never"` + + + +```vue + +``` + + + +## :books: Further Reading + +- [Reactive Props Destructure](https://vuejs.org/guide/components/props.html#reactive-props-destructure) + +## :rocket: Version + +This rule was introduced in eslint-plugin-vue v10.1.0 + +## :mag: Implementation + +- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/define-props-destructuring.js) +- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/define-props-destructuring.js) diff --git a/docs/rules/index.md b/docs/rules/index.md index 55c5b96c9..7828b58bb 100644 --- a/docs/rules/index.md +++ b/docs/rules/index.md @@ -218,6 +218,7 @@ For example: | [vue/define-emits-declaration] | enforce declaration style of `defineEmits` | | :hammer: | | [vue/define-macros-order] | enforce order of compiler macros (`defineProps`, `defineEmits`, etc.) | :wrench::bulb: | :lipstick: | | [vue/define-props-declaration] | enforce declaration style of `defineProps` | | :hammer: | +| [vue/define-props-destructuring] | enforce consistent style for props destructuring | | :hammer: | | [vue/enforce-style-attribute] | enforce or forbid the use of the `scoped` and `module` attributes in SFC top level style tags | | :hammer: | | [vue/html-button-has-type] | disallow usage of button without an explicit type attribute | | :hammer: | | [vue/html-comment-content-newline] | enforce unified line break in HTML comments | :wrench: | :lipstick: | @@ -398,6 +399,7 @@ The following rules extend the rules provided by ESLint itself and apply them to [vue/define-emits-declaration]: ./define-emits-declaration.md [vue/define-macros-order]: ./define-macros-order.md [vue/define-props-declaration]: ./define-props-declaration.md +[vue/define-props-destructuring]: ./define-props-destructuring.md [vue/dot-location]: ./dot-location.md [vue/dot-notation]: ./dot-notation.md [vue/enforce-style-attribute]: ./enforce-style-attribute.md diff --git a/docs/rules/no-bare-strings-in-template.md b/docs/rules/no-bare-strings-in-template.md index df1fae123..23a23c116 100644 --- a/docs/rules/no-bare-strings-in-template.md +++ b/docs/rules/no-bare-strings-in-template.md @@ -12,7 +12,7 @@ since: v7.0.0 ## :book: Rule Details -This rule disallows the use of bare strings in ` ` + }, + { + filename: 'test.vue', + code: ` + + `, + options: [{ disallowComments: false }] + }, + { + filename: 'test.vue', + code: ` + + `, + options: [{ disallowComments: false }] + }, + { + filename: 'test.vue', + code: ` + + `, + options: [{ disallowComments: true }] + }, + { + filename: 'test.vue', + code: ` + + `, + options: [{ disallowComments: true }] } ], invalid: [ @@ -104,6 +164,132 @@ ruleTester.run('no-multiple-template-root', rule, { filename: 'test.vue', code: '', errors: ["The template root disallows '