Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return true;
}
// [a[i]] = [0]
if (parent.type === AST_NODE_TYPES.ArrayPattern) {
return true;
}
// [...a[i]] = [0]
if (parent.type === AST_NODE_TYPES.RestElement) {
return true;
}
// ({ foo: a[i] }) = { foo: 0 }
if (
parent.type === AST_NODE_TYPES.Property &&
parent.value === node &&
parent.parent?.type === AST_NODE_TYPES.ObjectExpression &&
isAssignee(parent.parent)
) {
return true;
}
return false;
}
function getLocStart(
node:
| TSESTree.ArrowFunctionExpression
| TSESTree.FunctionDeclaration
| TSESTree.FunctionExpression,
): TSESTree.LineAndColumnData {
/* highlight method name */
const parent = node.parent;
if (
parent &&
(parent.type === AST_NODE_TYPES.MethodDefinition ||
(parent.type === AST_NODE_TYPES.Property && parent.method))
) {
return parent.loc.start;
}
return node.loc.start;
}
key: null as any,
value: null as any,
// Property flags
computed: false,
method: false,
kind: 'init',
// this will stop eslint from interrogating the type literal
shorthand: true,
// location data
parent: node.parent,
range: node.range,
loc: node.loc,
};
if (type === AST_NODE_TYPES.Property) {
return {
type,
...base,
} as TSESTree.Property;
} else {
return {
type,
static: false,
readonly: false,
declare: false,
...base,
} as TSESTree.ClassProperty;
}
}
function TSPropertySignatureToProperty(
node:
| TSESTree.TSPropertySignature
| TSESTree.TSEnumMember
| TSESTree.TypeElement,
type:
| AST_NODE_TYPES.ClassProperty
| AST_NODE_TYPES.Property = AST_NODE_TYPES.Property,
): TSESTree.Node | null {
const base = {
// indent doesn't actually use these
key: null as any,
value: null as any,
// Property flags
computed: false,
method: false,
kind: 'init',
// this will stop eslint from interrogating the type literal
shorthand: true,
// location data
parent: node.parent,
range: node.range,
}
const returnType = checker.getReturnTypeOfSignature(signatures[0]);
if (
!util.containsAllTypesByName(
returnType,
allowAny!,
allAllowedPromiseNames,
)
) {
return;
}
if (
node.parent &&
(node.parent.type === AST_NODE_TYPES.Property ||
node.parent.type === AST_NODE_TYPES.MethodDefinition) &&
(node.parent.kind === 'get' || node.parent.kind === 'set')
) {
return;
}
context.report({
messageId: 'missingAsync',
node,
});
}
export function isProperty(node: TSESTree.Node): node is TSESTree.Property {
return node.type === AST_NODE_TYPES.Property;
}
AST_NODE_TYPES.ForOfStatement,
AST_NODE_TYPES.FunctionDeclaration,
AST_NODE_TYPES.FunctionExpression,
AST_NODE_TYPES.Identifier,
AST_NODE_TYPES.IfStatement,
AST_NODE_TYPES.Literal,
AST_NODE_TYPES.LabeledStatement,
AST_NODE_TYPES.LogicalExpression,
AST_NODE_TYPES.MemberExpression,
AST_NODE_TYPES.MetaProperty,
AST_NODE_TYPES.MethodDefinition,
AST_NODE_TYPES.NewExpression,
AST_NODE_TYPES.ObjectExpression,
AST_NODE_TYPES.ObjectPattern,
AST_NODE_TYPES.Program,
AST_NODE_TYPES.Property,
AST_NODE_TYPES.RestElement,
AST_NODE_TYPES.ReturnStatement,
AST_NODE_TYPES.SequenceExpression,
AST_NODE_TYPES.SpreadElement,
AST_NODE_TYPES.Super,
AST_NODE_TYPES.SwitchCase,
AST_NODE_TYPES.SwitchStatement,
AST_NODE_TYPES.TaggedTemplateExpression,
AST_NODE_TYPES.TemplateElement,
AST_NODE_TYPES.TemplateLiteral,
AST_NODE_TYPES.ThisExpression,
AST_NODE_TYPES.ThrowStatement,
AST_NODE_TYPES.TryStatement,
AST_NODE_TYPES.UnaryExpression,
AST_NODE_TYPES.UpdateExpression,
AST_NODE_TYPES.VariableDeclaration,
function isNamedFunction(
node:
| TSESTree.ArrowFunctionExpression
| TSESTree.FunctionDeclaration
| TSESTree.FunctionExpression,
): boolean {
if (node.id) {
return true;
}
const parent = node.parent!;
return (
parent.type === AST_NODE_TYPES.MethodDefinition ||
(parent.type === AST_NODE_TYPES.Property &&
(parent.kind === 'get' || parent.kind === 'set' || parent.method))
);
}
function isSetter(node: TSESTree.Node | undefined): boolean {
return (
!!node &&
(node.type === AST_NODE_TYPES.MethodDefinition ||
node.type === AST_NODE_TYPES.Property) &&
node.kind === 'set'
);
}