[英]prevent asking "Missing JSDoc comment" for standard react methods in typescript project
we have React project with Typescript. We use TSDoc to standardize the doc comments used in TypeScript code我们有 Typescript 的 React 项目。我们使用TSDoc来标准化 TypeScript 代码中使用的文档注释
Our eslint.trc file as follow:我们的 eslint.trc 文件如下:
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"plugin:react/recommended",
"google",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"react",
"@typescript-eslint/eslint-plugin",
"eslint-plugin-tsdoc"
],
"settings": {
"react": {
"version": "detect"
}
},
"rules": {
"tsdoc/syntax": "warn",
"valid-jsdoc" : 0,
"@typescript-eslint/explicit-module-boundary-types": "off"
}
}
How to configure this configuration file, for not asking ESLINT about documenting standard react methods, like constructor(),static getDerivedStateFromProps(),render(),componentDidMount() and etc.
如何配置此配置文件,因为不询问 ESLINT 关于记录标准反应方法,如
constructor(),static getDerivedStateFromProps(),render(),componentDidMount() and etc.
We can switch "require-jsdoc":"off"
, but it also will not ask out user defined methods in class.我们可以切换
"require-jsdoc":"off"
,但它也不会询问 class 中用户定义的方法。
I've resolved this problem with this plugin https://www.npmjs.com/package/eslint-plugin-require-jsdoc-except?activeTab=readme我已经用这个插件https://www.npmjs.com/package/eslint-plugin-require-jsdoc-except?activeTab=readme解决了这个问题
You can add your function names at ignore:您可以在忽略时添加您的 function 名称:
"ignore":[
"constructor", "render","componentDidUpdate","getDerivedStateFromProps","componentDidMount"
]
Add this to your .eslintrc.js
rules:将此添加到您的
.eslintrc.js
规则中:
rules: {
'require-jsdoc': [
'error',
{
require: {
FunctionDeclaration: false,
MethodDefinition: false,
ClassDeclaration: false,
ArrowFunctionExpression: false,
FunctionExpression: false,
},
},
],
},
Read more: https://eslint.org/docs/latest/rules/require-jsdoc阅读更多: https://eslint.org/docs/latest/rules/require-jsdoc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.