Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
node,
i,
info.rest,
),
);
this.referencingDefaultValue(pattern, info.assignments, null, true);
}
},
);
}
// Process the return type.
this.visit(returnType);
// Process the body.
if (body && body.type === AST_NODE_TYPES.BlockStatement) {
this.visitChildren(body);
} else {
this.visit(body);
}
// Close the function scope.
this.close(node);
}
);
// Remove overload definition to avoid confusion of no-redeclare rule.
const { defs, identifiers } = upperScope.set.get(id.name)!;
for (let i = 0; i < defs.length; ++i) {
const def = defs[i];
if (
def.type === 'FunctionName' &&
def.node.type === AST_NODE_TYPES.TSDeclareFunction
) {
defs.splice(i, 1);
identifiers.splice(i, 1);
break;
}
}
} else if (type === AST_NODE_TYPES.FunctionExpression && id) {
scopeManager.__nestFunctionExpressionNameScope(node);
}
// Open the function scope.
scopeManager.__nestFunctionScope(node, this.isInnerMethodDefinition);
const innerScope = this.currentScope();
// Process the type parameters
this.visit(typeParameters);
// Process parameter declarations.
for (let i = 0; i < params.length; ++i) {
this.visitPattern(
params[i],
{ processRightHandNodes: true },
(pattern, info) => {
function binaryExp(node) {
const rule = rules.BinaryExpression;
// makes the rule think it should skip the left or right
if (node.left.type === experimental_utils_1.AST_NODE_TYPES.TSAsExpression) {
return rule(Object.assign(Object.assign({}, node), { left: Object.assign(Object.assign({}, node.left), { type: experimental_utils_1.AST_NODE_TYPES.BinaryExpression }) }));
}
if (node.right.type === experimental_utils_1.AST_NODE_TYPES.TSAsExpression) {
return rule(Object.assign(Object.assign({}, node), { right: Object.assign(Object.assign({}, node.right), { type: experimental_utils_1.AST_NODE_TYPES.BinaryExpression }) }));
}
return rule(node);
}
function callExp(node) {
function isInferrable(annotation, init) {
switch (annotation.type) {
case experimental_utils_1.AST_NODE_TYPES.TSBigIntKeyword: {
// note that bigint cannot have + prefixed to it
const unwrappedInit = hasUnaryPrefix(init, '-')
? init.argument
: init;
return (isFunctionCall(unwrappedInit, 'BigInt') ||
unwrappedInit.type === experimental_utils_1.AST_NODE_TYPES.BigIntLiteral);
}
case experimental_utils_1.AST_NODE_TYPES.TSBooleanKeyword:
return (hasUnaryPrefix(init, '!') ||
isFunctionCall(init, 'Boolean') ||
isLiteral(init, 'boolean'));
case experimental_utils_1.AST_NODE_TYPES.TSNumberKeyword: {
const unwrappedInit = hasUnaryPrefix(init, '+', '-')
? init.argument
: init;
return (isIdentifier(unwrappedInit, 'Infinity', 'NaN') ||
isFunctionCall(unwrappedInit, 'Number') ||
isLiteral(unwrappedInit, 'number'));
}
case experimental_utils_1.AST_NODE_TYPES.TSNullKeyword:
return init.type === experimental_utils_1.AST_NODE_TYPES.Literal && init.value === null;
case experimental_utils_1.AST_NODE_TYPES.TSStringKeyword:
return (isFunctionCall(init, 'String') ||
isLiteral(init, 'string') ||
init.type === experimental_utils_1.AST_NODE_TYPES.TemplateLiteral);
case experimental_utils_1.AST_NODE_TYPES.TSSymbolKeyword:
return isFunctionCall(init, 'Symbol');
case experimental_utils_1.AST_NODE_TYPES.TSTypeReference: {
function checkParameterPropertyAccessibilityModifier(
node: TSESTree.TSParameterProperty,
): void {
const nodeType = 'parameter property';
// HAS to be an identifier or assignment or TSC will throw
if (
node.parameter.type !== AST_NODE_TYPES.Identifier &&
node.parameter.type !== AST_NODE_TYPES.AssignmentPattern
) {
return;
}
const nodeName =
node.parameter.type === AST_NODE_TYPES.Identifier
? node.parameter.name
: // has to be an Identifier or TSC will throw an error
(node.parameter.left as TSESTree.Identifier).name;
switch (paramPropCheck) {
case 'explicit': {
if (!node.accessibility) {
reportIssue('missingAccessibility', nodeType, node, nodeName);
}
function isValidChainTarget(
node: TSESTree.Node,
allowIdentifier: boolean,
): node is ValidChainTarget {
if (
node.type === AST_NODE_TYPES.MemberExpression ||
node.type === AST_NODE_TYPES.OptionalMemberExpression
) {
const isObjectValid =
ALLOWED_MEMBER_OBJECT_TYPES.has(node.object.type) &&
// make sure to validate the expression is of our expected structure
isValidChainTarget(node.object, true);
const isPropertyValid = node.computed
? ALLOWED_COMPUTED_PROP_TYPES.has(node.property.type) &&
// make sure to validate the member expression is of our expected structure
(node.property.type === AST_NODE_TYPES.MemberExpression ||
node.property.type === AST_NODE_TYPES.OptionalMemberExpression
? isValidChainTarget(node.property, allowIdentifier)
: true)
: ALLOWED_NON_COMPUTED_PROP_TYPES.has(node.property.type);
return isObjectValid && isPropertyValid;
TSQualifiedName(node: TSESTree.TSQualifiedName) {
return rules['MemberExpression, JSXMemberExpression, MetaProperty']({
type: AST_NODE_TYPES.MemberExpression,
object: node.left as any,
property: node.right as any,
// location data
parent: node.parent,
range: node.range,
loc: node.loc,
optional: false,
computed: false,
});
},
function getText(node: ValidChainTarget): string {
if (node.type === AST_NODE_TYPES.BinaryExpression) {
return getText(
// isValidChainTarget ensures this is type safe
node.left as ValidChainTarget,
);
}
if (
node.type === AST_NODE_TYPES.CallExpression ||
node.type === AST_NODE_TYPES.OptionalCallExpression
) {
const calleeText = getText(
// isValidChainTarget ensures this is type safe
node.callee as ValidChainTarget,
);
// ensure that the call arguments are left untouched, or else we can break cases that _need_ whitespace:
// - JSX:
// - Unary Operators: typeof foo, await bar, delete baz
const closingParenToken = util.nullThrows(
sourceCode.getLastToken(node),
util.NullThrowsReasons.MissingToken('closing parenthesis', node.type),
);
const openingParenToken = util.nullThrows(
sourceCode.getFirstTokenBetween(
throw new Error(
`Unexpected BlockStatement. No parent defined. - please file a github issue at https://github.com/jest-community/eslint-plugin-jest`,
);
}
// functionDeclaration: function func() {}
if (func.type === AST_NODE_TYPES.FunctionDeclaration) {
return 'function';
}
if (isFunction(func) && func.parent) {
const expr = func.parent;
// arrowfunction or function expr
if (expr.type === AST_NODE_TYPES.VariableDeclarator) {
return 'function';
}
// if it's not a variable, it will be callExpr, we only care about describe
if (expr.type === AST_NODE_TYPES.CallExpression && isDescribe(expr)) {
return DescribeAlias.describe;
}
}
return null;
};
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
const KNOWN_NODES = new Set([
AST_NODE_TYPES.AssignmentExpression,
AST_NODE_TYPES.AssignmentPattern,
AST_NODE_TYPES.ArrayExpression,
AST_NODE_TYPES.ArrayPattern,
AST_NODE_TYPES.ArrowFunctionExpression,
AST_NODE_TYPES.AwaitExpression,
AST_NODE_TYPES.BlockStatement,
AST_NODE_TYPES.BinaryExpression,
AST_NODE_TYPES.BreakStatement,
AST_NODE_TYPES.CallExpression,
AST_NODE_TYPES.CatchClause,
AST_NODE_TYPES.ClassBody,
AST_NODE_TYPES.ClassDeclaration,
AST_NODE_TYPES.ClassExpression,
AST_NODE_TYPES.ConditionalExpression,
AST_NODE_TYPES.ContinueStatement,
AST_NODE_TYPES.DoWhileStatement,
AST_NODE_TYPES.DebuggerStatement,
AST_NODE_TYPES.EmptyStatement,
AST_NODE_TYPES.ExpressionStatement,
AST_NODE_TYPES.ForStatement,
AST_NODE_TYPES.ForInStatement,
AST_NODE_TYPES.ForOfStatement,
AST_NODE_TYPES.FunctionDeclaration,
AST_NODE_TYPES.FunctionExpression,
AST_NODE_TYPES.Identifier,