Skip to content

Commit

Permalink
Exclude JavaScript components in vue/require-typed-object-prop (#2505)
Browse files Browse the repository at this point in the history
  • Loading branch information
FloEdelmann authored Jul 13, 2024
1 parent 2c64a89 commit 15a9c1b
Show file tree
Hide file tree
Showing 2 changed files with 185 additions and 169 deletions.
24 changes: 24 additions & 0 deletions lib/rules/require-typed-object-prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,30 @@ module.exports = {
},
/** @param {RuleContext} context */
create(context) {
const filename = context.getFilename()
if (!utils.isVueFile(filename) && !utils.isTypeScriptFile(filename)) {
return {}
}

if (utils.isVueFile(filename)) {
const sourceCode = context.getSourceCode()
const documentFragment =
sourceCode.parserServices.getDocumentFragment &&
sourceCode.parserServices.getDocumentFragment()
if (!documentFragment) {
return {}
}
const scripts = documentFragment.children.filter(
/** @returns {element is VElement} */
(element) => utils.isVElement(element) && element.name === 'script'
)
if (
scripts.every((script) => !utils.hasAttribute(script, 'lang', 'ts'))
) {
return {}
}
}

return utils.compositingVisitors(
utils.defineScriptSetupVisitor(context, {
onDefinePropsEnter(_node, props) {
Expand Down
Loading

0 comments on commit 15a9c1b

Please sign in to comment.