Skip to content

Commit

Permalink
Fix detect Vue3 defineComponent (#1088)
Browse files Browse the repository at this point in the history
Co-authored-by: Yosuke Ota <otameshiyo23@gmail.com>
  • Loading branch information
yoyo930021 and ota-meshi committed Apr 21, 2020
1 parent 8d3c99a commit cadec3b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/utils/index.js
Expand Up @@ -550,6 +550,12 @@ module.exports = {
const isAppVueComponent = isObjectArgument(node)
return isAppVueComponent
}
if (callee.name === 'defineComponent') {
// for Vue.js 3.x
// defineComponent({})
const isDestructedVueComponent = isObjectArgument(node)
return isDestructedVueComponent
}
}
}

Expand Down
38 changes: 38 additions & 0 deletions tests/lib/rules/no-dupe-keys.js
Expand Up @@ -639,6 +639,44 @@ ruleTester.run('no-dupe-keys', rule, {
message: 'Duplicated key \'foo\'.',
line: 9
}]
},
{
filename: 'test.js',
code: `
defineComponent({
foo: {
bar: String
},
data: {
bar: null
},
})
`,
options: [{ groups: ['foo'] }],
parserOptions: { ecmaVersion: 6 },
errors: [{
message: 'Duplicated key \'bar\'.',
line: 7
}]
},
{
filename: 'test.js',
code: `
export default defineComponent({
foo: {
bar: String
},
data: {
bar: null
},
})
`,
options: [{ groups: ['foo'] }],
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
errors: [{
message: 'Duplicated key \'bar\'.',
line: 7
}]
}
]
})
6 changes: 6 additions & 0 deletions tests/lib/utils/vue-component.js
Expand Up @@ -311,6 +311,12 @@ function invalidTests (ext) {
`,
parserOptions,
errors: (ext === 'js' ? [] : [makeError(2)]).concat([makeError(8)])
},
{
filename: `test.${ext}`,
code: `export default defineComponent({})`,
parserOptions,
errors: [makeError(1)]
}
]
}
Expand Down

0 comments on commit cadec3b

Please sign in to comment.