使用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
相关产品推荐
相关产品推荐

