Skip to content
← Back to rules

eslint/no-irregular-whitespace 正确性

This rule is turned on by default.

它做了什么

禁止在代码中使用不规则的空白字符。

为什么这是个问题?

不规则的空白字符对大多数编辑器来说是不可见的,可能会导致意外行为,使代码更难调试和维护。它们还可能引起代码格式化和解析方面的问题。

示例

此规则的错误代码示例:

javascript
// 包含不规则的空白字符(不可见)
function example() {
  var foo = "bar"; // 'bar' 前存在不规则空白
}

此规则的正确代码示例:

javascript
function example() {
  var foo = "bar"; // 仅使用常规空格
}

如何使用

要通过配置文件或命令行工具启用此规则,可以使用:

json
{
  "rules": {
    "no-irregular-whitespace": "error"
  }
}
bash
oxlint --deny no-irregular-whitespace

参考资料