-
-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typescript contexts in require-jsdoc #640
Comments
Can you provide some sample code that highlights the issue please? |
Here's a code snippet: export enum testEnum {
A, B
}
export const storageMock = () => {
const storage: { [key: string]: any } = {};
return {
setItem: (key: string, value: string) => {
storage[key] = value || "";
},
getItem: (key: string) => {
return key in storage ? storage[key] : null;
},
removeItem: (key: string) => {
delete storage[key];
},
get length() {
return Object.keys(storage).length;
},
key: (i: number) => {
const keys = Object.keys(storage);
return keys[i] || null;
},
};
}; It reports an error at |
Also, here's the full config I'm using, in case anything is missing: module.exports = {
"extends": [
"plugin:jsdoc/recommended"
],
"plugins": [
"jsdoc"
],
"settings": {
"jsdoc": {
"mode": "typescript",
"exemptedBy": ["alpha", "internal"]
}
},
"rules": {
"jsdoc/newline-after-description": "off",
"jsdoc/check-alignment": "off",
"jsdoc/check-tag-names": "off",
"jsdoc/require-param": "off",
"jsdoc/require-param-type": "off",
"jsdoc/require-returns": "off",
"jsdoc/require-returns-type": "off",
"jsdoc/require-jsdoc": [
"error",
{
"publicOnly": true, // only report exports
"require": {
"ArrowFunctionExpression": true,
"ClassDeclaration": true,
"ClassExpression": true,
"FunctionDeclaration": true,
"FunctionExpression": true,
"MethodDefinition": false,
},
"contexts": [
"ArrowFunctionExpression",
"ClassDeclaration",
"ClassExpression",
"ClassProperty",
"FunctionDeclaration", // function
"FunctionExpression",
"MethodDefinition",
"TSDeclareFunction", // function without body
"TSEnumDeclaration",
"TSInterfaceDeclaration",
"TSMethodSignature",
"TSModuleDeclaration", // namespace
"TSTypeAliasDeclaration",
"VariableDeclaration",
]
}
],
}
} |
🎉 This issue has been resolved in version 30.5.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
I've fixed both the fact that I'm not a regular TS user, so if you find other TS AST is not working, please provide sample code for the syntax of interest, and there is a better chance we can add the support. |
Thanks, that was fast. I'll see if I encounter any more elements not working, but just to make it clear: anything I add to Considering there are more flavors of Javascript that add their own syntactic sugar than just Typescript, and there might come more in the future, I think the |
In the case of I'm not 100% comfortable with this rule, tbh, as it is implemented with some complexity and not enough docs. I get the basic idea and can get things to work with it, but I do not have the energy to dive in to get a better feel for how we can architect it any differently for more broadly-applicable defaults, or if that is not possible (since some AST probably does require its own parsing), then to pre-populate the specific TS types that will be needed. So you can either look into it on your own, or report some specific needs, and we can see about figuring them out one or a few at a time. I don't expect most people will be exporting every type of TS type anyways, as many of the types are inside of functions and such. |
If you want to help with a review, i suspect the ones with |
Wouldn't it be safe to say that any descendant of an The only exception I see with this is that you can have private or protected members in Typescript, which will just have an Does that make sense, or am I missing something? |
Much of the implementation is handling checks for cjs and window which are more complicated, e.g., for code like this which discovers that
The bulk of the logic is within There is the function quux () {
}
export default quux; Recursion is going on, but as I mentioned, you'll have to work on it on your own if you want to get into real refactoring. PRs are welcome, assuming existing tests continue to pass. |
The
require
option only allows a small subset of AST nodes, and the whitelist doesn't include anything Typescript-specific. So, in order to check for jsdoc comments at Typescript-specific AST nodes, like enums, we're advised to add the required node types to thecontexts
option, as per #484.However, this doesn't seem to work. I have the following config:
Enums are still not validated. In fact, if I remove the
require
option, it doesn't validate anything at all, even though all these node types are still incontexts
.The text was updated successfully, but these errors were encountered: