loviji
loviji

Reputation: 13080

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.

Upvotes: 1

Views: 7215

Answers (2)

Caio Mar
Caio Mar

Reputation: 2624

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

Upvotes: 1

loviji
loviji

Reputation: 13080

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"
         ]

Upvotes: 3

Related Questions