Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a5127b0

Browse files
FrontEndDogFloEdelmannwaynzh
authored
fix(valid-define-options): Allow the use of simple constants (#2920)
Co-authored-by: Flo Edelmann <git@flo-edelmann.de> Co-authored-by: waynzh <waynzh19@gmail.com>
1 parent 64f9880 commit a5127b0

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

‎.changeset/fresh-taxis-glow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-plugin-vue': minor
3+
---
4+
5+
Changed `vue/valid-define-options` to allow local literal constant references

‎lib/rules/valid-define-options.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,13 @@ module.exports = {
9393
(def) =>
9494
def.type !== 'ImportBinding' &&
9595
utils.inRange(scriptSetup.range, def.name) &&
96-
!utils.inRange(defineOptions.range, def.name)
96+
!utils.inRange(defineOptions.range, def.name) &&
97+
!(
98+
def.type === 'Variable' &&
99+
def.parent.kind === 'const' &&
100+
def.node.init &&
101+
def.node.init.type === 'Literal'
102+
)
97103
)
98104
) {
99105
if (utils.withinTypeNode(node)) {

‎tests/lib/rules/valid-define-options.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ tester.run('valid-define-options', rule, {
7474
7575
defineOptions(def);
7676
</script>`
77+
},
78+
{
79+
filename: 'test.vue',
80+
code: `
81+
<script setup>
82+
const def = 'foo';
83+
defineOptions({ name: def });
84+
</script>`
7785
}
7886
],
7987
invalid: [

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /