Beautiful is a self-righteous code formatter. This is a great way to maintain a consistent code format for you and your team, and supports many different languages out of the box.
Beautiful is a self-righteous code formatter.
It supports many different ready-made syntaxes, including:
versusPlug-inYou can use it for Python, PHP, Swift, Ruby, Java, etc.
It is integrated with the most popular code editors including VS Code, Sublime Text, Atom, etc.
Prettier is very popular. As of February 2018, Prettier has been downloaded more than 3.5 million times.
The most important link you need to learn more about Prettier is
I recently learned Go, one of the best things about Go isgofmt, This is an official tool that can automatically set the code format according to common standards.
Around 95% of Go code looks exactly the same because this tool can be easily implemented, and because Go maintainers define the style for you, you are more likely to adapt to the standard without having to stick to your own style. Such as tabs and spaces, or where to put the opening parenthesis.
This sounds like a limitation, but it is actually very powerful. All Go code looks the same.
What's more beautiful is
gofmtFor the rest of the world.
It has very few options, andMost decisions have been made for youSo you can stop arguing about styles and trivial matters and focus on the code.
Difference from ESLint
ESLintIt is a lint, it is not only formatted, but also highlights some errors due to the static analysis of the code.
It is a valuable tool that can be used with Prettier.
ESLint also emphasizes formatting issues, but because it is much more configurable, everyone can use a different set of formatting rules. Beautiful things provide common ground for everyone.
Now you can customize some content, such as:
- Label width
- Use of single and double quotes
- Row number
- Use of trailing commas
And some others, but Prettier tries to keep the number of these customization items within a controllable range to avoid over customization.
If you use a supported editor, the best practice is to use Prettier directly from the editor and run the Prettier format every time you save.
For example, this is the Prettier extension for VS Code:https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
Suitable for beginners
If you think Prettier is only suitable for teams or professional users, then you will miss the value proposition of this tool.
Good style will develop good habits.
Formatting is a topic that beginners usually ignore, but having a clear and consistent formatting is the key to success as a new developer.
More devtools tutorials:
- Yoman Introduction
- Bower, browser package manager
- Introduction to front-end testing
- Use node-webkit to create desktop applications
- VS Code: Use language-specific settings
- Introduction to Webpack
- A short and concise guide to the Tower of Babel
- Yarn introduction
- Overview of Browser DevTools
- Use Prettier to format code
- Use ESLint to keep your code clean
- List of cool Chrome DevTools tips and tricks
- How to use Visual Studio Code
- Introduction to Electronics
- Package, simpler Webpack
- Emmet's HTML reference
- Configure VS Code
- Configure macOS command line
- How to disable ESLint rules
- How to open VS Code from the command line
- How to set up hot reinstallation on Electron