简体   繁体   English

eslint 缩进和@typescript-eslint/indent 冲突

[英]eslint indent and @typescript-eslint/indent conflict

So I'm using eslint and prettier on a TS express app.所以我在 TS express 应用上使用了 eslint 和 prettier。 I want to set tab width to 4, but it seems the base eslint and the typescript eslint are in conflict.我想将制表符宽度设置为 4,但似乎基本 eslint 和 typescript eslint 有冲突。

This is what it gives me for the same line:这就是它给我的同一行:

在此处输入图像描述

This is my eslintrc.json:这是我的 eslintrc.json:

{
    "env": {
        "browser": true,
        "commonjs": true,
        "es2021": true
    },
    "extends": "standard-with-typescript",
    "overrides": [],
    "parserOptions": {
        "ecmaVersion": "latest",
        "project": "tsconfig.json"
    },
    "rules": {
        "indent": ["error", 4],
        "prettier/prettier": ["error", { "endOfLine": "auto" }]
    },
    "parser": "@typescript-eslint/parser",
    "plugins": ["prettier"]
}

This is my prettierrc.json:这是我的 prettierrc.json:

{
  "singleQuote": true,
  "arrowParens": "always",
  "printWidth": 120,
  "semi": false,
  "tabWidth": 4
}

Any idea how to resolve it so I can just have 4 spaces to a tab?知道如何解决它,以便我可以在一个选项卡上留出 4 个空格吗?

If you're using prettier and eslint, you should use the prettier eslint configuration.如果你使用 prettier 和 eslint,你应该使用 prettier eslint 配置。 It will disable every style-only eslint rule.它将禁用每个仅样式的 eslint 规则。 It should be ok, since styles would be left for prettier to format.应该没问题,因为 styles 会留给更漂亮的格式。 See the docs for more info on this.有关这方面的更多信息,请参阅文档

Since you have the prettier plugin installed, you can change your extends line to this and it should be enough:由于您安装了更漂亮的插件,您可以将您的扩展行更改为此,它应该足够了:

"extends": ["standard-with-typescript", "plugin:prettier/recommended"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM