[英]how to change prettier format for react native
my code formatting prettier didn't works well for react native, i don't understand where to config it but it works well with flutter我的代码格式 prettier 不适用于 React Native,我不知道在哪里配置它,但它适用于 flutter
from this code从这个代码
import { View, Text } from 'react-native'
import React from 'react'
export default function App() {
return (
<View>
<Text>Apps</Text>
</View>
)
}
it's formatted to this它被格式化为这个
import {
View,
Text
} from 'react-native'
import React from 'react'
export default function App() {
return ( <
View >
<
Text > Apps < /Text>
<
/View>
)
}
There is a shortcut for every idea to format your code, for instance for Vscode Ctrl + Shift + I
每个想法都有一个快捷方式来格式化代码,例如 Vscode
Ctrl + Shift + I
AND use Prettier to format your code in all files并使用 Prettier 格式化所有文件中的代码
1- First you can install the prettier code extension in your idea(Webstorm or vs code) https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode "for the vscode" 1- 首先你可以在你的想法中安装更漂亮的代码扩展(Webstorm 或 vs code) https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode “for the vscode”
2- Then install its package to your dependencies npm install --save-dev --save-exact prettier
https://prettier.io/docs/en/install.html 2- 然后将其 package 安装到您的依赖
npm install --save-dev --save-exact prettier
prettier https://prettier.io/docs/en/install.html
3- create .prettierrc
file and paste this code into it 3- 创建
.prettierrc
文件并将此代码粘贴到其中
{ "arrowParens": "always", "bracketSameLine": false, "bracketSpacing": true, "embeddedLanguageFormatting": "auto", "htmlWhitespaceSensitivity": "css", "insertPragma": false, "jsxSingleQuote": false, "printWidth": 80, "proseWrap": "preserve", "quoteProps": "as-needed", "requirePragma": false, "semi": true, "singleQuote": false, "tabWidth": 2, "trailingComma": "es5", "useTabs": false, "vueIndentScriptAndStyle": false }
4-Add 4-添加
"scripts": { ... "prettify": "prettier --write" }
script to your package.json
file脚本到您的
package.json
文件
Run npm run prettify
whenever you think your code is ugly运行
npm run prettify
每当你认为你的代码很丑时运行 prettify
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.