简体   繁体   English

防止为 typescript 项目中的标准反应方法询问“缺少 JSDoc 评论”

[英]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.

相关问题 使用@component 生成 React 18 项目的 JSDoc 文档 - Generating JSDoc Documentation on React 18 Project with @component 解决 TypeScript React JS Lint: React Hook useEffect has a missing dependency without using comment to disable lint or without pass dependency - Resolving TypeScript React JS Lint: React Hook useEffect has a missing dependency without using comment to disable lint or without passing dependency 可选用 jsdoc、typescript checkjs (javascript) 反应 useState 类型 - optional react useState types with jsdoc, typescript checkjs (javascript) 在标准create-react-app打字稿项目上加载scss模块时出现问题 - Trouble while Loading scss module on the standard create-react-app typescript project 如何在用TypeScript编写的React中注释HTML? - How to comment HTML within React written in TypeScript? 缺少 JSDoc @param "props.children" 类型。 和缺少 JSDoc @param "props.children" 类型。 使用 React Native FunctionalComponents - Missing JSDoc @param "props.children" type. and Missing JSDoc @param "props.children" type. with React Native FunctionalComponents Linting 反应 typescript 项目 - Linting react typescript project 现有 React 项目中的 Typescript - Typescript in Existing React Project 在Typescript + Webpack项目中缺少源图 - Missing sourcemaps in Typescript + Webpack project 打字稿反应属性和方法修饰符 - Typescript react properties and methods modifiers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM