Skip to content

Commit cd33896

Browse files
committed
Add support for ignoring undefined variables by pattern.
1 parent 431928f commit cd33896

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ then in your ~/.eslintrc:
2222
}
2323
```
2424

25+
`jsx/no-undef` also accepts a `varsIgnorePattern` which can be used to ignore certain undefined patterns (e.g. when using custom web elements).
26+
2527
All those rules are defined by default though so you can leave out the ones you agree with.
2628

2729
## Thanks

index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ const markUsedRule = context => {
7171
*/
7272

7373
const noUndefRule = context => {
74+
const config = context.options[0] || {}
75+
const ignored = config.varsIgnorePattern && new RegExp(config.varsIgnorePattern)
76+
const isIgnored = ignored
77+
? name => ignored.test(name)
78+
: () => false
79+
7480
return {
7581
JSXOpeningElement(node) {
7682
var name = node.name
@@ -79,9 +85,9 @@ const noUndefRule = context => {
7985
const variables = variablesInScope(context)
8086
node.attributes.forEach(attr => {
8187
if (attr.type == 'JSXSpreadAttribute') return
82-
if (attr.value == null) checkDefined(context, variables, attr.name)
88+
if (attr.value == null && !isIgnored(attr.name.name)) checkDefined(context, variables, attr.name)
8389
})
84-
if (!standardTags.has(name.name)) checkDefined(context, variables, name)
90+
if (!standardTags.has(name.name) && !isIgnored(name.name)) checkDefined(context, variables, name)
8591
}
8692
}
8793
}

0 commit comments

Comments
 (0)