Skip to content

Commit

Permalink
fix: minimatch should ignore set to "false" not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Geron committed Jan 20, 2024
1 parent b581a26 commit f8f9441
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
14 changes: 14 additions & 0 deletions __tests__/require-usememo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,20 @@ describe('Rule - Require-usememo', () => {
}`,
errors: [{ messageId: "object-usememo-props" }],
},
{
code: `import { useMemo } from 'react';
function useTesty() {
const x = {};
return useDataManager(x);
}`,
options: [{ checkHookReturnObject: true, ignoredHookCallsNames: {"useData*": false} }],
output: `import { useMemo } from 'react';
function useTesty() {
const x = useMemo(() => ({}), []);
return useDataManager(x);
}`,
errors: [{ messageId: "object-usememo-deps" }],
},
{
code: `
const useTest = () => {
Expand Down
9 changes: 6 additions & 3 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,20 @@ export function shouldIgnoreNode(node: ESNode, ignoredNames: Record<string, bool
}

// Checking via patterns
const shouldIgnore = Object.keys(ignoredNames).find(key => {
let shouldIgnore;

Object.keys(ignoredNames).find(key => {
const value = ignoredNames[key];
const miniMatch = new Minimatch(key);
if (miniMatch.hasMagic()) {
const isMatch = (nameToCheck && miniMatch.match(nameToCheck));
if (isMatch) {
return !!value;
shouldIgnore = !!value;
return true;
}
}
return false;
});

return shouldIgnore != undefined ? shouldIgnore : false;
return !!shouldIgnore;
}

0 comments on commit f8f9441

Please sign in to comment.