How to use the jsdoctypeparser.parse function in jsdoctypeparser

To help you get started, we’ve selected a few jsdoctypeparser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gajus / eslint-plugin-jsdoc / src / rules / validTypes.js View on Github external
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();
github infamous / infamous / readem.ts View on Github external
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)
github gajus / eslint-plugin-jsdoc / src / rules / validTypes.js View on Github external
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;
github gajus / eslint-plugin-jsdoc / src / rules / noUndefinedTypes.js View on Github external
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);
        }
      }
    });
  });
}, {
github gajus / eslint-plugin-jsdoc / src / rules / checkTypes.js View on Github external
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];
github gajus / eslint-plugin-jsdoc / src / rules / validTypes.js View on Github external
const validTypeParsing = function (type) {
      try {
        parse(type);
      } catch (error) {
        report(`Syntax error in type: ${type}`, null, tag);

        return false;
      }

      return true;
    };