Skip to content

Add support for defineOptions to vue/component-definition-name-casing rule #2159

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

Merged
merged 1 commit into from
May 13, 2023
Merged
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
14 changes: 12 additions & 2 deletions lib/rules/component-definition-name-casing.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ module.exports = {
}
}

return Object.assign(
{},
return utils.compositingVisitors(
utils.executeOnCallVueComponent(context, (node) => {
if (node.arguments.length === 2) {
const argument = node.arguments[0]
Expand All @@ -94,6 +93,17 @@ module.exports = {
if (!node) return
if (!canConvert(node.value)) return
convertName(node.value)
}),
utils.defineScriptSetupVisitor(context, {
onDefineOptionsEnter(node) {
if (node.arguments.length === 0) return
const define = node.arguments[0]
if (define.type !== 'ObjectExpression') return
const nameNode = utils.findProperty(define, 'name')
if (!nameNode) return
if (!canConvert(nameNode.value)) return
convertName(nameNode.value)
}
})
)
}
Expand Down
48 changes: 48 additions & 0 deletions tests/lib/rules/component-definition-name-casing.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,26 @@ ruleTester.run('component-definition-name-casing', rule, {
filename: 'test.js',
code: `fn1(component.data)`,
parserOptions
},
{
filename: 'test.vue',
code: `<script setup> defineOptions({}) </script>`,
parser: require.resolve('vue-eslint-parser'),
parserOptions
},
{
filename: 'test.vue',
code: `<script setup> defineOptions({name: 'FooBar'}) </script>`,
options: ['PascalCase'],
parser: require.resolve('vue-eslint-parser'),
parserOptions
},
{
filename: 'test.vue',
code: `<script setup> defineOptions({name: 'foo-bar'}) </script>`,
options: ['kebab-case'],
parser: require.resolve('vue-eslint-parser'),
parserOptions
}
],

Expand Down Expand Up @@ -393,6 +413,34 @@ ruleTester.run('component-definition-name-casing', rule, {
line: 1
}
]
},
{
filename: 'test.vue',
code: `<script setup> defineOptions({name: 'foo-bar'}) </script>`,
output: `<script setup> defineOptions({name: 'FooBar'}) </script>`,
options: ['PascalCase'],
parser: require.resolve('vue-eslint-parser'),
parserOptions,
errors: [
{
message: 'Property name "foo-bar" is not PascalCase.',
line: 1
}
]
},
{
filename: 'test.vue',
code: `<script setup> defineOptions({name: 'FooBar'}) </script>`,
output: `<script setup> defineOptions({name: 'foo-bar'}) </script>`,
options: ['kebab-case'],
parser: require.resolve('vue-eslint-parser'),
parserOptions,
errors: [
{
message: 'Property name "FooBar" is not kebab-case.',
line: 1
}
]
}
]
})