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; 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}';