Skip to content

Add vue/valid-define-options to vue3-essential config #2653

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

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/rules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Rules in this category are enabled for all presets provided by eslint-plugin-vue
| [vue/use-v-on-exact] | enforce usage of `exact` modifier on `v-on` | | :three::two::hammer: |
| [vue/valid-attribute-name] | require valid attribute names | | :three::two::warning: |
| [vue/valid-define-emits] | enforce valid `defineEmits` compiler macro | | :three::two::warning: |
| [vue/valid-define-options] | enforce valid `defineOptions` compiler macro | | :three::two::warning: |
| [vue/valid-define-props] | enforce valid `defineProps` compiler macro | | :three::two::warning: |
| [vue/valid-model-definition] | require valid keys in model option | | :two::warning: |
| [vue/valid-next-tick] | enforce valid `nextTick` function calls | :wrench::bulb: | :three::two::warning: |
Expand Down Expand Up @@ -288,7 +289,6 @@ For example:
| [vue/v-for-delimiter-style] | enforce `v-for` directive's delimiter style | :wrench: | :lipstick: |
| [vue/v-if-else-key] | require key attribute for conditionally rendered repeated components | :wrench: | :warning: |
| [vue/v-on-handler-style] | enforce writing style for handlers in `v-on` directives | :wrench: | :hammer: |
| [vue/valid-define-options] | enforce valid `defineOptions` compiler macro | | :warning: |

</rules-table>

Expand Down
2 changes: 2 additions & 0 deletions docs/rules/valid-define-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ since: v9.13.0

> enforce valid `defineOptions` compiler macro

- :gear: This rule is included in all of `"plugin:vue/essential"`, `*.configs["flat/essential"]`, `"plugin:vue/vue2-essential"`, `*.configs["flat/vue2-essential"]`, `"plugin:vue/strongly-recommended"`, `*.configs["flat/strongly-recommended"]`, `"plugin:vue/vue2-strongly-recommended"`, `*.configs["flat/vue2-strongly-recommended"]`, `"plugin:vue/recommended"`, `*.configs["flat/recommended"]`, `"plugin:vue/vue2-recommended"` and `*.configs["flat/vue2-recommended"]`.

This rule checks whether `defineOptions` compiler macro is valid.

## :book: Rule Details
Expand Down
1 change: 1 addition & 0 deletions lib/configs/flat/vue2-essential.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module.exports = [
'vue/use-v-on-exact': 'error',
'vue/valid-attribute-name': 'error',
'vue/valid-define-emits': 'error',
'vue/valid-define-options': 'error',
'vue/valid-define-props': 'error',
'vue/valid-model-definition': 'error',
'vue/valid-next-tick': 'error',
Expand Down
1 change: 1 addition & 0 deletions lib/configs/flat/vue3-essential.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ module.exports = [
'vue/use-v-on-exact': 'error',
'vue/valid-attribute-name': 'error',
'vue/valid-define-emits': 'error',
'vue/valid-define-options': 'error',
'vue/valid-define-props': 'error',
'vue/valid-next-tick': 'error',
'vue/valid-template-root': 'error',
Expand Down
1 change: 1 addition & 0 deletions lib/configs/vue2-essential.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ module.exports = {
'vue/use-v-on-exact': 'error',
'vue/valid-attribute-name': 'error',
'vue/valid-define-emits': 'error',
'vue/valid-define-options': 'error',
'vue/valid-define-props': 'error',
'vue/valid-model-definition': 'error',
'vue/valid-next-tick': 'error',
Expand Down
1 change: 1 addition & 0 deletions lib/configs/vue3-essential.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ module.exports = {
'vue/use-v-on-exact': 'error',
'vue/valid-attribute-name': 'error',
'vue/valid-define-emits': 'error',
'vue/valid-define-options': 'error',
'vue/valid-define-props': 'error',
'vue/valid-next-tick': 'error',
'vue/valid-template-root': 'error',
Expand Down
4 changes: 1 addition & 3 deletions lib/rules/valid-define-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ module.exports = {
type: 'problem',
docs: {
description: 'enforce valid `defineOptions` compiler macro',
// TODO Switch in the next major version
// categories: ['vue3-essential', 'vue2-essential'],
categories: undefined,
categories: ['vue3-essential', 'vue2-essential'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is defineOptions even supported in Vue 2? If not, then it makes no sense to add this rule to the vue2-essentials config.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can only be used in <script setup> syntax. Removed ✅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vue 2.7 added support for <script setup> (see https://blog.vuejs.org/posts/vue-2-7-naruto), but I think defineOptions was added later to Vue 3 and never backported to Vue 2.

Copy link
Member Author

@waynzh waynzh Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I'm not very familiar with Vue 2.7, I'll check whether defineOptions was introduced in Vue 2.7.
Since vue/valid-define-emits and vue/valid-define-props are in the essential category for both Vue 2 and Vue 3.

Update: Yep, you're right, defineOptions was never added back to Vue 2. So, setting the category as vue3-essential should be enough.

url: 'https://eslint.vuejs.org/rules/valid-define-options.html'
},
fixable: null,
Expand Down