Skip to content

Commit 7f751e1

Browse files
authored
fix(no-global-regexp-flag-in-query): check if empty name property node (#566)
* fix(no-global-regexp-flag-in-query): check if empty name property node * style: write the valid snippet without an object Closes #565
1 parent b62ba43 commit 7f751e1

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/rules/no-global-regexp-flag-in-query.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,11 @@ export default createTestingLibraryRule<Options, MessageIds>({
9696
ASTUtils.isIdentifier(p.key) &&
9797
p.key.name === 'name' &&
9898
isLiteral(p.value)
99-
) as TSESTree.ObjectLiteralElement & { value: TSESTree.Literal };
100-
report(namePropertyNode.value);
99+
) as TSESTree.Property | undefined;
100+
101+
if (namePropertyNode) {
102+
report(namePropertyNode.value);
103+
}
101104
}
102105
},
103106
};

tests/lib/rules/no-global-regexp-flag-in-query.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ ruleTester.run(RULE_NAME, rule, {
7878
const utils = render(<Component/>)
7979
utils.notAQuery(/hello/i)
8080
`,
81+
82+
// issue #565
83+
`
84+
import { screen } from "@testing-library/react"
85+
86+
describe("App", () => {
87+
test("is rendered", async () => {
88+
await screen.findByText("Hello World", { exact: false });
89+
})
90+
})
91+
`,
8192
],
8293
invalid: [
8394
{

0 commit comments

Comments
 (0)