【问题标题】:Ignore lines from linting and formating - VSC EsLint + Prettier忽略掉毛和格式化中的线条 - VSC EsLint + Prettier
【发布时间】:2021-09-03 03:14:44
【问题描述】:
some.JS.Code;

//ignore this line from linting etc.
##Software will do some stuff here, but for JS it's an Error##

hereGoesJs();

是否有可能从 Visual Studio Code 中的 linting 和格式化中排除一行? 因为我需要这条线,但代码的其他部分也需要 Linting 和 Formatting...

// I Tried

// eslint-disable-next-line no-use-before-define

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

/*eslint-disable */

//suppress all warnings between comments
alert('foo');

/*eslint-enable */

// @ts-ignore
        

【问题讨论】:

  • 是的。您应该查看 ESLint 文档。那里都有解释。
  • @Andy 我查找并尝试了,但它不起作用:/
  • 将特定代码添加到您的问题以及您尝试过的内容中。
  • @Andy 我添加了我尝试过的内容
  • 我第一次这样做时也有点困惑。我想为 8 行代码禁用一条规则,我花了几个小时尝试不同的 cmets 才能让它正确。无论如何,我很高兴我的回答有所帮助。 +1

标签: javascript typescript visual-studio-code prettier-eslint


【解决方案1】:

是的,您有多种选择。



选项 #1 禁用特定规则:


  /* eslint-disable no-var */
  
  var x = 'apple sauce'; 
  
  /* eslint-enable no-var */



选项 #2 禁用整个文件:


// Anything up here will still be affected by the linter.

/* eslint-disable */  // Disables everything from this point down




选项 #3 禁用单行:



    // eslint-disable-next-line 
    var x = 'apple sauce';
    
    //  or you can do this:

    var y = 'apple sauce'; // eslint-disable-line

  



涵盖主题“禁用 ESLint”的官方 ESLint 页面位于以下链接
https://eslint.org/docs/user-guide/configuring/rules#disabling-rules

【讨论】:

    猜你喜欢
    • 2018-02-05
    • 2021-05-31
    • 2019-05-22
    • 2021-03-27
    • 2021-08-15
    • 2017-11-25
    • 2021-09-17
    • 2020-12-25
    • 2021-12-15
    相关资源
    最近更新 更多