diff --git a/.github/workflows/check-for-resources-update.yml b/.github/workflows/check-for-resources-update.yml index 613125fc3..31f881b1d 100644 --- a/.github/workflows/check-for-resources-update.yml +++ b/.github/workflows/check-for-resources-update.yml @@ -5,12 +5,13 @@ on: - cron: 0 0 * * 0 # At 00:00 on Sunday, see https://crontab.guru/#0_0_*_*_0 permissions: - contents: write - pull-requests: write + contents: write + pull-requests: write jobs: check-for-resources-update: runs-on: ubuntu-latest + if: ${{ github.repository == 'vuejs/eslint-plugin-vue' }} steps: - name: Checkout uses: actions/checkout@v4 diff --git a/README.md b/README.md index 95e0c08be..bdeb5e167 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![NPM version](https://img.shields.io/npm/v/eslint-plugin-vue.svg?style=flat)](https://npmjs.org/package/eslint-plugin-vue) [![NPM downloads](https://img.shields.io/npm/dm/eslint-plugin-vue.svg?style=flat)](https://npmjs.org/package/eslint-plugin-vue) -[![CircleCI](https://img.shields.io/circleci/project/github/vuejs/eslint-plugin-vue/master.svg?style=flat)](https://circleci.com/gh/vuejs/eslint-plugin-vue) +[![CI](https://img.shields.io/github/actions/workflow/status/vuejs/eslint-plugin-vue/CI.yml?style=flat&label=CI)](https://github.com/vuejs/eslint-plugin-vue/actions/workflows/CI.yml) [![License](https://img.shields.io/github/license/vuejs/eslint-plugin-vue.svg?style=flat)](https://github.com/vuejs/eslint-plugin-vue/blob/master/LICENSE) > Official ESLint plugin for Vue.js diff --git a/docs/rules/define-emits-declaration.md b/docs/rules/define-emits-declaration.md index 7a11524c5..c24f5ec62 100644 --- a/docs/rules/define-emits-declaration.md +++ b/docs/rules/define-emits-declaration.md @@ -35,8 +35,8 @@ const emit = defineEmits<{ /* ✗ BAD */ const emit = defineEmits({ - change: (id) => typeof id == 'number', - update: (value) => typeof value == 'string' + change: (id) => typeof id === 'number', + update: (value) => typeof value === 'string' }) /* ✗ BAD */ @@ -70,8 +70,8 @@ const emit = defineEmits<{ /* ✓ GOOD */ const emit = defineEmits({ - change: (id) => typeof id == 'number', - update: (value) => typeof value == 'string' + change: (id) => typeof id === 'number', + update: (value) => typeof value === 'string' }) /* ✓ GOOD */ @@ -92,8 +92,8 @@ const emit = defineEmits(['change', 'update']) /* ✗ BAD */ const emit = defineEmits({ - change: (id) => typeof id == 'number', - update: (value) => typeof value == 'string' + change: (id) => typeof id === 'number', + update: (value) => typeof value === 'string' }) /* ✗ BAD */ 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 `