vscode并在<text>上加上错误的缩进JSX |反应本机

时间:2018-08-09 10:10:32

标签: reactjs react-native visual-studio-code eslint prettier

原始文件如下所示: Before Saving

然后,一旦我保存,它将更改为:

enter image description here

我的开发依赖项:

"devDependencies": {
"@babel/preset-flow": "^7.0.0-beta.56",
"babel-eslint": "^8.2.6",
"babel-jest": "23.4.2",
"babel-preset-react-native": "^5",
"eslint": "^4.19.1",
"eslint-config-airbnb": "^17.0.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-jsx-a11y": "^6.1.1",
"eslint-plugin-react": "^7.10.0",
"flow-bin": "^0.78.0",
"jest": "23.4.2",
"prettier-eslint": "^8.8.2",
"react-test-renderer": "16.4.1"},

任何想法为什么会这样?

谢谢您的关注:)

2 个答案:

答案 0 :(得分:1)

我认为是由于空白配置(例如 no-irregular-whitespace ?)引起的。我想说,最安全的方法是将它们作为单线包装(并用大括号括起来):

<Text>{'Drawer'}</Text>

答案 1 :(得分:0)

我没有安装eslint-plugin-prettier和eslint-config-prettier,然后执行以下操作:

  1. 在“ .eslintrc”的“插件”部分添加“漂亮”
  2. 将“'eslint-config-prettier”,“'eslint-config-prettier / react”和“'eslint-config-prettier / flow”添加到“ .eslintrc”的“扩展”部分
  3. 在“ .eslintrc”的“规则”部分中添加“'更漂亮/更漂亮':['错误',{railingComma:'es5',singleQuote:true}]”

然后删除“ prettier-eslint”包,以便更漂亮可以完全处理格式。先运行“ prettier-eslint”,再运行eslint,以便eslint可以更改prettier制作的格式。

我还禁用了VScode上的漂亮扩展,并按照eslint-config-prettier https://www.npmjs.com/package/eslint-plugin-prettier

的建议添加了漂亮

还要按如下所示配置我的.eslintrc:

{
"extends": [
"airbnb",
"prettier",
"prettier/react"
],
"parser": "babel-eslint",
"parserOptions":{
    "ecmaVersion": 8,
    "ecmaFeatures": {
        "experimentalObjectRestSpread": true,
        "impliedStrict": true,
        "classes": true
    }
},
"env": {
    "browser": true,
    "node": true,
    "jquery": true
},
"plugins": ["react", "prettier"],
"rules": {
    "react/jsx-filename-extension": [
    2,
    {
        "extensions": [".js", ".jsx"]
    }
    ],
    "react/forbid-prop-types": [0],
    "react/require-default-props": [0],
    "global-require": [0],
    "no-underscore-dangle": [0],
    "react/destructuring-assignment": 0,
    "ignoreClassFields": true,
    "no-unused-vars": 1,
    "react/prop-types": 1,
    "camelcase": 1,
    "max-len": 1,
    "prettier/prettier": ["error", { "trailingComma": "es5", "singleQuote": true }]
}

}

希望能帮助到那里的人:)