[英]vscode and eslint wrong indentation on <Text> | JSX | React Native
The original file looks like this:原始文件如下所示:
Then once I save, it changes to this:然后一旦我保存,它就会变成这样:
My development dependencies:我的开发依赖:
"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"},
Any ideas why is that happening?任何想法为什么会这样?
Thanks for looking into it:)感谢您调查它:)
I think it's because of whitespace config (eg no-irregular-whitespace ?). 我认为这是由于空白配置(例如, no-irregular-whitespace吗?)。 I'd say the safest way would be having them as one-liner (and wrapped in curly brackets):
我想说,最安全的方法是将它们作为单线包装(并用大括号括起来):
<Text>{'Drawer'}</Text>
I did not have eslint-plugin-prettier and eslint-config-prettier installed, then I did the following: 我没有安装eslint-plugin-prettier和eslint-config-prettier,然后执行以下操作:
And then removed "prettier-eslint" package so prettier can handle the formatting completely. 然后删除“ prettier-eslint”包,以便更漂亮可以完全处理格式。 "prettier-eslint" runs prettier then eslint so eslint can change the formatting made by prettier.
先运行“ prettier-eslint”,再运行eslint,以便eslint可以更改prettier制作的格式。
I also disable prettier extension on VScode and added prettier as suggested on eslint-config-prettier https://www.npmjs.com/package/eslint-plugin-prettier 我还禁用了VScode上的漂亮扩展,并按照eslint-config-prettier https://www.npmjs.com/package/eslint-plugin-prettier上的建议添加了漂亮
And also config my .eslintrc as following: 并配置我的.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 }]
}
} }
Hope that helps someone out there :) 希望可以帮助某人:)
I solved this by adding:我通过添加解决了这个问题:
"react/jsx-indent": [
"error",
4
]
to my.eslintrc.json到我的.eslintrc.json
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.