From c1c93ff05e0e1b757e12deab1543f302e4085e2a Mon Sep 17 00:00:00 2001 From: Hasegawa-Yukihiro Date: Sat, 12 Jul 2025 13:36:24 +0900 Subject: [PATCH 1/2] fix: only report rule when Testing Library or custom utils module is imported --- lib/rules/no-node-access.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/rules/no-node-access.ts b/lib/rules/no-node-access.ts index 0027fcd3..e6d9cfbb 100644 --- a/lib/rules/no-node-access.ts +++ b/lib/rules/no-node-access.ts @@ -90,6 +90,13 @@ export default createTestingLibraryRule({ return { CallExpression(node: TSESTree.CallExpression) { + // This rule is so aggressive that can cause tons of false positives outside test files when Aggressive Reporting + // is enabled. Because of that, this rule will skip this mechanism and report only if some Testing Library package + // or custom one (set in utils-module Shared Setting) is found. + if (!helpers.isTestingLibraryImported(true)) { + return; + } + const { callee } = node; const property = isMemberExpression(callee) ? callee.property : null; const object = isMemberExpression(callee) ? callee.object : null; From 74a17fa199e1c9a1fbfef807b8e30557ae98bfc5 Mon Sep 17 00:00:00 2001 From: Hasegawa-Yukihiro Date: Sat, 12 Jul 2025 13:38:12 +0900 Subject: [PATCH 2/2] test: add test --- tests/lib/rules/no-node-access.test.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/lib/rules/no-node-access.test.ts b/tests/lib/rules/no-node-access.test.ts index 8e9ec456..1062d08f 100644 --- a/tests/lib/rules/no-node-access.test.ts +++ b/tests/lib/rules/no-node-access.test.ts @@ -23,6 +23,15 @@ const SUPPORTED_TESTING_FRAMEWORKS = [ ruleTester.run(RULE_NAME, rule, { valid: SUPPORTED_TESTING_FRAMEWORKS.flatMap( (testingFramework) => [ + { + // valid because no Testing Library module is imported + code: ` + // case: custom module set but not imported using ${testingFramework} (aggressive reporting limited) + const body = document.body + + body.click(); + `, + }, { code: ` import { screen } from '${testingFramework}';