【问题标题】:How to deal with conflicting eslint rules in AirBNB configuration如何处理 AirBNB 配置中冲突的 eslint 规则
【发布时间】:2021-01-02 06:40:57
【问题描述】:

我是一个尝试在 Vue 中编写 POC 的菜鸟。我在 AirBNB 配置中使用 ESLint,但遇到了冲突。

这是我的 Axios 调用的错误捕获部分:

  .catch((error) => {
    errorMsg.value = error;
    console.log('Error is ' + error);
    console.log(`Error is {error}`);
  });

这是我收到的 linter 错误:

  50:21  error  Unexpected string concatenation  prefer-template
  51:21  error  Strings must use singlequote     quotes

✖ 2 problems (2 errors, 0 warnings)

由于这两个相互冲突的规则,我似乎无法获得我想要的输出。我做错了什么?

【问题讨论】:

  • 尝试将{error}替换为${error},这是JS中字符串插值的正确语法(即不要忘记$符号)。 ESlint 可能认为是普通字符串,推荐使用单引号
  • @Riron:是的,python 把我绊倒了。把它作为一个答案,我会把它标记为正确的。谢谢!

标签: javascript vue.js eslint


【解决方案1】:

JS 中的字符串插值需要$ 符号。 所以你应该使用:

.catch((error) => {
    errorMsg.value = error;
    console.log('Error without interpolation'); // Single quotes for simple strings
    console.log(`Error is ${error}`); // Template for interpolation
  });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-04
    • 2020-02-28
    • 2018-02-22
    • 1970-01-01
    • 1970-01-01
    • 2019-11-10
    • 2020-09-09
    • 2022-01-13
    相关资源
    最近更新 更多