Skip to content

Commit 5fc8bed

Browse files
committed
feat: change to suggestion
1 parent 39bc85d commit 5fc8bed

File tree

2 files changed

+69
-50
lines changed

2 files changed

+69
-50
lines changed

lib/rules/define-macros-order.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,14 @@ function create(context) {
196196
node,
197197
loc: node.loc,
198198
messageId: 'defineExposeNotTheLast',
199-
fix(fixer) {
200-
return moveNodeToLast(fixer, node, lastNode)
201-
}
199+
suggest: [
200+
{
201+
messageId: 'putExposeAtTheLast',
202+
fix(fixer) {
203+
return moveNodeToLast(fixer, node, lastNode)
204+
}
205+
}
206+
]
202207
})
203208
}
204209

@@ -228,13 +233,8 @@ function create(context) {
228233
node.range[0] - beforeNodeToken.range[1]
229234
)
230235

231-
// insert position: after target and comments (if any)
232-
const afterTargetComment = sourceCode.getTokenAfter(target, {
233-
includeComments: true
234-
})
235-
236236
return [
237-
fixer.insertTextAfter(afterTargetComment, textNode),
237+
fixer.insertTextAfter(target, textNode),
238238
fixer.removeRange([cutStart, cutEnd])
239239
]
240240
}
@@ -322,6 +322,7 @@ module.exports = {
322322
url: 'https://eslint.vuejs.org/rules/define-macros-order.html'
323323
},
324324
fixable: 'code',
325+
hasSuggestions: true,
325326
schema: [
326327
{
327328
type: 'object',
@@ -345,7 +346,9 @@ module.exports = {
345346
macrosNotOnTop:
346347
'{{macro}} should be the first statement in `<script setup>` (after any potential import statements or type definitions).',
347348
defineExposeNotTheLast:
348-
'`defineExpose` should be the last statement in `<script setup>`.'
349+
'`defineExpose` should be the last statement in `<script setup>`.',
350+
putExposeAtTheLast:
351+
'Put `defineExpose` as the last statement in `<script setup>`.'
349352
}
350353
},
351354
create

tests/lib/rules/define-macros-order.js

+56-40
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ function message(macro) {
4040
const defineExposeNotTheLast =
4141
'`defineExpose` should be the last statement in `<script setup>`.'
4242

43+
const putExposeAtBottom =
44+
'Put `defineExpose` as the last statement in `<script setup>`.'
45+
4346
tester.run('define-macros-order', rule, {
4447
valid: [
4548
{
@@ -678,58 +681,52 @@ tester.run('define-macros-order', rule, {
678681
filename: 'test.vue',
679682
code: `
680683
<script setup>
681-
defineProps({
682-
test: Boolean
683-
})
684-
685-
/** expose */
686-
defineExpose({
687-
foo: 'bar'
688-
})
689-
690-
/** console start */
691-
console.log('test')
692-
/** console end */
693-
</script>
694-
`,
695-
output: `
696-
<script setup>
697-
defineProps({
698-
test: Boolean
699-
})
700-
701-
/** console start */
702-
console.log('test')
703-
/** console end */
704-
705-
/** expose */
706-
defineExpose({
707-
foo: 'bar'
708-
})
684+
/** emits */
685+
defineEmits(['update:foo'])
686+
/** expose */
687+
defineExpose({})
688+
/** slots */
689+
const slots = defineSlots()
709690
</script>
710691
`,
692+
output: null,
711693
options: optionsExposeLast,
712694
errors: [
713695
{
714696
message: defineExposeNotTheLast,
715-
line: 8
697+
line: 6,
698+
suggestions: [
699+
{
700+
desc: putExposeAtBottom,
701+
output: `
702+
<script setup>
703+
/** emits */
704+
defineEmits(['update:foo'])
705+
/** slots */
706+
const slots = defineSlots()
707+
/** expose */
708+
defineExpose({})
709+
</script>
710+
`
711+
}
712+
]
716713
}
717714
]
718715
},
719716
{
720717
filename: 'test.vue',
721718
code: `
722719
<script setup>
723-
/** slots */
724-
const slots = defineSlots()
725-
/** options */
726-
defineOptions({})
727720
/** emits */
728721
defineEmits(['update:foo'])
729722
/** expose */
730723
defineExpose({})
724+
/** options */
725+
defineOptions({})
731726
/** props */
732727
const props = defineProps(['foo'])
728+
/** slots */
729+
const slots = defineSlots()
733730
</script>
734731
`,
735732
output: `
@@ -738,28 +735,47 @@ tester.run('define-macros-order', rule, {
738735
defineOptions({})
739736
/** emits */
740737
defineEmits(['update:foo'])
738+
/** expose */
739+
defineExpose({})
741740
/** props */
742741
const props = defineProps(['foo'])
743742
/** slots */
744743
const slots = defineSlots()
745-
/** expose */
746-
defineExpose({})
747744
</script>
748745
`,
749746
options: [
750747
{
751-
order: ['defineOptions', 'defineEmits', 'defineProps', 'defineSlots'],
748+
order: ['defineOptions', 'defineEmits', 'defineProps'],
752749
defineExposeLast: true
753750
}
754751
],
755752
errors: [
756753
{
757-
message: message('defineOptions'),
758-
line: 6
754+
message: defineExposeNotTheLast,
755+
line: 6,
756+
suggestions: [
757+
{
758+
desc: putExposeAtBottom,
759+
output: `
760+
<script setup>
761+
/** emits */
762+
defineEmits(['update:foo'])
763+
/** options */
764+
defineOptions({})
765+
/** props */
766+
const props = defineProps(['foo'])
767+
/** slots */
768+
const slots = defineSlots()
769+
/** expose */
770+
defineExpose({})
771+
</script>
772+
`
773+
}
774+
]
759775
},
760776
{
761-
message: defineExposeNotTheLast,
762-
line: 10
777+
message: message('defineOptions'),
778+
line: 8
763779
}
764780
]
765781
}

0 commit comments

Comments
 (0)