Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Check static methods.
for (const reference of getReferences(
Object.keys(PROPERTY_TEST_TARGETS)
)) {
const node = reference.identifier
const parentNode = node.parent
if (
parentNode.type !== "MemberExpression" ||
parentNode.object !== node
) {
continue
}
const objectName = node.name
const properties = PROPERTY_TEST_TARGETS[objectName]
const propertyName = getPropertyName(parentNode)
if (
propertyName &&
properties.indexOf(propertyName) !== -1
) {
report(parentNode, `${objectName}.${propertyName}`)
}
}
// Check subclassing
for (const reference of getReferences(
SUBCLASSING_TEST_TARGETS
)) {
const node = reference.identifier
const parentNode = node.parent
if (
CLASS_TYPE.test(parentNode.type) &&
"Program:exit"() {
// Check new global variables.
for (const name of NEW_BUILTIN_TYPES) {
for (const reference of getReferences([name])) {
// Ignore if it's using new static methods.
const node = reference.identifier
const parentNode = node.parent
const properties = PROPERTY_TEST_TARGETS[name]
if (
properties &&
parentNode.type === "MemberExpression"
) {
const propertyName = getPropertyName(parentNode)
if (properties.indexOf(propertyName) !== -1) {
continue
}
}
report(reference.identifier, name)
}
}
// Check static methods.
for (const reference of getReferences(
Object.keys(PROPERTY_TEST_TARGETS)
)) {
const node = reference.identifier
const parentNode = node.parent
if (
function isLengthExpression(
node: TSESTree.Node,
expectedObjectNode: TSESTree.Node,
): boolean {
if (node.type === 'MemberExpression') {
return (
getPropertyName(node, globalScope) === 'length' &&
isSameTokens(node.object, expectedObjectNode)
);
}
const evaluatedLength = getStaticValue(node, globalScope);
const evaluatedString = getStaticValue(expectedObjectNode, globalScope);
return (
evaluatedLength != null &&
evaluatedString != null &&
typeof evaluatedLength.value === 'number' &&
typeof evaluatedString.value === 'string' &&
evaluatedLength.value === evaluatedString.value.length
);
}
function isLengthExpression(node, expectedObjectNode) {
if (node.type === 'MemberExpression') {
return (eslint_utils_1.getPropertyName(node, globalScope) === 'length' &&
isSameTokens(node.object, expectedObjectNode));
}
const evaluatedLength = eslint_utils_1.getStaticValue(node, globalScope);
const evaluatedString = eslint_utils_1.getStaticValue(expectedObjectNode, globalScope);
return (evaluatedLength != null &&
evaluatedString != null &&
typeof evaluatedLength.value === 'number' &&
typeof evaluatedString.value === 'string' &&
evaluatedLength.value === evaluatedString.value.length);
}
/**