Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commited320a7

Browse files
committed
fix(no-v-html): add CallExpression support to ignorePattern option (#2949)
This commit extends the `ignorePattern` option to support function call expressionslike `$sanitize(test)`, not just simple variable identifiers like `htmlSafe`.Changes:- Add new `shouldIgnore()` helper function that handles both Identifier and CallExpression expression types- For Identifiers, use the `name` property directly for optimal performance- For CallExpressions and other expression types, use `sourceCode.getText()` to get the full expression text- Update the visitor to pass `sourceCode` to the new helper functionThis allows users to configure patterns like `^\$sanitize\(` to match functioncall expressions where the function name matches the pattern.Tests:- Add test case for CallExpression matching with ignorePattern `^\$sanitize\(`- All existing tests continue to pass
1 parent5ec36ce commited320a7

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

‎lib/rules/no-v-html.js‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,37 @@ module.exports = {
3636
?newRegExp(options.ignorePattern,'u')
3737
:undefined
3838

39+
/**
40+
* Check if the expression matches the ignore pattern
41+
*@param {VExpressionContainer['expression']} expression
42+
*@param {SourceCode} sourceCode
43+
*@returns {boolean}
44+
*/
45+
functionshouldIgnore(expression,sourceCode){
46+
if(!ignoreRegEx||!expression){
47+
returnfalse
48+
}
49+
50+
// For simple identifiers, use the name property directly (optimized)
51+
if(expression.type==='Identifier'){
52+
returnignoreRegEx.test(expression.name)
53+
}
54+
55+
// For other expression types (e.g., CallExpression), get the full text
56+
constexpressionText=sourceCode.getText(expression)
57+
returnignoreRegEx.test(expressionText)
58+
}
59+
3960
returnutils.defineTemplateBodyVisitor(context,{
4061
/**@param {VDirective} node */
4162
"VAttribute[directive=true][key.name.name='html']"(node){
63+
constsourceCode=context.sourceCode
64+
4265
if(
43-
ignoreRegEx&&
4466
node.value&&
4567
node.value.expression&&
46-
node.value.expression.type==='Identifier'&&
47-
ignoreRegEx.test(node.value.expression.name)
68+
sourceCode&&
69+
shouldIgnore(node.value.expression,sourceCode)
4870
){
4971
return
5072
}

‎tests/lib/rules/no-v-html.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ ruleTester.run('no-v-html', rule, {
3333
filename:'test.vue',
3434
code:'<template><div v-html="htmlKnownToBeSafe"></div></template>',
3535
options:[{ignorePattern:'^html'}]
36+
},
37+
{
38+
filename:'test.vue',
39+
code:'<template><div v-html="$sanitize(test)"></div></template>',
40+
options:[{ignorePattern:String.raw`^\$sanitize\(`}]
3641
}
3742
],
3843
invalid:[

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp