From e9f6a0aeaf04fd19d0a992ffc11b29f719352997 Mon Sep 17 00:00:00 2001 From: Simon Seyock Date: Mon, 24 May 2021 14:33:39 +0200 Subject: [PATCH] Update parser --- src/rules/checkTypes.js | 26 +++++++++++++------------- src/rules/noUndefinedTypes.js | 5 +---- test/rules/assertions/validTypes.js | 14 -------------- 3 files changed, 14 insertions(+), 31 deletions(-) diff --git a/src/rules/checkTypes.js b/src/rules/checkTypes.js index 1f3a5b757..12dacaae2 100644 --- a/src/rules/checkTypes.js +++ b/src/rules/checkTypes.js @@ -20,32 +20,32 @@ const adjustNames = (type, preferred, isGenericMatch, nodeName, node, parentNode let ret = preferred; if (isGenericMatch) { if (preferred === '[]') { - parentNode.meta.brackets = '[]'; + parentNode.meta.brackets = 'square'; parentNode.meta.dot = false; ret = 'Array'; } else { const dotBracketEnd = preferred.match(/\.(?:<>)?$/u); if (dotBracketEnd) { - parentNode.meta.brackets = '<>'; + parentNode.meta.brackets = 'angle'; parentNode.meta.dot = true; ret = preferred.slice(0, -dotBracketEnd[0].length); } else { const bracketEnd = preferred.endsWith('<>'); if (bracketEnd) { - parentNode.meta.brackets = '<>'; + parentNode.meta.brackets = 'angle'; parentNode.meta.dot = false; ret = preferred.slice(0, -2); } else if ( - parentNode.meta.brackets === '[]' && + parentNode.meta.brackets === 'square' && (nodeName === '[]' || nodeName === 'Array') ) { - parentNode.meta.brackets = '<>'; + parentNode.meta.brackets = 'angle'; parentNode.meta.dot = false; } } } - } else if (type === 'ANY') { - node.type = 'NAME'; + } else if (type === 'JsdocTypeAny') { + node.type = 'JsdocTypeName'; } node.value = ret.replace(/(?:\.|<>|\.<>|\[\])$/u, ''); @@ -79,12 +79,12 @@ export default iterateJsdoc(({ let isGenericMatch; let typeName = nodeName; if (Object.keys(preferredTypes).length) { - const isNameOfGeneric = parentNode !== undefined && parentNode.type === 'GENERIC' && property === 'left'; + const isNameOfGeneric = parentNode !== undefined && parentNode.type === 'JsdocTypeGeneric' && property === 'left'; if (unifyParentAndChildTypeChecks || isNameOfGeneric) { const brackets = parentNode?.meta?.brackets; const dot = parentNode?.meta?.dot; - if (brackets === '<>') { + if (brackets === 'angle') { const checkPostFixes = dot ? ['.', '.<>'] : ['<>']; isGenericMatch = checkPostFixes.some(checkPostFix => { if (preferredTypes?.[nodeName + checkPostFix] !== undefined) { @@ -96,7 +96,7 @@ export default iterateJsdoc(({ } if (!isGenericMatch && property) { - const checkPostFixes = dot ? ['.', '.<>'] : [brackets] + const checkPostFixes = dot ? ['.', '.<>'] : [brackets === 'angle' ? '<>' : '[]'] isGenericMatch = checkPostFixes.some(checkPostFix => { if (preferredTypes?.[checkPostFix] !== undefined) { @@ -132,10 +132,10 @@ export default iterateJsdoc(({ traverse(typeAst, (node, parentNode, property) => { const {type, value} = node; - if (!['NAME', 'ANY'].includes(type)) { + if (!['JsdocTypeName', 'JsdocTypeAny'].includes(type)) { return; } - let nodeName = type === 'ANY' ? '*' : value; + let nodeName = type === 'JsdocTypeAny' ? '*' : value; const [hasMatchingPreferredType, typeName, isGenericMatch] = getPreferredTypeInfo(type, nodeName, parentNode, property); @@ -172,7 +172,7 @@ export default iterateJsdoc(({ !types.includes(nodeName); })) { invalidTypes.push([nodeName, types]); - } else if (!noDefaults && type === 'NAME') { + } else if (!noDefaults && type === 'JsdocTypeName') { for (const strictNativeType of strictNativeTypes) { if (strictNativeType === 'object' && mode === 'typescript') { continue; diff --git a/src/rules/noUndefinedTypes.js b/src/rules/noUndefinedTypes.js index 4e0ebe575..23c611d0e 100644 --- a/src/rules/noUndefinedTypes.js +++ b/src/rules/noUndefinedTypes.js @@ -151,10 +151,7 @@ export default iterateJsdoc(({ } traverse(parsedType, ({type, value}, parentNode, property) => { - if (type === 'NAME') { - if (parentNode !== undefined && parentNode.type === 'KEY_VALUE' && property === 'left') { - return - } + if (type === 'JsdocTypeName') { const structuredTypes = structuredTags[tag.tag]?.type; if (!allDefinedTypes.has(value) && (!Array.isArray(structuredTypes) || !structuredTypes.includes(value)) diff --git a/test/rules/assertions/validTypes.js b/test/rules/assertions/validTypes.js index 1caeb593f..561638871 100644 --- a/test/rules/assertions/validTypes.js +++ b/test/rules/assertions/validTypes.js @@ -144,20 +144,6 @@ export default { }, }, }, - { - code: ` - /** - * @alias module:abc#event:foo-bar - */ - function quux() { - - } - `, - errors: [{ - line: 3, - message: 'Syntax error in namepath: module:abc#event:foo-bar', - }], - }, { code: ` /**