This article is a mirror article of machine translation, please click here to jump to the original article.

View: 2488|Reply: 0

[Other] Prettier is a front-end tool to beautify and format your code

[Copy link]
Posted on 7/28/2024 10:56:57 PM | | | |
Prettier is a powerful code formatter that supports:

  • JavaScript (including experimental features)
  • JSX
  • Angular
  • Vue
  • Flow
  • TypeScript
  • CSS, Less, and SCSS
  • HTML
  • Ember/Handlebars
  • JSON
  • GraphQL
  • Markdown, including GFM and MDX v1
  • YAML


Features: Prettier can be run on save in editor, in pre-commit hooks, or in a CI environment to ensure your codebase has a consistent style without the need for developers to post critical comments in code reviews anymore!

Documentation:The hyperlink login is visible.
GitHub address:The hyperlink login is visible.

Install prettier in your Node project using the npm command, which is as follows:

Create two new files in the project root:

.prettierignore: Ignored files or folders, meaning that those contents are not allowed to be formatted by the prettier. Reference:The hyperlink login is visible.
.prettierrc: A configuration file, a file written in JSON or YAML. Reference:The hyperlink login is visible.



In this article, taking an Angular 18 project as an example, two new file configurations are created in the project directory as follows.

.prettierignore reads:

.prettierrc reads:

Add the following configuration to the scripts under the package.json file:

Test formatting the code with the following command:

The effect is as follows:



(End)





Previous:[Practice] Use Dapper to operate SQLite databases
Next:Angular 18 series (twenty) environment variables are used by Environments
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com