How to use the jsdoctypeparser.traverse 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 / 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];
        nodeName = typeName === '[]' ? typeName : nodeName;

        if (!preferredSetting) {
          invalidTypes.push([nodeName]);
        } else if (typeof preferredSetting === 'string') {