Skip to content

Commit

Permalink
fix (vue/define-macros-order): hoist secondary expressions correctly (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
43081j committed Jan 7, 2023
1 parent 2c3d623 commit abdd93d
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/define-macros-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function create(context) {

// need move only second
if (secondStatement !== shouldSecondNode) {
reportNotOnTop(order[1], shouldSecondNode, shouldFirstNode)
reportNotOnTop(order[1], shouldSecondNode, secondStatement)
}

return
Expand Down
66 changes: 66 additions & 0 deletions tests/lib/rules/define-macros-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,26 @@ tester.run('define-macros-order', rule, {
parserOptions: {
parser: require.resolve('@typescript-eslint/parser')
}
},
{
filename: 'test.vue',
code: `
<script setup>
'use strict';
defineProps({
test: Boolean
})
defineEmits(['update:test'])
</script>
`,
options: optionsPropsFirst
},
{
filename: 'test.vue',
code: `
<script setup>
</script>
`
}
],
invalid: [
Expand Down Expand Up @@ -454,6 +474,52 @@ tester.run('define-macros-order', rule, {
line: 2
}
]
},
{
filename: 'test.vue',
code: `
<script setup>
console.log('test1')
defineProps({ test: Boolean })
</script>
`,
output: `
<script setup>
defineProps({ test: Boolean })
console.log('test1')
</script>
`,
options: optionsEmitsFirst,
errors: [
{
message: message('defineProps'),
line: 4
}
]
},
{
filename: 'test.vue',
code: `
<script setup>
defineEmits(['update:test'])
console.log('test1')
defineProps({ test: Boolean })
</script>
`,
output: `
<script setup>
defineEmits(['update:test'])
defineProps({ test: Boolean })
console.log('test1')
</script>
`,
options: optionsEmitsFirst,
errors: [
{
message: message('defineProps'),
line: 5
}
]
}
]
})

0 comments on commit abdd93d

Please sign in to comment.