(params: {
scopeManager: TSESLint.Scope.ScopeManager
sourceCode: Readonly<TSESLint.SourceCode>
node: TSESTree.Node
})
| 158 | return scope.set.has(reference.identifier.name) |
| 159 | }, |
| 160 | getExternalRefs(params: { |
| 161 | scopeManager: TSESLint.Scope.ScopeManager |
| 162 | sourceCode: Readonly<TSESLint.SourceCode> |
| 163 | node: TSESTree.Node |
| 164 | }): Array<TSESLint.Scope.Reference> { |
| 165 | const { scopeManager, sourceCode, node } = params |
| 166 | const scope = scopeManager.acquire(node) |
| 167 | |
| 168 | if (scope === null) { |
| 169 | return [] |
| 170 | } |
| 171 | |
| 172 | const collectReferences = ( |
| 173 | currentScope: TSESLint.Scope.Scope, |
| 174 | ): Array<TSESLint.Scope.Reference> => { |
| 175 | const references = [...currentScope.references] |
| 176 | |
| 177 | for (const childScope of currentScope.childScopes) { |
| 178 | references.push(...collectReferences(childScope)) |
| 179 | } |
| 180 | |
| 181 | return references |
| 182 | } |
| 183 | |
| 184 | const references = collectReferences(scope) |
| 185 | .filter((x) => x.isRead() && !scope.set.has(x.identifier.name)) |
| 186 | .map((x) => { |
| 187 | const referenceNode = ASTUtils.traverseUpOnly(x.identifier, [ |
| 188 | AST_NODE_TYPES.MemberExpression, |
| 189 | AST_NODE_TYPES.Identifier, |
| 190 | ]) |
| 191 | |
| 192 | return { |
| 193 | variable: x, |
| 194 | node: referenceNode, |
| 195 | text: sourceCode.getText(referenceNode), |
| 196 | } |
| 197 | }) |
| 198 | |
| 199 | const localRefIds = new Set( |
| 200 | [...scope.set.values()].map((x) => sourceCode.getText(x.identifiers[0])), |
| 201 | ) |
| 202 | |
| 203 | const externalRefs = references.filter( |
| 204 | (x) => x.variable.resolved === null || !localRefIds.has(x.text), |
| 205 | ) |
| 206 | |
| 207 | return uniqueBy(externalRefs, (x) => x.text).map((x) => x.variable) |
| 208 | }, |
| 209 | mapKeyNodeToText( |
| 210 | node: TSESTree.Node, |
| 211 | sourceCode: Readonly<TSESLint.SourceCode>, |
nothing calls this directly
no test coverage detected