-
Notifications
You must be signed in to change notification settings - Fork 150
feat: add new settings for prefer-user-event #251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -253,3 +253,22 @@ export function getImportModuleName( | |
return node.arguments[0].value; | ||
} | ||
} | ||
|
||
export function getSpecifierFromImport( | ||
node: ImportModuleNode, | ||
specifierName: string | ||
) { | ||
if (isImportDeclaration(node)) { | ||
const namedExport = node.specifiers.find( | ||
(node) => isImportSpecifier(node) && node.imported.name === specifierName | ||
); | ||
// it is "import { foo } from 'baz'"" | ||
if (namedExport) { | ||
return namedExport; | ||
} | ||
// it could be "import * as rtl from 'baz'" | ||
return node.specifiers.find((n) => isImportNamespaceSpecifier(n)); | ||
} else { | ||
// TODO make it work for require | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we move this function into the detect-import-testing-library utils, instead of passing I still have to make it work for both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's a good idea to have this within detection module. I actually mentioned this helper when analyzing how to organize the helpers for detection module. There are difference scenarios as you have already figured in your draft, but there are more related to other Testing Library utils, specially for Anyway, I think we should include this one within detection already, covering all different imports. Then we can improve it when necessary when refactoring other rules. I'd name it something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved it into the detection helper, and added the scenario for |
Uh oh!
There was an error while loading. Please reload this page.