Turning off eslint rule for a specific file

后端 未结 15 1456
后悔当初
后悔当初 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:36
    /* eslint-disable */
    
    //suppress all warnings between comments
    alert('foo');
    
    /* eslint-enable */
    

    This will disable all eslint rules within the block.

    0 讨论(0)
  • 2020-11-30 17:39

    As of today, the answer does not work for me, but putting this at the top of the file does work:

    /* eslint-disable @typescript-eslint/no-unused-vars */
    

    It is important to know that at least in my case, the type of comment makes a difference. The previous comment works for me, but the following won't work:

    // eslint-disable @typescript-eslint/no-unused-vars
    
    0 讨论(0)
  • 2020-11-30 17:39

    You can turn off specific rule for a file by using /*eslint [<rule: "off"], >]*/

    /* eslint no-console: "off", no-mixed-operators: "off" */

    Version: eslint@4.3.0

    0 讨论(0)
  • 2020-11-30 17:40

    You can turn off/change a particular rule for a file by putting the configurations at the top of the file.

    /* eslint no-use-before-define: 0 */  // --> OFF
    
    or
    
    /* eslint no-use-before-define: 2 */  // --> ON
    

    More info

    0 讨论(0)
  • 2020-11-30 17:46

    Simply create an empty file .eslintignore in your project root the type the path to the file you want it to be ignore.

    Source: https://eslint.org/docs/2.13.1/user-guide/configuring#:~:text=To%20disable%20rule%20warnings%20in,*%2F%20alert('foo')%3B

    Line Ignoring Files and Directories

    0 讨论(0)
  • 2020-11-30 17:48

    Accepted answer didn't work for me (maybe a different version of eslint...? I'm using eslint v3.19.0), but did find a solution with the following...

    Place the following on the top of your file

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

    This will disable the rule for the entire file

    0 讨论(0)
提交回复
热议问题