prettier/prettier
Prettier
Prettier is an opinionated code formatter that parses source code and reprints it from scratch to enforce a consistent, project-wide visual style. By transforming code into an abstract syntax tree and applying a recursive document printing process, it eliminates manual style debates and ensures that all source files adhere to a unified appearance.
The project is distinguished by its extensible, plugin-based architecture, which decouples language-specific parsing logic from the core engine. This modular design allows for uniform style enforcement across diverse programming languages and complex, mixed-content files where code is embedded within other languages. It also provides robust support for configuration-driven workflows, allowing teams to resolve hierarchical settings across directory trees and share standardized rule sets through reusable configuration packages.
Beyond its core formatting engine, the tool integrates into the entire development lifecycle. It offers programmatic APIs and command-line utilities for file discovery, change detection, and verification, alongside native support for editor-based formatting on save. The system also facilitates integration with linting workflows and continuous integration pipelines, enabling automated style enforcement through pre-commit hooks and status checks that ensure only properly formatted code enters version control.
Features
- Extensible Parsers - Decouples language-specific parsing logic from the core engine to allow support for multiple programming languages and file types.
- Parser Engines - A modular architecture that transforms various programming languages into abstract syntax trees to enable uniform style enforcement across different syntaxes.
- Custom Parser Implementations - The formatter supports converting source code into abstract syntax trees using custom logic to support unique file types or specialized language features.
- In-Place Formatters - The formatter applies formatting changes directly to source files by overwriting the original content to ensure consistent code style across the entire project.
- Browser Formatting - The formatter enables code string processing in browser environments by loading standalone libraries and language plugins via script tags, module imports, or worker scripts.
- Indentation Settings - The formatter allows specifying the number of spaces used for indentation to ensure consistent visual structure across all files in a project.
- Quote Style Configurations - The formatter allows specifying preferred quote types for strings and automatically adjusts them based on content to maintain clean and readable code.
- Semicolon Configuration Rules - The formatter provides control over the inclusion of semicolons at the end of statements to ensure consistent syntax and prevent errors.
- Pretty Printing Algorithms - Traverses the syntax tree to calculate optimal line breaks and indentation based on a target print width constraint.
- Formatting Constraints - The formatter allows defining a target line length guideline to balance code readability with the constraints of modern development environments and screen sizes.
- Formatting Rules - The formatter allows enabling or disabling trailing commas in multi-line structures to improve the readability of version control diffs and simplify code maintenance.
- Ignore Directives - Scans source files for specific comment markers to identify and protect code segments from being modified by the formatter.
- Code Formatters - Eliminating manual style debates by automatically reprinting source code to ensure consistent, project-wide visual standards.
- Formatting Verification - The formatter provides a verification mode that lists unformatted files and returns specific exit codes to signal success or failure within automated continuous integration pipelines.
- Source Code Formatters - The formatter provides a core API to format source code strings using specified parser options or by inferring the correct parser from file paths.
- Continuous Integration Quality Controls - Verifying code style within automated pipelines to ensure that only properly formatted code enters the version control history.
- Formatting and Linting Pipelines - The formatter supports piping output through both the formatter and linter fix commands to combine style enforcement with automated code correction in one step.
- Formatting Checkers - The formatter provides a programmatic method to verify whether a source code string is already formatted according to options, returning a boolean result for change detection.
- Formatting Diagnostics - The formatter supports reporting formatting discrepancies as linting issues by running the formatter directly within the linting process for immediate feedback.
- Multi-Language Formatters - Applying uniform formatting rules across mixed-language codebases, including embedded content, to maintain a consistent appearance throughout a project.
- Embedded Code Formatters - The formatter supports loading additional parser plugins to process code embedded within other languages, such as HTML strings inside JavaScript, ensuring consistent style across mixed content.
- Formatting Rule Definitions - The formatter allows defining consistent style guidelines using standard data formats to maintain a uniform appearance across all source files in a project.
- Configuration Resolution - The formatter provides a mechanism to resolve configuration settings for specific files by searching directory trees or parsing external configuration files.
- Configuration Cascade Resolutions - Merges settings from multiple hierarchical files and command-line overrides to determine the final formatting rules for any given file.
- Configuration Distribution Packages - The formatter supports distributing shared configuration packages through a registry to make standardized formatting rules available for installation in other projects.
- Configuration Overrides - The formatter allows applying custom formatting options to specific file subsets or directories to accommodate unique requirements within a larger project structure.
- Shareable Configurations - The formatter allows installing and referencing shared formatting packages in project files to adopt established team standards while allowing for local overrides.
- Abstract Syntax Tree Transformations - Parses source code into a tree structure, modifies the nodes according to style rules, and reprints the code.
- Extensible Plugin Frameworks - A framework that allows developers to register custom parsers and language support to handle specialized file types or experimental syntax features.
- Code Formatters - A tool that parses source code and reprints it from scratch to enforce a consistent, project-wide visual style.
- CI Formatting Checks - The formatter provides utilities for continuous integration pipelines to detect style violations in pull requests and commit necessary fixes automatically.
- Hierarchical Configuration Resolvers - A mechanism that resolves hierarchical settings to apply standardized formatting rules while allowing for project-specific overrides and local adjustments.
- Editor Integrations - Triggering automatic style fixes directly within text editors on save or via shortcuts to maintain clean code while writing.
- Cursor Position Mapping - The formatter supports mapping cursor positions from unformatted input to the corresponding location in the formatted output, maintaining the user's editing context during the transformation.
- Formatting Automations - A set of integrations that trigger automatic code styling during editing, commit, or continuous integration to eliminate manual formatting debates.
- Pre-commit Hooks - The formatter supports running formatting checks on staged files before committing to ensure that only clean and properly styled code enters version control.
- Editor Formatting Integrations - The formatter integrates into text editors and development environments to automatically format source code files according to project-defined style rules during the daily workflow.
- Vim Plugins - The formatter provides a dedicated Vim plugin that enables manual formatting commands and automatic formatting on file save events within the editor.
- Incremental Processing Caches - Stores hashes of file content and configuration to skip redundant processing and improve performance during large-scale formatting tasks.
- Language Support Definitions - The formatter allows registering new languages by specifying the name and the associated parser required to interpret the syntax correctly.
- Incremental Build Caches - The formatter stores formatting outcomes based on file metadata or content to skip processing unchanged files and accelerate performance during subsequent execution cycles.
- File Pattern Resolvers - The formatter identifies target files for processing by expanding directories and glob patterns while automatically skipping dependency folders and handling special character escaping.
- Team Configuration Standards - Sharing and enforcing unified formatting rules across multiple independent projects to ensure consistent standards across an entire organization.
- File Metadata Inspection - The formatter provides utilities to determine if a file should be ignored and to identify the appropriate parser based on file paths or URLs.
- Conflict Resolution Strategies - The formatter allows disabling conflicting linting rules in configuration files to ensure that formatting rules do not clash with the primary code formatter.