Prettier - Short Review

Coding Tools



Product Overview of Prettier



What is Prettier?

Prettier is an opinionated code formatter designed to enforce a consistent code style across a wide range of programming languages and frameworks. It aims to eliminate the need for manual code formatting and the associated discussions and disagreements within development teams.



Key Features and Functionality



Multi-Language Support

Prettier supports a diverse array of programming languages, including JavaScript, TypeScript, JSX, Angular, Vue, Flow, CSS, Less, SCSS, HTML, Ember/Handlebars, JSON, GraphQL, Markdown (including GFM and MDX v1), and YAML.



Automated Code Formatting

Prettier works by parsing the code, disregarding the original styling, and then re-printing the parsed Abstract Syntax Tree (AST) with its own formatting rules. This ensures that all outputted code conforms to a consistent style, taking into account maximum line length and wrapping code when necessary.



Integration with Editors

Prettier integrates seamlessly with most popular code editors such as Visual Studio Code, Sublime Text, WebStorm, Nova, and Espresso, among others. This integration allows developers to format their code automatically on save or with a simple keyboard shortcut.



Consistency and Usability

Prettier enforces a consistent code style, which helps in maintaining readability and reducing the time spent on code reviews. It follows the Principle of Least Astonishment, ensuring that the formatting is consistent and predictable. This consistency makes it easier for new team members to adapt to the project’s codebase.



Handling Comments and AST

Prettier handles comments by attaching them to the appropriate nodes in the AST and then printing them in the correct positions. This process ensures that comments are preserved and correctly formatted along with the code.



Plugins and Customization

While Prettier is opinionated and does not offer extensive configuration options, it does support plugins that allow developers to add new languages or formatting rules. This flexibility is achieved through the plugin API, which includes functions for handling comments, preprocessing, and embedding code.



Productivity and Efficiency

By automating the code formatting process, Prettier saves developers time and energy that would otherwise be spent on manual formatting. This allows teams to focus on more productive tasks, such as writing code and solving complex problems.



Key Quality Attributes

  • Usability: Prettier is designed to be easy and quick to use, ensuring that formatting code is a simple and straightforward process.
  • Modifiability: Although Prettier is not highly configurable, it is modifiable to support evolving changes in file types and syntax.
  • Consistency: Prettier ensures consistent formatting across the entire codebase, making it easier for developers to work with and maintain the code.

In summary, Prettier is a powerful tool that streamlines the development process by enforcing consistent code formatting, integrating with popular editors, and supporting a wide range of programming languages. Its automated formatting capabilities and focus on usability, modifiability, and consistency make it an invaluable asset for development teams.

Scroll to Top