Search code examples
reactjstypescripteslinttsdoc

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

Our eslint.trc file as follow:

{
    "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.

We can switch "require-jsdoc":"off", but it also will not ask out user defined methods in class.


Solution

  • I've resolved this problem with this plugin https://www.npmjs.com/package/eslint-plugin-require-jsdoc-except?activeTab=readme

    You can add your function names at ignore:

     "ignore":[
                "constructor", "render","componentDidUpdate","getDerivedStateFromProps","componentDidMount"
             ]