【问题标题】:Fix do expression throwing linter error in VS Code修复 VS Code 中的 do 表达式抛出 linter 错误
【发布时间】:2021-04-11 07:31:49
【问题描述】:

一段时间以来,我一直在努力让 Visual Studio Code 停止抱怨和减慢我的编辑器,因为这个 linter 错误是关于 do 表达式没有一段时间或期待一个表达式。

这是我在编辑器中看到的内容

我已经安装了 eslint,这是我拥有的版本

"@babel/core": "7.9.0",
"babel-eslint": "10.1.0",
"@babel/eslint-plugin": "^7.12.1",
"@babel/plugin-proposal-do-expressions": "^7.8.3",
"eslint": "^6.6.0",

这是我的一些配置

...
"plugins": [
  ...
  "@babel"
],
...
"rules": {
  "no-unused-expressions": 0,
  "@babel/no-unused-expressions": 2,
},
...

我无法弄清楚为什么我仍然在编辑器中收到这些错误,我不确定这是否与 eslint 相关,或者当我将鼠标悬停在它上面时是否有其他原因导致它我看到了这个,看起来打字稿现在可能正在整理它?即使它是一个 javascript 文件?

这是来自 babel 插件提案页面的示例 https://babeljs.io/docs/en/babel-plugin-proposal-do-expressions

const Component = props =>
  <div className='myComponent'>
    {do {
      if(color === 'blue') { <BlueComponent/>; }
      else if(color === 'red') { <RedComponent/>; }
      else if(color === 'green') { <GreenComponent/>; }
    }}
  </div>
;

【问题讨论】:

    标签: javascript typescript visual-studio-code eslint


    【解决方案1】:

    2020 年 11 月 20 日更新 注意:babel-eslint 现在是 @babel/eslint-parser 并已移至 Babel monorepo

    $ npm install @babel/eslint-parser --save-dev
    # or
    $ yarn add @babel/eslint-parser -D
    

    然后在你的.eslintrc 做:

    {
      parser: "@babel/eslint-parser",
    }
    

    来源: https://stackoverflow.com/a/61629494/13859552 https://eslint.org/docs/user-guide/configuring

    【讨论】:

      猜你喜欢
      • 2022-01-20
      • 1970-01-01
      • 2023-04-04
      • 2023-02-20
      • 2020-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-30
      相关资源
      最近更新 更多