prevent asking "Missing JSDoc comment" for standard react methods in typescript project

5.5k views Asked by At

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.

2

There are 2 answers

0
loviji On BEST ANSWER

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"
         ]
0
Caio Mar On

Add this to your .eslintrc.js rules:

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