需要 Typescript 接口、枚举、命名空间等的文档
Require documentation for Typescript interfaces, enums, namespaces, etc
我过去曾使用 TSLint 来要求文档,例如接口、枚举和 Javascript 中不存在的其他内容:
"completed-docs": [
true,
{
...
"enums": {
"visibilities": ["all"]
},
"enum-members": {
"visibilities": ["all"]
},
"functions": {
"visibilities": ["all"]
},
"interfaces": {
"visibilities": ["all"]
},
"namespaces": {
"visibilities": ["all"]
},
"types": {
"visibilities": ["exported"]
},
"variables": {
"visibilities": ["exported"]
}
鉴于 TSLint 已被弃用,我想使用 Eslint,但无论如何我找不到需要有关 Typescript 结构的文档...我可以通过此规则需要有关 类、方法等的文档:
"jsdoc/require-jsdoc": ["error", {"require": {
"FunctionExpression": true,
"ClassDeclaration": true,
"MethodDefinition": true,
"ArrowFunctionExpression": true,
"ClassExpression": true
}}],
但是该规则不支持要求 Typescript 结构的文档。有什么方法可以用 Eslint 做到这一点(不使用 TSLint 插件?)
您的问题已解决 here,您应该:
Add the AST types to the contexts option to the rule.
You'll have to consult a list of TypeScript AST to find the types or
use a @typescript-eslint/parser-supporting AST explorer like
astexplorer.net (there is also ts-ast-viewer.com and that is
TS-specific, but it is not using @typescript-eslint/parser which
adapts TS interfaces into the AST needed by ESLint and which we are
using).
So, for example:
'jsdoc/require-jsdoc': ['error', {contexts: ['TSInterfaceDeclaration', 'TSTypeAliasDeclaration', 'TSEnumDeclaration']}]
我过去曾使用 TSLint 来要求文档,例如接口、枚举和 Javascript 中不存在的其他内容:
"completed-docs": [
true,
{
...
"enums": {
"visibilities": ["all"]
},
"enum-members": {
"visibilities": ["all"]
},
"functions": {
"visibilities": ["all"]
},
"interfaces": {
"visibilities": ["all"]
},
"namespaces": {
"visibilities": ["all"]
},
"types": {
"visibilities": ["exported"]
},
"variables": {
"visibilities": ["exported"]
}
鉴于 TSLint 已被弃用,我想使用 Eslint,但无论如何我找不到需要有关 Typescript 结构的文档...我可以通过此规则需要有关 类、方法等的文档:
"jsdoc/require-jsdoc": ["error", {"require": {
"FunctionExpression": true,
"ClassDeclaration": true,
"MethodDefinition": true,
"ArrowFunctionExpression": true,
"ClassExpression": true
}}],
但是该规则不支持要求 Typescript 结构的文档。有什么方法可以用 Eslint 做到这一点(不使用 TSLint 插件?)
您的问题已解决 here,您应该:
Add the AST types to the contexts option to the rule.
You'll have to consult a list of TypeScript AST to find the types or use a @typescript-eslint/parser-supporting AST explorer like astexplorer.net (there is also ts-ast-viewer.com and that is TS-specific, but it is not using @typescript-eslint/parser which adapts TS interfaces into the AST needed by ESLint and which we are using).
So, for example:
'jsdoc/require-jsdoc': ['error', {contexts: ['TSInterfaceDeclaration', 'TSTypeAliasDeclaration', 'TSEnumDeclaration']}]