You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用ESLint触发no-irregular-whitespace不规则空格报错如何解决

TSLint迁移至ESLint v7.31.0问题解决方案

报错1:模板字符串触发不规则空白校验失败

  • 触发代码:const url = ${this.url}​/members​/${memberId}​/profile;
  • 报错信息:Irregular whitespace not allowed
  • 对应规则:no-irregular-whitespace

报错2:配置React规则后提示插件缺失

  • 触发场景:添加如下配置后执行lint报错
plugins: ["@typescript-eslint", "react"],
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:react/recommended"],
rules: {}
  • 报错信息:ESLint couldn't find the plugin "eslint-plugin-react"
  • 解决方案:安装对应依赖即可,执行命令:npm install eslint-plugin-react --save-dev

no-irregular-whitespace误报终极修复

如果确认模板字符串内的空白字符是业务需要,不需要校验,直接在ESLint配置的rules字段中添加以下规则即可:

"no-irregular-whitespace": ["error", { 
  skipRegExps: true, 
  skipTemplates: true 
}]

内容的提问来源于stack exchange,提问作者James

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.09 13:45:02