-
Notifications
You must be signed in to change notification settings - Fork 96
feat: support chains started of helper functions in unsafe-to-chain-command #307
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
base: master
Are you sure you want to change the base?
Changes from all commits
a85a90a
7c114e8
ec2dcde
2b0516b
e3af5d3
a49261b
783aee7
e9575a2
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 |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /** | ||
| * Checks if the root of a call expression originated from a 'cy' identifier. | ||
| * If type information are available, additionally checks the return type of helper functions. | ||
| * | ||
| * @param {import('estree').Node} node | ||
| * @param {import('eslint').Rule.RuleContext} context | ||
| * @returns {boolean} | ||
| */ | ||
| const isRootCypress = (node, context) => { | ||
| if (node.type !== 'CallExpression') { | ||
| return false | ||
| } | ||
|
|
||
| const calleeType = node.callee.type | ||
| if (calleeType === 'MemberExpression') { | ||
| if (node.callee.object.type === 'Identifier' && node.callee.object.name === 'cy') { | ||
| return true | ||
| } | ||
|
|
||
| return isRootCypress(node.callee.object, context) | ||
| } | ||
|
|
||
| if (calleeType === 'Identifier') { | ||
| const services = context?.sourceCode?.parserServices | ||
| if (services?.program && services.esTreeNodeToTSNodeMap) { | ||
| const checker = services.program.getTypeChecker() | ||
| const tsNode = services.esTreeNodeToTSNodeMap.get(node) | ||
| const signature = checker.getResolvedSignature(tsNode) | ||
|
|
||
| if (signature) { | ||
| const returnType = checker.getReturnTypeOfSignature(signature) | ||
| const symbol = returnType.getSymbol() | ||
| if (symbol) { | ||
| return checker.getFullyQualifiedName(symbol) === 'Cypress.Chainable' | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return false | ||
| } | ||
|
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. Extracted utility duplicates existing implementations in other rulesMedium Severity The new
Contributor
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. This needs fixed as well, please! |
||
|
|
||
| module.exports = { isRootCypress } | ||


Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@typescript-eslint/parseris necessary as well, correct?Can you add these as optional peer dependencies, with the appropriate semvers?