Skip to content

Commit b827d6b

Browse files
committed
chore: use glob patterns instead of regex
1 parent 58c9063 commit b827d6b

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

docs/rules/jsx-handler-names.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Examples of **correct** code for this rule:
4444
- `eventHandlerPropPrefix`: Prefix for props that are used as event handlers. Defaults to `on`
4545
- `checkLocalVariables`: Determines whether event handlers stored as local variables are checked. Defaults to `false`
4646
- `checkInlineFunction`: Determines whether event handlers set as inline functions are checked. Defaults to `false`
47-
- `ignoreComponentNames`: Array of regex, when matched with component name, ignores the rule on that component. Defaults to `[]`
47+
- `ignoreComponentNames`: Array of glob strings, when matched with component name, ignores the rule on that component. Defaults to `[]`
4848

4949
## When Not To Use It
5050

lib/rules/jsx-handler-names.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
'use strict';
77

8+
const minimatch = require('minimatch');
89
const docsUrl = require('../util/docsUrl');
910
const getText = require('../util/eslint').getText;
1011
const report = require('../util/report');
@@ -142,8 +143,8 @@ module.exports = {
142143
JSXAttribute(node) {
143144
const componentName = node.parent.name.name;
144145

145-
const isComponentNameIgnored = ignoreComponentNames.some((ignoredComponentNameRegex) => {
146-
const isIgnored = new RegExp(ignoredComponentNameRegex).test(componentName);
146+
const isComponentNameIgnored = ignoreComponentNames.some((ignoredComponentNamePattern) => {
147+
const isIgnored = minimatch(componentName, ignoredComponentNamePattern);
147148
return isIgnored;
148149
});
149150

tests/lib/rules/jsx-handler-names.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ ruleTester.run('jsx-handler-names', rule, {
197197
)
198198
}
199199
`,
200-
options: [{ checkLocalVariables: true, ignoreComponentNames: ['^MyLib'] }],
200+
options: [{ checkLocalVariables: true, ignoreComponentNames: ['MyLib**'] }],
201201
},
202202
]),
203203

@@ -399,7 +399,7 @@ ruleTester.run('jsx-handler-names', rule, {
399399
)
400400
}
401401
`,
402-
options: [{ checkLocalVariables: true, ignoreComponentNames: ['^MyLibrary'] }],
402+
options: [{ checkLocalVariables: true, ignoreComponentNames: ['MyLibrary**'] }],
403403
errors: [
404404
{
405405
messageId: 'badPropKey',

0 commit comments

Comments
 (0)