Movatterモバイル変換


[0]ホーム

URL:


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

Commit5ec36ce

Browse files
SysixFloEdelmann
andauthored
feat(no-import-compiler-macros): clarify that macros are not allowed outside<script setup> (#2938)
Co-authored-by: Flo Edelmann <git@flo-edelmann.de>
1 parent3bf079c commit5ec36ce

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

‎.changeset/lemon-socks-follow.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+
Updated`vue/no-import-compiler-macros` to clarify that macros are not allowed outside`<script setup>`

‎lib/rules/no-import-compiler-macros.js‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
'use strict'
66

7+
constutils=require('../utils')
8+
79
constCOMPILER_MACROS=newSet([
810
'defineProps',
911
'defineEmits',
@@ -35,7 +37,9 @@ module.exports = {
3537
schema:[],
3638
messages:{
3739
noImportCompilerMacros:
38-
"'{{name}}' is a compiler macro and doesn't need to be imported."
40+
"'{{name}}' is a compiler macro and doesn't need to be imported.",
41+
onlyValidInScriptSetup:
42+
"'{{name}}' is a compiler macro and can only be used inside <script setup>."
3943
}
4044
},
4145
/**
@@ -60,7 +64,9 @@ module.exports = {
6064

6165
context.report({
6266
node:specifier,
63-
messageId:'noImportCompilerMacros',
67+
messageId:utils.isScriptSetup(context)
68+
?'noImportCompilerMacros'
69+
:'onlyValidInScriptSetup',
6470
data:{
6571
name:specifier.imported.name
6672
},

‎tests/lib/rules/no-import-compiler-macros.js‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,54 @@ tester.run('no-import-compiler-macros', rule, {
214214
endColumn:60
215215
}
216216
]
217+
},
218+
{
219+
filename:'test.vue',
220+
code:`
221+
<script>
222+
// not in <script setup>
223+
import { defineProps } from 'vue'
224+
</script>
225+
`,
226+
output:`
227+
<script>
228+
// not in <script setup>
229+
230+
</script>
231+
`,
232+
errors:[
233+
{
234+
messageId:'onlyValidInScriptSetup',
235+
data:{
236+
name:'defineProps'
237+
},
238+
line:4,
239+
column:16,
240+
endLine:4,
241+
endColumn:27
242+
}
243+
]
244+
},
245+
{
246+
filename:'test.ts',
247+
code:`
248+
import { defineProps } from 'vue'
249+
`,
250+
output:`
251+
252+
`,
253+
errors:[
254+
{
255+
messageId:'onlyValidInScriptSetup',
256+
data:{
257+
name:'defineProps'
258+
},
259+
line:2,
260+
column:16,
261+
endLine:2,
262+
endColumn:27
263+
}
264+
]
217265
}
218266
]
219267
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp