eslint和prettier样式冲突解决

原因:eslint格式化部分的规则和 prettier不兼容。

解决方案:

eslint-config-prettier + eslint-plugin-prettier

  • eslint-config-prettier:关闭eslint中与prettier相互冲突的规则。
  • eslint-plugin-prettier:赋予eslintprettier格式化代码的能力。

安装依赖并修改.eslintrc文件

{
    "parser": "@typescript-eslint/parser",
    "env": {
        "browser": true,
        "jest": true
    },
    "extends": [
        "airbnb",
        "plugin:@typescript-eslint/recommended",
        // 使用来自@typescript-eslint/eslint-plugin的推荐规则
        "plugin:prettier/recommended"
    ],
    "globals": {
        "$": true,
        "describe": true,
        "expect": true,
        "test": true,
        "it": true,
        "jest": true
    },
    "rules": {
        "no-underscore-dangle": "off",
        "one-var": 0,
        "one-var-declaration-per-line": 0,
        "no-restricted-syntax": 0,
        "no-plusplus": 0,
        "no-param-reassign": 0,
        "linebreak-style": [
            "error",
            "unix"
        ],
        "func-names": [
            "error",
            "never"
        ],
        "semi": 2,
        "indent": [
            "error",
            4,
            {
                "VariableDeclarator": 2,
                "SwitchCase": 1
            }
        ],
        "max-len": [
            "error",
            {
                "code": 300
            }
        ],
        "arrow-parens": [
            "error",
            "as-needed"
        ],
        "import/no-unresolved": 0,
        "import/extensions": 0,
        "react/jsx-indent": [
            0,
            4
        ],
        "react/forbid-prop-types": 0,
        "react/jsx-indent-props": [
            "error",
            4
        ],
        "react/self-closing-comp": [
            "error",
            {
                "component": true,
                "html": false
            }
        ],
        "jsx-quotes": [
            2,
            "prefer-single"
        ],
        "no-unused-expressions": [
            "error",
            {
                "allowShortCircuit": true,
                "allowTernary": true
            }
        ],
        "jsx-a11y/click-events-have-key-events": 0,
        "jsx-a11y/no-static-element-interactions": 0,
        "jsx-a11y/no-noninteractive-element-interactions": 0,
        "react/jsx-one-expression-per-line": 0,
        "prefer-destructuring": 0,
        "react/no-multi-comp": 0,
        "no-nested-ternary": 0,
        "no-multi-assign": 0,
        "react/no-array-index-key": 0,
        "react/jsx-props-no-spreading": 0,
        "import/prefer-default-export": 0,
        "max-classes-per-file": 0,
        "array-callback-return": 0,
        "react/no-find-dom-node": 0,
        "import/no-extraneous-dependencies": 0,
        "react/jsx-pascal-case": 0,
        "react/state-in-constructor": 0,
        "react/jsx-filename-extension": [
            "error",
            {
                "extensions": [
                    ".js",
                    ".jsx",
                    ".ts",
                    ".tsx"
                ]
            }
        ],
        "no-use-before-define": "off",
        "react/forbid-foreign-prop-types": "off",
        "@typescript-eslint/no-empty-function": "off"
    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值