Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const validNamepathParsing = function (namepath, tagName) {
try {
parse(namepath);
} catch (error) {
let handled = false;
if (tagName) {
if (['memberof', 'memberof!'].includes(tagName)) {
const endChar = namepath.slice(-1);
if (['#', '.', '~'].includes(endChar)) {
try {
parse(namepath.slice(0, -1));
handled = true;
} catch (memberofError) {
// Use the original error for including the whole type
}
}
} else if (tagName === 'borrows') {
const startChar = namepath.charAt();
source: originalComment,
content: [],
}
// strip the leading stars, if any
const commentContent = commentMatch[1].replace(leadingStarsRegex, '')
const re = jsDocTagRegex
let tagMatch: ReturnType
// get each part of each JSDoc tag
while ((tagMatch = re.exec(commentContent))) {
let type: any
try {
type = tagMatch[2] && jsdocTypeParse(tagMatch[2])
type.source = tagMatch[2]
} catch (e) {
type = tagMatch[2]
}
comment.content.push({
source: tagMatch[0],
tag: tagMatch[1],
type: type || undefined,
name: tagMatch[3],
description: (tagMatch[4] && tagMatch[4].trim()) || undefined,
})
}
comments.push(comment)
if (tagName) {
if (['memberof', 'memberof!'].includes(tagName)) {
const endChar = namepath.slice(-1);
if (['#', '.', '~'].includes(endChar)) {
try {
parse(namepath.slice(0, -1));
handled = true;
} catch (memberofError) {
// Use the original error for including the whole type
}
}
} else if (tagName === 'borrows') {
const startChar = namepath.charAt();
if (['#', '.', '~'].includes(startChar)) {
try {
parse(namepath.slice(1));
handled = true;
} catch (memberofError) {
// Use the original error for including the whole type
}
}
}
}
if (!handled) {
report(`Syntax error in namepath: ${namepath}`, null, tag);
return false;
}
}
return true;
jsdocTagsWithPossibleType.forEach((tag) => {
let parsedType;
try {
parsedType = parseType(tag.type);
} catch (error) {
// On syntax error, will be handled by valid-types.
return;
}
traverse(parsedType, ({type, name}) => {
if (type === 'NAME') {
if (!allDefinedTypes.includes(name)) {
report(`The type '${name}' is undefined.`, null, tag);
} else if (!_.includes(extraTypes, name)) {
context.markVariableAsUsed(name);
}
}
});
});
}, {
jsdocTagsWithPossibleType.forEach((jsdocTag) => {
const invalidTypes = [];
let typeAst;
try {
typeAst = parse(jsdocTag.type);
} catch (error) {
return;
}
traverse(typeAst, (node, parentName, parentNode) => {
const {type, name} = node;
if (!['NAME', 'ANY'].includes(type)) {
return;
}
let nodeName = type === 'ANY' ? '*' : name;
const [hasMatchingPreferredType, typeName, isGenericMatch] = getPreferredTypeInfo(type, nodeName, parentName, parentNode);
let preferred;
if (hasMatchingPreferredType) {
const preferredSetting = preferredTypes[typeName];
const validTypeParsing = function (type) {
try {
parse(type);
} catch (error) {
report(`Syntax error in type: ${type}`, null, tag);
return false;
}
return true;
};