Skip to content

Commit

Permalink
Add support for defineOptions to `vue/padding-lines-in-component-de…
Browse files Browse the repository at this point in the history
…finition` rule (#2164)
  • Loading branch information
ota-meshi committed May 13, 2023
1 parent 28db555 commit 6b3736b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/rules/padding-lines-in-component-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,16 @@ module.exports = {
parseOption(emitsOption, OptionKeys.BetweenItems),
parseOption(emitsOption, OptionKeys.WithinEach)
)
},
onDefineOptionsEnter(node) {
if (node.arguments.length === 0) return
const define = node.arguments[0]
if (define.type !== 'ObjectExpression') return
verify(
define.properties,
parseOption(options, OptionKeys.BetweenOptions),
parseOption(options, OptionKeys.WithinOption)
)
}
})
)
Expand Down
40 changes: 40 additions & 0 deletions tests/lib/rules/padding-lines-in-component-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,19 @@ tester.run('padding-lines-in-component-definition', rule, {
</script>
`,
options: ['always']
},
{
filename: 'MyComment.vue',
code: `
<script setup>
defineOptions({
name: 'MyComment',
inheritAttrs: false,
})
</script>
`,
options: [{ betweenOptions: 'always', groupSingleLineProperties: false }]
}
],
invalid: [
Expand Down Expand Up @@ -1235,6 +1248,33 @@ tester.run('padding-lines-in-component-definition', rule, {
line: 16
}
]
},
{
filename: 'MyComment.vue',
code: `
<script setup>
defineOptions({
name: 'MyComment',
inheritAttrs: false,
})
</script>
`,
output: `
<script setup>
defineOptions({
name: 'MyComment',
inheritAttrs: false,
})
</script>
`,
options: [{ betweenOptions: 'always', groupSingleLineProperties: false }],
errors: [
{
message: 'Expected blank line before this definition.',
line: 5
}
]
}
]
})

0 comments on commit 6b3736b

Please sign in to comment.