gpt4 book ai didi

javascript - VSCode Linter ES6 ES7 Babel linter

转载 作者:IT王子 更新时间:2023-10-29 03:13:29 25 4
gpt4 key购买 nike

如何使用 Visual Studio code 根据 babel/ES7 stage-0 规则对 JavaScript 文件进行 lint?

我只需要 lint 代码。我已经有 webpack 转译 Js 文件了。

最佳答案

我如何进行:

  • 全局安装 eslint : npm install -g eslint
  • 安装 babel-eslint : npm install --save-dev babel-eslint
  • 安装 eslint-plugin-react : npm install --save-dev eslint-plugin-react
  • 在您的根目录中创建.eslintrc 文件。这是我的配置:

{
"env": {
"browser": true,
"node": true,
"es6": true,
"jest": true,
"jquery": true
},
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"arrowFunctions": true,
"binaryLiterals": true,
"blockBindings": true,
"classes": true,
"defaultParams": true,
"destructuring": true,
"forOf": true,
"generators": true,
"modules": true,
"objectLiteralComputedProperties": true,
"objectLiteralDuplicateProperties": true,
"objectLiteralShorthandMethods": true,
"objectLiteralShorthandProperties": true,
"octalLiterals": true,
"regexUFlag": true,
"regexYFlag": true,
"spread": true,
"superInFunctions": true,
"templateStrings": true,
"unicodeCodePointEscapes": true,
"globalReturn": true,
"jsx": true,
"experimentalObjectRestSpread": true
}
},
"plugins": [
"react"
],
"rules": {
"strict": 0
}
}
  • 在 VSC 中,按 F1,然后输入“扩展”,选择“安装扩展”,然后输入“eslint”并验证。你将不得不重新启动 VSC
  • 在VSC代码中,打开用户参数(settings.json)并写入:

{
//disable default javascript validator replaced by eslint
"javascript.validate.enable" : false
}

现在,它应该会根据需要检查您的 ES7 代码。如果 VSC 读取 eslint 配置有任何问题,您可以在 VSC 控制台(Ctrls移U).

因此,ES7 代码(例如对象中的展开运算符)被很好地检查: enter image description here

PS:可能是我的 .eslintrc 为 ES7 linting 使用了一些无用的额外数据,所以请随意删除它:)

关于javascript - VSCode Linter ES6 ES7 Babel linter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36327096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com