gpt4 book ai didi

reactjs - 使用 typescript react CRA 不适用于 eslint

转载 作者:搜寻专家 更新时间:2023-10-30 21:55:04 26 4
gpt4 key购买 nike

我正在尝试将 linting 集成到使用 CRA 创建的应用程序中,该应用程序使用 typescript。

在终端重现的步骤

  • create-react-app my-app --typescript
  • ./node_modules/.bin/eslint --init
    • select :检查语法、发现问题并强制执行代码风格
    • 选择:JavaScript 模块(导入/导出)
    • 选择: react
    • y 你的项目是否使用 typescript
    • 选择:浏览器
    • 使用的流行风格指南是 airbnb

我的 .eslintrc json 文件如下所示

{
"env": {
"browser": true,
"es6": true
},
"extends": [
"airbnb"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"react",
"@typescript-eslint"
],
"rules": {
"semi":"warn"
}
}

我通常通过删除分号来检查 lint 是否有效,以查看 vs 代码是否突出显示。

然而它并没有发生。

最佳答案

将以下代码片段添加到 VS 代码上的 settings.json 即可。

"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
],

关于reactjs - 使用 typescript react CRA 不适用于 eslint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58264433/

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