首页 > 解决方案 > Eslint 仍在将双引号更改为单引号

问题描述

这是我第一次使用 eslint,所以如果我错过了下面的任何信息,请在评论中告诉我。我有一个 react native 项目并在其中配置了 eslint。这是我的规则:

{
    "env": {
        "browser": true,
        "es6": true,
        "node": true,
            "react-native/react-native": true,

    },
    "extends": "eslint:recommended",
    "globals": {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly"
    },
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": 2018,
        "sourceType": "module"
    },
    "plugins": [
        "react",
            "react-native"
    ],
    "rules": {
      "quotes": [2, "double", "avoid-escape"],
            "semi": [
          "error",
            "always"
      ],
            "indent": [
            "error",
            2
        ],
            "linebreak-style": [
                    "error",
                    "unix"
            ],
            "react-native/no-unused-styles": 2,
            "react-native/split-platform-components": 2,
            "react-native/no-inline-styles": 2,
            "react-native/no-color-literals": 2,
            "react-native/no-raw-text": 2,
            "object-curly-spacing": [2, "always", {
                "objectsInObjects": true,
                "arraysInObjects": true
            }]
    }
}

正如您在此处看到的关于引号和对象卷曲间距的两个重要规则。即使我已将引号设置为双倍,但当我执行 yarn lint --fix 时,它仍会警告我

警告字符串必须使用单引号

并使用 --fix 标志将其更改为单引号。我在这里做错了什么,请解释一下。

同样,将对象卷曲间距设置为“始终”,我的导入从对象中的空格更改为无空格,即从 {test} 到 {test}。

我想要在对象文字之后和之前使用双引号和空格的字符串。

标签: react-nativeeslint

解决方案


推荐阅读