Skip to content

Add a few tests & fix the macros-order rule #2067

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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 lib/rules/component-api-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function buildAllowedPhrase(allowsOpt) {
phrases.push('Options API')
}
return phrases.length > 2
? `${phrases.slice(0, -1).join(',')} or ${phrases.slice(-1)[0]}`
? `${phrases.slice(0, -1).join(', ')} or ${phrases.slice(-1)[0]}`
: phrases.join(' or ')
}

Expand Down
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
25 changes: 25 additions & 0 deletions tests/lib/rules/component-api-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,31 @@ tester.run('component-api-style', rule, {
column: 9
}
]
},
{
filename: 'test.vue',
code: `
<script>
export default {
data () {
return {
msg: 'Hello World!',
// ...
}
},
// ...
}
</script>
`,
options: [['script-setup', 'composition', 'composition-vue2']],
errors: [
{
message:
'Options API is not allowed in your project. `data` option is part of the Options API. Use `<script setup>`, Composition API or Composition API (Vue 2) instead.',
line: 4,
column: 9
}
]
}
]
})
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
}
]
}
]
})
21 changes: 21 additions & 0 deletions tests/lib/rules/max-attributes-per-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,27 @@ job="Vet"></component></template>`,
options: [{ singleline: 3, multiline: 1 }],
output: `<template><component
name="John Doe"
age="30"
job="Vet">
</component>
</template>`,
errors: [
{
message: "'age' should be on a new line.",
type: 'VAttribute',
line: 2
}
]
},
{
code: `<template><component
name="John Doe" age="30"
job="Vet">
</component>
</template>`,
options: [{ multiline: { max: 1 } }],
output: `<template><component
name="John Doe"
age="30"
job="Vet">
</component>
Expand Down