Turning off eslint rule for a specific file

后端 未结 15 1459
后悔当初
后悔当初 2020-11-30 17:26

Is it possible to turn off the eslint rule for the whole file? Something such as:

// eslint-disable-file no-use-before-define 

(Analogous t

15条回答
  •  無奈伤痛
    2020-11-30 17:29

    To disable specific rules for file(s) inside folder(s), you need to use the "overrides" key of your .eslintrc config file.

    For example, if you want to remove the following rules:

    1. max-lines-per-function
    2. import/no-unresolved

    For all files inside the following main folder:

    /spec

    You can add this to your .eslintrc file...

    "overrides": [
      {
        "files": ["spec/**/*.js"],
        "rules": {
          "max-lines-per-function": ["off"],
          "import/no-unresolved": ["off"]
        }
      }
    ]
    

    Note that I used ** inside the spec/**/*.js regex, which means I am looking recursively for all subfolders inside the folder called spec and selecting all files that ends with js in order to remove the desired rules from them.

提交回复
热议问题