Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
}
CallExpression(node) {
const callee =
node.callee.type === AST_NODE_TYPES.TaggedTemplateExpression
? node.callee.tag
: node.callee;
if (callee.type === AST_NODE_TYPES.MemberExpression) {
if (
callee.object.type === AST_NODE_TYPES.Identifier &&
isCallToFocusedTestFunction(callee.object)
) {
context.report({ messageId: 'focusedTest', node: callee.object });
return;
}
if (
callee.object.type === AST_NODE_TYPES.MemberExpression &&
isCallToTestOnlyFunction(callee.object)
) {
context.report({
messageId: 'focusedTest',
node: callee.object.property,
});
return;
}
function isEntityNameExpression(node: TSESTree.Node): boolean {
return (
node.type === AST_NODE_TYPES.Identifier ||
(isPropertyAccessExpression(node) &&
isEntityNameExpression(node.object))
);
}
function getNameFromMember(
member:
| TSESTree.MethodDefinition
| TSESTree.TSMethodSignature
| TSESTree.TSAbstractMethodDefinition
| TSESTree.ClassProperty
| TSESTree.TSAbstractClassProperty
| TSESTree.Property
| TSESTree.TSPropertySignature,
sourceCode: TSESLint.SourceCode,
): string {
if (member.key.type === AST_NODE_TYPES.Identifier) {
return member.key.name;
}
if (member.key.type === AST_NODE_TYPES.Literal) {
return `${member.key.value}`;
}
return sourceCode.text.slice(...member.key.range);
}
const isFixableIncludesCallExpression = (
node: TSESTree.Node,
): node is FixableIncludesCallExpression =>
node.type === AST_NODE_TYPES.CallExpression &&
node.callee.type === AST_NODE_TYPES.MemberExpression &&
isSupportedAccessor(node.callee.property, 'includes') &&
node.callee.property.type === AST_NODE_TYPES.Identifier &&
hasOnlyOneArgument(node);
function isMatchingIdentifier(
node: TSESTree.Expression,
name: string,
): boolean {
return node.type === AST_NODE_TYPES.Identifier && node.name === name;
}
function isIdentifier(node: TSESTree.Node): node is TSESTree.Identifier {
return node.type === AST_NODE_TYPES.Identifier;
}
node.callee,
closingParenToken,
isOpeningParenToken,
),
util.NullThrowsReasons.MissingToken('opening parenthesis', node.type),
);
const argumentsText = sourceCode.text.substring(
openingParenToken.range[0],
closingParenToken.range[1],
);
return `${calleeText}${argumentsText}`;
}
if (node.type === AST_NODE_TYPES.Identifier) {
return node.name;
}
if (node.type === AST_NODE_TYPES.ThisExpression) {
return 'this';
}
return getMemberExpressionText(node);
}
function isIdentifier(
init: TSESTree.Expression,
...names: string[]
): boolean {
return (
init.type === AST_NODE_TYPES.Identifier && names.includes(init.name)
);
}
function hasUnaryPrefix(
fix(fixer) {
const leftPropQuote =
left.property.type === AST_NODE_TYPES.Identifier ? "'" : '';
const [arg] = jestFnCall.arguments;
const argSource = arg && context.getSourceCode().getText(arg);
const mockImplementation = argSource
? `.mockImplementation(${argSource})`
: '.mockImplementation()';
return [
fixer.insertTextBefore(left, `jest.spyOn(`),
fixer.replaceTextRange(
[left.object.range[1], left.property.range[0]],
`, ${leftPropQuote}`,
),
fixer.replaceTextRange(
[left.property.range[1], jestFnCall.range[1]],
`${leftPropQuote})${mockImplementation}`,
),