Home

Awesome

pretty-php: the opinionated code formatter for Visual Studio Code

This extension integrates the latest release of pretty-php with VS Code.

<p> <a href="https://packagist.org/packages/lkrms/pretty-php"><img src="https://poser.pugx.org/lkrms/pretty-php/v" alt="Latest Stable Version" /></a> <a href="https://packagist.org/packages/lkrms/pretty-php"><img src="https://poser.pugx.org/lkrms/pretty-php/license" alt="License" /></a> <a href="https://github.com/lkrms/pretty-php/actions"><img src="https://github.com/lkrms/pretty-php/actions/workflows/ci.yml/badge.svg" alt="CI Status" /></a> <a href="https://codecov.io/gh/lkrms/pretty-php"><img src="https://codecov.io/gh/lkrms/pretty-php/graph/badge.svg?token=W0KVZU718K" alt="Code Coverage" /></a> <a href="https://marketplace.visualstudio.com/items?itemName=lkrms.pretty-php"><img src="https://img.shields.io/visual-studio-marketplace/i/lkrms.pretty-php?label=Marketplace%20installs&color=%230066b8" alt="Visual Studio Marketplace install count" /></a> <a href="https://open-vsx.org/extension/lkrms/pretty-php"><img src="https://img.shields.io/open-vsx/dt/lkrms/pretty-php?label=Open%20VSX%20downloads&color=%23a60ee5" alt="Open VSX Registry download count" /></a> </p>

pretty-php is a fast, deterministic, minimally configurable code formatter for PHP.

By taking responsibility for the whitespace in your code, pretty-php makes it easier to focus on the content, providing time and mental energy savings that accrue over time.

Code formatted by pretty-php produces the smallest diffs possible and looks the same regardless of the project you're working on, eliminating visual dissonance and improving the speed and effectiveness of code review.

Aside from running it in VS Code, you can use pretty-php as a standalone tool, pair it with a linter, or add it to your CI workflows. Configuration is optional in each case.

If you have questions or feedback, I'd love to hear from you.

pretty-php isn't stable yet, so updates may introduce formatting changes that affect your code.

Features

Configuration

To configure pretty-php, you can use the extension's VS Code settings, or you can add a configuration file to your project.

VS Code settings are ignored if an applicable .prettyphp or prettyphp.json file is found.

To create a configuration file based on your current VS Code settings, use the extension's "Create .prettyphp or prettyphp.json" command. The bundled JSON schema for pretty-php configuration files makes them easy to edit in VS Code:

.prettyphp file IntelliSense

More information about configuring pretty-php is available here.

Examples

Minimal

{
  "src": ["."]
}

PSR-12 compliant

{
  "src": ["bin", "src", "tests/unit", "bootstrap.php"],
  "includeIfPhp": true,
  "psr12": true
}

Requirements

Pragmatism

pretty-php generally abides by its own rules ("previous formatting is ignored, and nothing in the original file other than whitespace is changed"), but exceptions are occasionally made and documented here.

License

MIT