Skip to content

Commit f95559e

Browse files
author
Arthur Geron
committed
fix: minimatch should ignore set to "false" not working
1 parent 7e2be6f commit f95559e

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

__tests__/require-usememo.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,20 @@ describe('Rule - Require-usememo', () => {
581581
}`,
582582
errors: [{ messageId: "object-usememo-props" }],
583583
},
584+
{
585+
code: `import { useMemo } from 'react';
586+
function useTesty() {
587+
const x = {};
588+
return useDataManager(x);
589+
}`,
590+
options: [{ checkHookReturnObject: true, ignoredHookCallsNames: {"useData*": false} }],
591+
output: `import { useMemo } from 'react';
592+
function useTesty() {
593+
const x = useMemo(() => ({}), []);
594+
return useDataManager(x);
595+
}`,
596+
errors: [{ messageId: "object-usememo-deps" }],
597+
},
584598
{
585599
code: `
586600
const useTest = () => {

src/utils/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,20 @@ export function shouldIgnoreNode(node: ESNode, ignoredNames: Record<string, bool
131131
}
132132

133133
// Checking via patterns
134-
const shouldIgnore = Object.keys(ignoredNames).find(key => {
134+
let shouldIgnore;
135+
136+
Object.keys(ignoredNames).find(key => {
135137
const value = ignoredNames[key];
136138
const miniMatch = new Minimatch(key);
137139
if (miniMatch.hasMagic()) {
138140
const isMatch = (nameToCheck && miniMatch.match(nameToCheck));
139141
if (isMatch) {
140-
return !!value;
142+
shouldIgnore = !!value;
143+
return true;
141144
}
142145
}
143146
return false;
144147
});
145148

146-
return shouldIgnore != undefined ? shouldIgnore : false;
149+
return !!shouldIgnore;
147150
}

0 commit comments

Comments
 (0)