使用Prettier与Eslint,ESLINT错误删除;从之前(

发布于 2025-01-23 18:30:12 字数 1511 浏览 1 评论 0 原文

我的React TypeScript Prettier和Eslint配置如下。 它大多仅适用于一个情况

ESLINT错误的正常工作:不必要的半隆。

“在此处输入图像描述”

注意: semicolumn由Prettier强制执行,但在下面的配置中是设置为false。

配置文件:

.prettierrc

{
  "trailingComma": "es5",
  "tabWidth": 2,
  "semi": false,
  "singleQuote": true,
  "printWidth": 100,
  "bracketSpacing": true
}

.eslintrc.json

{
  "env": {
    "browser": true,
    "es2021": true
  },
  "extends": [
    "plugin:react/recommended",
    "plugin:@typescript-eslint/recommended"
    // "plugin:prettier/recommended"
  ],
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": "latest",
    "sourceType": "module"
  },
  "plugins": ["react", "@typescript-eslint", "react-hooks"],
  "rules": {
    "semi": [2, "never"],
    // "no-extra-semi": "error",
    "react/react-in-jsx-scope": "off",
    "react-hooks/rules-of-hooks": "error",
    "react-hooks/exhaustive-deps": "warn",
    "react/jsx-filename-extension": [
      1,
      {
        "extensions": [".ts", ".tsx"]
      }
    ]
  },
  "settings": {
    "react": {
      "version": "detect"
    }
  }
}

我有一些异步代码,例如

;(async() => {
// some code 
}
)()

可能有更漂亮的Eslint配置冲突。不确定如何解决它们。

My react typescript prettier and eslint config as below.
It mostly works fine just for one case

Eslint error: Unnecessary semicolon.

enter image description here

Note: semicolumn is enforced by prettier but in the below config it is set to false.

Config Files:

.prettierrc

{
  "trailingComma": "es5",
  "tabWidth": 2,
  "semi": false,
  "singleQuote": true,
  "printWidth": 100,
  "bracketSpacing": true
}

.eslintrc.json

{
  "env": {
    "browser": true,
    "es2021": true
  },
  "extends": [
    "plugin:react/recommended",
    "plugin:@typescript-eslint/recommended"
    // "plugin:prettier/recommended"
  ],
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": "latest",
    "sourceType": "module"
  },
  "plugins": ["react", "@typescript-eslint", "react-hooks"],
  "rules": {
    "semi": [2, "never"],
    // "no-extra-semi": "error",
    "react/react-in-jsx-scope": "off",
    "react-hooks/rules-of-hooks": "error",
    "react-hooks/exhaustive-deps": "warn",
    "react/jsx-filename-extension": [
      1,
      {
        "extensions": [".ts", ".tsx"]
      }
    ]
  },
  "settings": {
    "react": {
      "version": "detect"
    }
  }
}

I have some async code like

;(async() => {
// some code 
}
)()

There may be prettier and eslint config conflict. not sure how to resolved them.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文