How can I use ESLint no-unused-vars for a block of code?

前端 未结 5 1981
野趣味
野趣味 2021-02-03 20:24

I need to disable some variable checks in ESLint.

Currently, I am using this code, but am not getting the desired result:



        
相关标签:
5条回答
  • 2021-02-03 20:52

    For typescript eslint users just add this at the end of line you wish to ignore:

    // eslint-disable-line @typescript-eslint/no-unused-vars
    
    0 讨论(0)
  • 2021-02-03 21:04

    One more option...

    function doStuff({
      // eslint-disable-next-line no-unused-vars
      unused,
      usedA,
      usedB
    }) {
    
    0 讨论(0)
  • 2021-02-03 21:14

    Just use pair of lines:

    /* eslint-disable no-unused-vars */
    
    // ... your code here with unused vars...
    
    /* eslint-enable no-unused-vars */
    
    0 讨论(0)
  • 2021-02-03 21:14

    If you've got multiple overlapping rules that you want to ignore (e.g. typescript and standard js), you can specify more than one rule to ignore by separating by a comma:

    // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
    
    0 讨论(0)
  • 2021-02-03 21:17

    Alternatively, you can disable the rule for one line:

    // Based on your Typescript example
    
    export type Hey = { // eslint-disable-line no-unused-vars
      a: string,
      b: object
    }
    
    0 讨论(0)
提交回复
热议问题