Search code examples
typescripttslint

set options for rule in .eslintrc.json


I'd like to use this rule with the ignoreParameters option set to false. My eslint is configured with a .eslintrc.json file and I can't manage to find how to set the options for a rule in this file. I've looked the doc and googled, and I looked at this question but I couldn't find an example of how to set options for a rule with eslint and a .eslintrc.json file.

Here is my .eslintrc.json file before I try to add this rule (the rule is applied, but with default options instead of the options I want) :

{
  "parser": "@typescript-eslint/parser",
  "extends": [
    "react-app",
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "prettier/@typescript-eslint",
    "plugin:prettier/recommended"
  ],
  "rules": {
    "@typescript-eslint/explicit-function-return-type": 0,
    "@typescript-eslint/no-explicit-any": 0,
    "no-return-await": 2,
    "curly": 2
  }
}

and here is what I tried, always resulting in the rule not being applied anymore (with an error Definition for rule '@typescript-eslint/no-inferable-types' was not found @typescript-eslint/no-inferable-types):

{
  "parser": "@typescript-eslint/parser",
  "extends": [
    "react-app",
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "prettier/@typescript-eslint",
    "plugin:prettier/recommended"
  ],
  "rules": {
    "@typescript-eslint/explicit-function-return-type": 0,
    "@typescript-eslint/no-explicit-any": 0,
    "no-return-await": 2,
    "curly": 2,
    "@typescript-eslint/no-inferable-types": [
      "error",
      {
        "ignoreParameters": true
      }
    ]
  }
}

or :

{
 "parser": "@typescript-eslint/parser",
 "extends": [
   "react-app",
   "eslint:recommended",
   "plugin:@typescript-eslint/recommended",
   "prettier/@typescript-eslint",
   "plugin:prettier/recommended"
 ],
 "rules": {
   "@typescript-eslint/explicit-function-return-type": 0,
   "@typescript-eslint/no-explicit-any": 0,
   "no-return-await": 2,
   "curly": 2,
   "@typescript-eslint/no-inferable-types": [
     2,
     {
       "ignoreParameters": true,
       "ignoreProperties": false
     }
   ]
 }
}

Thank you for your help.


Solution

  • So all things I tried were actually with the right syntax (I'll still let this question because I didn't find a clear resource with an example of a .eslinrc.json file with options, leading me to search problem at the wrong place).

    My problem was I tried to change rule no-inferrable-types and I wrote the rule in my .eslintrc.json file no-inferable-types (with one "r" less).

    My (working) .eslintrc.json is therefore this :

    {
      "parser": "@typescript-eslint/parser",
      "extends": [
        "react-app",
        "eslint:recommended",
        "plugin:@typescript-eslint/recommended",
        "prettier/@typescript-eslint",
        "plugin:prettier/recommended"
      ],
      "rules": {
        "@typescript-eslint/explicit-function-return-type": 0,
        "@typescript-eslint/no-explicit-any": 0,
        "no-return-await": 2,
        "curly": 2,
        "@typescript-eslint/no-inferrable-types": [
          2,
          {
            "ignoreParameters": true
          }
        ]
      }
    }