englercj / tsd-jsdoc

Compiles JSDoc annotated JavaScript into a Typescript Definition file (.d.ts)
MIT License
316 stars 42 forks source link

Incorrect warning: Failed to find parent of doclet #133

Open mramato opened 4 years ago

mramato commented 4 years ago

Given SomeClass.js

/**
 * Some Class
 * @constructor
 * @private
 */
function SomeClass() {}

/**
 * Some Function
 */
SomeClass.someFunction = function () {};

/**
 * Some Prototype Function
 */
SomeClass.somePrototypeFunction = function () {};

export default SomeClass;

tsd-jsdoc outputs the below, incorrect, warnings:

[TSD-JSDoc] SomeClass.js:12:0 Failed to find parent of doclet 'SomeClass.someFunction' using memberof 'SomeClass', this is likely due to invalid JSDoc.
[TSD-JSDoc] SomeClass.js:18:0 Failed to find parent of doclet 'SomeClass.somePrototypeFunction' using memberof 'SomeClass', this is likely due to invalid JSDoc.

tsd-jsdoc should pick up on the fact that SomeClass is marked private and not print warnings for someFunction or somePrototypeFunction because they are automatically made private as well (according to JSDoc). JSDoc has no issues with this file.

I was able to hack up the JS to fix for this in my local tsd-jsdoc install, but would be happy to open a PR to fix it properly. I did this by adding an _ignoredNodes property to Emitter and then wrapping the warning in an additional check to see if the memberof is an ignored node and only displaying the warning if that is the case.

Thanks again for an awesome tool.

englercj commented 4 years ago

This looks like a dupe of #105 which should be fixed in the latest version, can you confirm?

mramato commented 4 years ago

@englercj I can confirm that it happens with 2.5.0 (installed via npm). Also, I was using jsdoc 3.6.4 (latest version via npm) in case that matters.

I put together a reduced test case that you can run to see the problem: issue133.zip (Just npm install and then npm start

Basically it includes SomeClass.js, a simplified package.json where npm start simple runs:

jsdoc --configure ts-conf.json

where ts-conf.json is

{
    "source": {
        "include": [
            "SomeClass.js"
        ]
    },
    "opts": {
        "template": "./node_modules/tsd-jsdoc/dist"
    }
}

and the output is

$ npm start

> issue133@0.0.0 start /home/mamato/Git/issue133
> jsdoc --configure ts-conf.json

[TSD-JSDoc] SomeClass.js:11:0 Failed to find parent of doclet 'SomeClass.someFunction' using memberof 'SomeClass', this is likely due to invalid JSDoc.
[TSD-JSDoc] SomeClass.js:16:0 Failed to find parent of doclet 'SomeClass.somePrototypeFunction' using memberof 'SomeClass', this is likely due to invalid JSDoc.
mramato commented 4 years ago

@englercj if there's anything I can do to help out here, please let me know. I suppose I can just pull down master and open a PR, but wanted to make sure you would be willing to review/accept it first.

FYI we just opened our Cesium pull request which uses tsd-jsdoc https://github.com/CesiumGS/cesium/pull/8878 and you'll be happy to hear that everything else worked great. I'm not sure how big the typical TypeScript type definition is, but ours ended up being ~41,000 lines and 1.9 MB :smile:

Thanks again for a great tool.

englercj commented 4 years ago

PRs are the best way to get changes to this repo. I don't spend much time on it these days.