Skip to content

Commit

Permalink
chore: use glob patterns instead of regex
Browse files Browse the repository at this point in the history
  • Loading branch information
akulsr0 committed Jul 12, 2024
1 parent 58c9063 commit b827d6b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/rules/jsx-handler-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Examples of **correct** code for this rule:
- `eventHandlerPropPrefix`: Prefix for props that are used as event handlers. Defaults to `on`
- `checkLocalVariables`: Determines whether event handlers stored as local variables are checked. Defaults to `false`
- `checkInlineFunction`: Determines whether event handlers set as inline functions are checked. Defaults to `false`
- `ignoreComponentNames`: Array of regex, when matched with component name, ignores the rule on that component. Defaults to `[]`
- `ignoreComponentNames`: Array of glob strings, when matched with component name, ignores the rule on that component. Defaults to `[]`

## When Not To Use It

Expand Down
5 changes: 3 additions & 2 deletions lib/rules/jsx-handler-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

'use strict';

const minimatch = require('minimatch');
const docsUrl = require('../util/docsUrl');
const getText = require('../util/eslint').getText;
const report = require('../util/report');
Expand Down Expand Up @@ -142,8 +143,8 @@ module.exports = {
JSXAttribute(node) {
const componentName = node.parent.name.name;

const isComponentNameIgnored = ignoreComponentNames.some((ignoredComponentNameRegex) => {
const isIgnored = new RegExp(ignoredComponentNameRegex).test(componentName);
const isComponentNameIgnored = ignoreComponentNames.some((ignoredComponentNamePattern) => {
const isIgnored = minimatch(componentName, ignoredComponentNamePattern);
return isIgnored;
});

Expand Down
4 changes: 2 additions & 2 deletions tests/lib/rules/jsx-handler-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ ruleTester.run('jsx-handler-names', rule, {
)
}
`,
options: [{ checkLocalVariables: true, ignoreComponentNames: ['^MyLib'] }],
options: [{ checkLocalVariables: true, ignoreComponentNames: ['MyLib**'] }],
},
]),

Expand Down Expand Up @@ -399,7 +399,7 @@ ruleTester.run('jsx-handler-names', rule, {
)
}
`,
options: [{ checkLocalVariables: true, ignoreComponentNames: ['^MyLibrary'] }],
options: [{ checkLocalVariables: true, ignoreComponentNames: ['MyLibrary**'] }],
errors: [
{
messageId: 'badPropKey',
Expand Down

0 comments on commit b827d6b

Please sign in to comment.