Skip to content

Commit 15a9c1b

Browse files
authored
Exclude JavaScript components in vue/require-typed-object-prop (#2505)
1 parent 2c64a89 commit 15a9c1b

File tree

2 files changed

+185
-169
lines changed

2 files changed

+185
-169
lines changed

lib/rules/require-typed-object-prop.js

+24
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,30 @@ module.exports = {
129129
},
130130
/** @param {RuleContext} context */
131131
create(context) {
132+
const filename = context.getFilename()
133+
if (!utils.isVueFile(filename) && !utils.isTypeScriptFile(filename)) {
134+
return {}
135+
}
136+
137+
if (utils.isVueFile(filename)) {
138+
const sourceCode = context.getSourceCode()
139+
const documentFragment =
140+
sourceCode.parserServices.getDocumentFragment &&
141+
sourceCode.parserServices.getDocumentFragment()
142+
if (!documentFragment) {
143+
return {}
144+
}
145+
const scripts = documentFragment.children.filter(
146+
/** @returns {element is VElement} */
147+
(element) => utils.isVElement(element) && element.name === 'script'
148+
)
149+
if (
150+
scripts.every((script) => !utils.hasAttribute(script, 'lang', 'ts'))
151+
) {
152+
return {}
153+
}
154+
}
155+
132156
return utils.compositingVisitors(
133157
utils.defineScriptSetupVisitor(context, {
134158
onDefinePropsEnter(_node, props) {

0 commit comments

Comments
 (0)