如何抑制错误:混合空格和制表符?

新手上路,请多包涵

我在 Vue.js 应用程序中收到了这个烦人的“错误”消息。

 error: Mixed spaces and tabs (no-mixed-spaces-and-tabs) at src/components/Landing.vue:388:2:

我想知道如何抑制它?

原文由 Babr 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 961
2 个回答

这是一个 ESLint 错误( no-mixed-spaces-and-tabs ,旨在警告不要同时使用空格和制表符来缩进代码。空格/制表符的 一致性 是一种代码约定,这在团队内共享代码库 ( 1 ) ( 2 ) 时很重要。如果您是单独使用它(并且没有其他计划),请随意禁用/启用您想要的任何规则。

禁用每个项目的规则

您可以配置 ESLint 以忽略整个项目中的该错误。配置通常存储在 Vue CLI 生成的项目中的 .eslintrc.js 中。在该文件中,编辑 rules 对象以包含:

 // .eslintrc.js
module.exports = {
  "rules": {
    "no-mixed-spaces-and-tabs": 0, // disable rule
  }
}

禁用每行规则

要仅忽略单行的该错误,请在该行上使用内联注释( eslint-disable-line no-mixed-spaces-and-tabseslint-disable-next-line no-mixed-spaces-and-tabs ):

 ⋅⋅const x = 1
⇥⋅⋅const y = 2 // eslint-disable-line no-mixed-spaces-and-tabs

// eslint-disable-next-line no-mixed-spaces-and-tabs
⇥⋅⋅const z = 3

禁用每个部分的规则

要忽略多行代码的该错误,请在代码周围加上 eslint-disable no-mixed-spaces-and-tabseslint-enable no-mixed-spaces-and-tabs 多行 注释:

 ⋅⋅const x = 1

/* eslint-disable no-mixed-spaces-and-tabs */
⇥⋅⋅const y = 2  // 🙈
⇥⋅⋅const z = 3  // 🙈
/* eslint-enable no-mixed-spaces-and-tabs */

⇥⋅⋅const q = 4  // ❌ error: mixed spaces and tabs!

原文由 tony19 发布,翻译遵循 CC BY-SA 4.0 许可协议

转到 view option 然后转到 indentation 你会发现 indent using space 。你的问题应该得到解决。如果未修复,请转到 convert indention to spaces

原文由 Milon Rai 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题