Skip to content

Commit 476b7f6

Browse files
committed
docs: update old comments related to ImportDeclaration
1 parent e9d7bc3 commit 476b7f6

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/detect-testing-library-utils.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,14 @@ export function detectTestingLibraryUtils<
7777
};
7878

7979
// Instructions for Testing Library detection.
80-
// `ImportDeclaration` must be first in order to know if Testing Library
81-
// is imported ASAP.
8280
const detectionInstructions: TSESLint.RuleListener = {
81+
/**
82+
* This ImportDeclaration rule listener will check if Testing Library related
83+
* modules are loaded. Since imports happen first thing in a file, it's
84+
* safe to use `isImportingTestingLibraryModule` and `isImportingCustomModule`
85+
* since they will have corresponding value already updated when reporting other
86+
* parts of the file.
87+
*/
8388
ImportDeclaration(node: TSESTree.ImportDeclaration) {
8489
if (!isImportingTestingLibraryModule) {
8590
// check only if testing library import not found yet so we avoid
@@ -102,14 +107,12 @@ export function detectTestingLibraryUtils<
102107
const ruleInstructions = ruleCreate(context, optionsWithDefault, helpers);
103108
const enhancedRuleInstructions: TSESLint.RuleListener = {};
104109

105-
// The order here is important too: detection instructions must come before
106-
// than rule instructions to:
107-
// - detect Testing Library things before the rule is applied
108-
// - be able to prevent the rule about to be applied if necessary
109110
const allKeys = new Set(
110111
Object.keys(detectionInstructions).concat(Object.keys(ruleInstructions))
111112
);
112113

114+
// Iterate over ALL instructions keys so we can override original rule instructions
115+
// to prevent their execution if conditions to report errors are not met.
113116
allKeys.forEach((instruction) => {
114117
enhancedRuleInstructions[instruction] = (node) => {
115118
if (instruction in detectionInstructions) {

0 commit comments

Comments
 (0)