Notable changes to this extension and to pretty-php itself are documented in this file.
It is generated from the GitHub release notes of both projects by salient/changelog. The format is based on Keep a Changelog.
v0.4.72 - 2024-09-18
- Report version information unless
-qq
is given - Refactor for clarity and consistency
- Improve user documentation
v0.4.71 - 2024-09-03
- Sort imports by name when
--preset=symfony
is used - Include statements terminated by close tags (
?>
) when sorting imports
-
Fix issue where sorting imports by name produces unexpected results when aliases are used, e.g.
<?php // Before fix use Doctrine\DBAL\Driver\Connection as ConnectionInterface; use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware; use Doctrine\DBAL\Driver as DriverInterface; // After fix use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver\Connection as ConnectionInterface; use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware;
v0.4.70 - 2024-08-31
-
Fix issue where, in some contexts,
++
and--
operators are formatted incorrectly when they modify anything other than a plain variable, e.g.<?php // Before fix $this->Counter ++ ? ',' : ''; // After fix $this->Counter++ ? ',' : '';
v0.4.69 - 2024-08-27
- Add
files.exclude
setting
- Improve performance
- Fix issue where close brace in
function &() {};
is parsed as a statement terminator, causing incorrect "empty statement" reports
v0.4.68 - 2024-08-24
- Add support for new
T_PROPERTY_C
token in PHP 8.4
- Don't add blank lines after, or normalise blank lines between,
global
orstatic
variable declarations - Fix issue where property declarations like
static int|null $property
are not formatted correctly - Improve performance
- Fix
pretty-php
man page syntax issues
v0.4.67 - 2024-08-16
- Improve performance and reduce memory consumption
- Improve Symfony preset
- Don't collapse empty declaration bodies
- Don't collapse
<?php declare(...
to one line - Add a blank line between
<?php
and subsequent declarations
- Fix issue where method chains are not always detected
- Fix
AlignChains
issue where method chains with one object operator are not aligned consistently
v0.4.66 - 2024-08-08
- In addition to
@inheritDoc
, never collapse one-line DocBlocks with one of the following tags, with or without a@phan-
,@psalm-
, or@phpstan-
prefix:@api
,@internal
@method
,@property
,@property-read
,@property-write
@param
,@return
,@throws
- Update dependencies
- Fix issue where a non-declaration token may be taken as the first token of a subsequent declaration if its sibling is a declaration token, e.g. the opening brace in
else { } case 6:
- This issue surfaced during refactoring and is not known to have affected
pretty-php
's output
- This issue surfaced during refactoring and is not known to have affected
- Fail with an exception if invalid or non-unique token constants are defined by other libraries
- Only use trusted polyfills on PHP 7.4
v0.4.65 - 2024-06-13
-
Improve CLI robustness, consistency and ergonomics
Changes include but are not limited to:
- Don't report syntax errors or non-critical code problems until formatting is complete
- Print a summary that includes resource usage when
--diff
or--check
are given - Report location of invalid syntax when formatting fails due to a syntax error
- Send messages to
STDERR
only, even when formatted code is not being written toSTDOUT
- Don't hide progress updates while
--diff
output is rendering - Remove superfluous
/./
segments from input paths when a directory with a configuration file is passed topretty-php
- Don't index input directories unnecessarily when
--print-config
is given
- Fix string normalisation issue where some codepoints are escaped unnecessarily, e.g.
U+FE19
v0.4.64 - 2024-05-13
- Don't ignore
--tight
when a configuration file or preset is applied - Collapse DocBlocks above standalone declarations if they were originally collapsed
- Do not collapse DocBlocks that contain only
@inheritDoc
- Maintain the same gap between one-line declarations before and after any multi-line declarations of the same type
- Don't allow multi-line properties or constants to maintain tight spacing
This reverts a change in v0.4.63 that helped prevent unintended propagation of loose spacing. Other improvements have addressed this issue, and allowing multi-line declarations to run together makes code less readable, so
pretty-php
's previous behaviour has been restored.
- Fix issue where declaration DocBlocks are not always collapsed correctly
v0.4.63 - 2024-05-10
- Add
pretty-php.formatting.tightDeclarationSpacing
setting - Add
--tight
option to remove blank lines between declarations where possible
- Rewrite declaration spacing to improve consistency and reduce diff size
- Allow subsequent groups of declarations to use "loose" and "tight" spacing alternately, i.e. do not simply propagate loose spacing from its first appearance onwards
- Allow properties and constants with multi-line values to maintain "tight" spacing
- Do not propagate "loose" spacing triggered by comments other than DocBlocks to subsequent declarations of the same type
- Preserve blank lines between declarations with mutually exclusive modifiers, e.g. between a group of
public
properties and a group ofprotected
andprivate
properties, but not betweenpublic
properties and a group ofpublic
andprotected
properties
- Fix issue where a blank line is not always added between declarations and subsequent code
- Fix declaration spacing issues with
function &()
constructs and nested declarations
v0.4.62 - 2024-04-30
- Fix "supplied resource is not a valid stream resource" regression
v0.4.61 - 2024-04-30
- Apply unconditional symmetrical whitespace to brackets
- Fix issue where
pretty-php
sometimes fails with a "Process is not running" exception
v0.4.60 - 2024-04-09
- Fix failure to recognise functions with return type
array
,callable
orstatic
- Fix issue where
static
variable declaration DocBlocks are not collapsed in functions with any of these return types
v0.4.59 - 2024-04-09
- Fix regression where horizontal whitespace is not applied to bitwise operators in switch
case
statements
v0.4.58 - 2024-04-09
- Fix issue where DocBlocks and blank lines are not collapsed as expected
v0.4.57 - 2024-04-09
- Detect indentation of input files for more accurate tab expansion
-
Improve CLI option validation and error messages
-
Treat
case
statements in enumerations as declarations for more consistent vertical whitespace and DocBlock handling -
Always collapse one-line DocBlocks before
global
andstatic
variable declarations -
Collapse and ignore one-line DocBlocks with a PHPDoc tag when applying vertical whitespace to consecutive one-line declarations
Before (DocBlock triggers vertical expansion):
<?php class Foo { public int $Bar; public string $Qux; /** * @var string[] */ public array $Quux = []; }
After (DocBlock is collapsed if there are no blank lines between property declarations):
<?php class Foo { public int $Bar; public string $Qux; /** @var string[] */ public array $Quux = []; }
-
Improve DocBlock normalisation when leading asterisks are missing
Input:
<?php /** * Comment * @api */ /* * List: * Item 1 * Item 2 */
Previous output:
<?php /** * * Comment * * * @api */ /* * List: * Item 1 * Item 2 */
Current output:
<?php /** * Comment * * @api */ /* * List: * * Item 1 * * Item 2 */
- Fix issue where braces with a nested
match
expression may be incorrectly parsed as a complete statement
v0.4.56 - 2024-03-11
- Add "pretty-php.formatting.operatorPlacement" setting
- Move comments if necessary for correct placement of adjacent delimiters and operators
- Normalise casts to their canonical form (e.g.
( DOUBLE ) $var
->(float) $var
)
- Refactor for clarity, speed and to reduce memory consumption
- Improve underlying API, incl. removal of unused methods and creation of a standalone
Parser
class - Update dependencies
- Fix issue where an untrusted
PhpToken
polyfill may be extended from theToken
class on PHP 7.4 - Fix issue where
--operators-first
and--operators-last
have no effect - Fix issue where hanging indentation is not always applied when
--operators-first
is given
v0.4.55 - 2024-02-27
- Update dependencies
v0.4.54 - 2024-02-08
- Don't insert space between
exit
/die
and subsequent parentheses (#99) - Move assignment and comparison operators to the start of the line when
--operators-first
is given - Allow
--output
to be given when reading from standard input
- Fix issue where enum comments are indented like switch comments (#97)
v0.4.53 - 2024-02-02
- Suppress blank lines between
use
,use function
anduse constant
groups whensort-imports
is disabled
- Fix issue where
--no-sort-imports
fails with "--sort-imports-by and --no-sort-imports/--disable=sort-imports cannot both be given"
v0.4.52 - 2024-01-29
- Allow
--print-config
to be combined with--config
without losing input files given on the command line
- Fix "file not found" exception when processing configuration files in directories other than the current working directory
v0.4.51 - 2024-01-28
- Update dependencies to work around "Private methods cannot be final as they are never overridden by other classes" bug in PHP 8.3.2
v0.4.50 - 2024-01-21
pretty-php for Visual Studio Code v0.4.50 was not released
- Copy build tools to the repository to fix downstream packaging issues
v0.4.49 - 2024-01-21
- Add another
--quiet
level so a summary of changes can be printed without reporting every file replaced - Add colour to unified
--diff
output when the standard output is a TTY
- Escape non-ASCII characters with Unicode's "blank" property
- Improve validation of options loaded from configuration files
- Improve
--debug
output - Add
--log-progress
so--debug
need not be combined with--verbose
to generate progress-log files
- Fix bugs related to empty directories and configuration files, e.g. where
pretty-php
falls backs to reading fromSTDIN
when directories given on the command line yield no files to format
v0.4.48 - 2024-01-11
-
Add "pretty-php.formatting.simplifyNumbers" setting
-
Normalise integers and floats
Before:
<?php $decimal = [0, 1234567, 1_2_3, 12_34_56_7]; $hex = [0x1, 0x000b, 0xfe0, 0X00_CA_FE_F0_0D]; $octal = [00, 000_600, 0o755, 0O411]; $binary = [0b1, 0b0011, 0B101]; $float = [.14, 3., 03.00, 00.1400, 06.71E+083, 671.21e-4];
After:
<?php $decimal = [0, 1234567, 123, 1_234_567]; $hex = [0x01, 0x0B, 0x0FE0, 0xCAFE_F00D]; $octal = [0, 0600, 0755, 0411]; $binary = [0b01, 0b11, 0b0101]; $float = [0.14, 3.0, 3.0, 0.14, 6.71e83, 6.7121e-2];
-
Add
--no-simplify-numbers
option -
Sign
pretty-php.phar
releases for improved PHIVE support
- Fix regression in v0.4.47 where some Unicode sequences are escaped incorrectly, producing output like
"🧑\u{200D}🚒"
instead of'🧑🚒'
- Fix issue where strings containing sequences like
"\0002"
(NUL
followed by"2"
) are incorrectly normalised to"\02"
(equivalent to"\x02"
) - Fix output validation issue where all tokens are truncated for comparison, not just comments
v0.4.47 - 2024-01-08
- Use
\x{####}
to escape UTF-8 characters with the UnicodeDefault_Ignorable_Code_Point
property to improve code readability when working with invisible sequences, e.g. Unicode byte order marks
- Fix issue where escaped carriage returns (
"\r"
) are not preserved in multiline strings - Fix issue where strings with invalid UTF-8 sequences trigger an exception
v0.4.46 - 2023-12-29
-
Remove
align-lists
from thelaravel
preset -
Don't force newlines between boolean operators and negated expressions
Before:
<?php foo(bar() && qux() && quux() && !( quuux() || quuuux() ));
After:
<?php foo(bar() && qux() && quux() && !( quuux() || quuuux() ));
- Fix
sort-imports
issue where traits inserted into enums are sorted in error
v0.4.45 - 2023-12-22
- Add "Create .prettyphp or prettyphp.json" command
- Add "pretty-php.formatting.moveComments" setting
- Fix regression where disabled rules are ignored in strict PSR-12 mode
v0.4.44 - 2023-12-21
pretty-php for Visual Studio Code v0.4.44 was not released
-
Propagate line breaks after logical and bitwise operators to others of equal or lower precedence in the same statement
<?php // Input foo(bar() || baz() || qux() && quux() || quuux()); // Output foo(bar() || baz() || qux() && quux() || quuux());
-
Place comments with subsequent delimiters after the delimiters, demoting DocBlocks to standard C-style comments as a precaution
Input:
<?php [ // comment 0 => 'foo' ,1 => 'bar' // comment ,2 => 'baz' ]; [ /** DocBlock */ 0 => 'foo' ,1 => 'bar' /** invalid DocBlock */ ,2 => 'baz' ];
Previous output:
<?php [ // comment 0 => 'foo', 1 => 'bar' // comment , 2 => 'baz' ]; [ /** DocBlock */ 0 => 'foo', 1 => 'bar' /** invalid DocBlock */, 2 => 'baz' ];
Current output:
<?php [ // comment 0 => 'foo', 1 => 'bar', // comment 2 => 'baz' ]; [ /** DocBlock */ 0 => 'foo', 1 => 'bar', /* invalid DocBlock */ 2 => 'baz' ];
-
Preserve newlines before
??=
, not after -
Do not keep
<?php...?>
blocks on one line if they contain more than one statement -
Improve indentation and alignment heuristics when HTML has embedded PHP
-
Stop looking for a configuration file when a
.svn
directory is found (.git
and.hg
directories already had this effect) -
Rework exit codes for more granular feedback
-
Update usage information and JSON schema
- Fix issue where output is written to standard output when an explicit
--output
file is given - Don't print "Formatting 1 of 1: php://stdin" when reading TTY input
v0.4.43 - 2023-11-09
- Always move doc comments (
/**
...*/
) to the next line - Don't add blank lines before multi-line doc comments or their C-style counterparts if they appear mid-statement
- Collapse doc comments with one line of content to a single line (unless they appear to describe a file or are pinned to a declaration)
- Remove empty doc comments
v0.4.42 - 2023-10-26
- Add (experimental) support for PHP 8.3
-
Fix issue where
CompileError
exceptions thrown by the PHP 8.3 tokenizer are not caught -
Fix ternary alignment issue when
??
appears in the first expressionBefore:
<?php $foo = $bar ? $qux[$i] ?? $fallback : $quux;
After:
<?php $foo = $bar ? $qux[$i] ?? $fallback : $quux;
-
Fix issue where labels after close braces are not correctly identified
Before:
<?php if ($foo) { goto bar; } bar: qux();
After:
<?php if ($foo) { goto bar; } bar: qux();
v0.4.41 - 2023-10-20
- Link to
pretty-php
usage information from the "Formatter Arguments" description - Review files excluded by default when running from the command line
- The default regex is now case sensitive:
/\/(\.git|\.hg|\.svn|_?build|dist|vendor)\/$/
- Files in
**/tests*/
and**/var/
are no longer excluded by default
- The default regex is now case sensitive:
- Remove "Honour Configuration Files" setting (configuration files are always honoured)
- Add experimental
drupal
preset (available via--preset drupal
)
-
Fix issue where indentation is incorrect when arguments to
new static(...
break over multiple lines -
Fix same issue with
isset()
listsBefore:
<?php isset($a, $b);
After:
<?php isset($a, $b);
v0.4.40 - 2023-10-19
-
Fix issue where XML files are incorrectly identified as PHP files
-
Fix issue where ternary operators are not always identified correctly
Before:
<?php $filter = $exclude ? function ($value, $key, $iterator) use ($exclude) : bool { return (bool) preg_match($exclude, $key); } : null;
After:
<?php $filter = $exclude ? function ($value, $key, $iterator) use ($exclude): bool { return (bool) preg_match($exclude, $key); } : null;
v0.4.39 - 2023-10-17
- Suppress a level of hanging indentation in lists with one item
- Fix regression where hanging indentation isn't always applied after assignment operators
- Fix bug where tokens adjacent to brackets that enclose one token on its own line are indented incorrectly
v0.4.38 - 2023-10-16
- Add code samples to the descriptions of more settings
- Treat null coalescing operators (
??
) the same as ternary operators (?:
) for hanging indentation and alignment purposes - Improve robustness of declaration type matching
- Fix regression in hanging indentation where some expressions are indented unnecessarily
- Fix issue where output may not be idempotent in strict PSR-12 mode when comments appear after closing braces in the input
v0.4.37 - 2023-10-13
-
Improve hanging indentation heuristics
Before:
<?php $a = $b . $c . $d;
After:
<?php $a = $b . $c . $d;
- Fix issue where newlines between arrow functions and bodies are not always preserved
v0.4.36 - 2023-10-10
- Fix "Call to a member function declarationParts() on bool" exception reported in #60
v0.4.35 - 2023-10-09
-
Always preserve blank lines between statements (even when
--ignore-newlines
is given) -
Suppress line breaks between
,
and=>
in match expressions, e.g.<?php match ($a) { 0, => false, };
-
Suppress blank lines before and after comments in intra-statement contexts, e.g.
<?php class Foo // { public function bar() {} }
- Fix issue where, in strict PSR-12 mode, the
=>
operator after an arrow function that returns by reference is not moved to the next line
v0.4.34 - 2023-10-07
pretty-php for Visual Studio Code v0.4.34 was not released
- Fix issue where
vendor/bin/pretty-php
fails
v0.4.33 - 2023-10-04
- Always move docblocks to the start of their own line to reflect their association with subsequent structural elements
- Treat C-style comments that break over multiple lines as docblocks for vertical spacing purposes
- Multi-line C-style comments aren't "pinned" to subsequent code like docblocks are, but they are handled consistently otherwise
- Improve inline comment handling when collapsing hanging indentation
- Fix issue where arrays created with square brackets are not treated as lists in some contexts
- Fix inconsistent formatting of anonymous functions that return values by reference
v0.4.32 - 2023-10-03
- In strict PSR-12 mode, add whitespace between exception delimiters in
catch
blocks - Always add a newline before the first object operator in a multi-line method chain (unless
align-chains
is enabled and strict PSR-12 mode is disabled) - Format
for
loop expressions as list items whenalign-lists
is enabled - If an expression in a
for
loop breaks over multiple lines, add a newline after each comma-delimited expression, and a blank line between each semicolon-delimited expression - Suppress whitespace in empty
for
loop expressions
-
Fix DNF type formatting
Before:
<?php class Foo { public(Countable & ArrayAccess)|MyClass|string|null $Bar; }
After:
<?php class Foo { public (Countable&ArrayAccess)|MyClass|string|null $Bar; }
-
Fix issue where parameter lists are not recognised as lists when they belong to an anonymous function that returns by reference
-
Fix
align-lists
issue where adjacent declaration and control structure bodies are aligned with the preceding list item
v0.4.31 - 2023-09-29
- Add JSON schema for .prettyphp files
v0.4.30 - 2023-09-28
- Update dependencies and packaging
- An upstream issue where "-" could not be given as the only argument has been fixed
v0.4.29 - 2023-09-25
-
Convert shell-style comments (
#
) to C++-style comments (//
) -
Add a space between
//
and subsequent text -
Remove leading and trailing empty lines from PHP docblocks
-
Preserve indentation when normalising PHP docblocks
-
Improve heuristics so C-style comments (
/* ... */
) are normalised like PHP docblocks more consistently -
Don't reindent multiline comments beside code if they have text in column 1, e.g.
<?php foo(); /* this comment starts after column 1 but has text in column 1 */
v0.4.28 - 2023-09-18
-
Revert change to logical operator placement in v0.4.27
This change was intended to improve the readability of PSR-12-compliant control structure expressions, but output was inconsistent and there were unforeseen side-effects, so v0.4.26 behaviour has been restored. Apologies for the disruption!
-
In strict PSR-12 mode, move comments beside the closing brace of classes, interfaces, etc. to the next line
-
Move multi-line docblocks beside code to their own line
-
When adding blank lines before statements, respect continuation of earlier comments
-
Remove blank lines between subsequent one-line
declare
statements -
For vertical spacing purposes, treat consecutive property declarations as the same declaration type, regardless of syntax (e.g. when
var
is mixed withprivate
)
-
Fix issue where blank lines are added after
<?php
when there are two or more subsequent declarations of the same type -
If subsequent declaration types are different, propagate spacing from earlier siblings of the same type to avoid output like the following (there should be a blank line between
class B
andclass C
):<?php class A { public function a() {} } class B {} class C {}
-
Add blank lines before comments that trigger vertical expansion of declarations, preventing output like:
<?php class A { public $foo; public $bar; // There should be a blank line above this public $baz; public $qux; }
v0.4.27 - 2023-09-16
- Report output from
pretty-php
to stderr in the output channel - Move logical operators to the start of the line in contexts where hanging indentation will not be applied
- Add
StrictExpressions
rule for PSR-12-compliant handling of multi-line control structure expressions
- Improve
PreserveLineBreaks
heuristics to fix an issue where leading operators remain at the end of a line when followed by!
on the next line
v0.4.26 - 2023-09-14
- Fix issue where backslashes in heredocs are escaped unnecessarily
- Fix additional escaping issues, e.g. in strings like
"\\\{$a}"
v0.4.25 - 2023-09-11
- Update setting descriptions
- Normalise constant parts of all strings--including heredocs and between backtick operators--not just single- and double-quoted constant strings
- Remove unnecessary backslash escapes
- Escape
"\x1b"
as"\e"
- Fix regression in v0.4.24 where unnecessary backslashes are added in some contexts (sorry!)
v0.4.24 - 2023-09-09
- Unescape leading tabs in strings when using tabs for indentation
- Remove
T_BAD_CHARACTER
tokens
v0.4.23 - 2023-09-06
- Improve performance by removing unnecessary type checking
v0.4.22 - 2023-08-31
-
Adjust preservation of line breaks and blank lines
- Don't preserve newlines after close braces that aren't structural (where "structural" essentially means "may enclose statements")
- Collapse blank lines between list items and in other expression contexts (e.g.
for
loop expressions), including before comments - If one expression in a
for
loop is at the start of a line, add a newline before the others
-
Don't sort
use <trait>
statementsChanging the order of traits inserted into a class changes the order its members are reported, so behaviour removed in v0.4.15 has been restored
-
When sorting imports, don't treat one-line comments as continuations if there is a change of type
-
If chained method calls would render as below, move the first call in the chain to the next line:
// Before $foxtrot->foo( // ) ->baz(); // After $foxtrot ->foo( // ) ->baz();
v0.4.21 - 2023-08-31
- Change default sort order of alias/import statements to depth-first
- To restore the previous behaviour, use
--sort-imports-by name
or set "Sort Imports By" to "name"
- To restore the previous behaviour, use
- When sorting by name, don't place grouped alias/import statements below ungrouped imports
- Collapse space after
;
infor
loops if the next expression is empty - Preserve newlines before and after attributes
- Add a newline before every parameter, not just annotated parameters, when splitting parameter lists to accommodate attributes
- Fix issue where blocks that start with an empty statement (e.g.
function () { ; // ...
) are not indented correctly - Fix issue where anonymous class declarations are not always recognised
- Fix issue where newlines are added after inline comments between control structure tokens, leading to unnecessary indentation
- Fix issue where arrow function alignment fails in strict PSR-12 mode
- Fix
align-lists
issue where list items appearing consecutively on the same line are not always aligned correctly
v0.4.20 - 2023-08-24
- Remove "Magic Commas" setting
- Rename "Align Assignments" setting to "Align Data"
- Downgrade Box to fix an issue where
pretty-php.phar
fails with an exception on Windows
v0.4.19 - 2023-08-11
pretty-php for Visual Studio Code v0.4.19 was not released
- Add
symfony
preset (CLI only)
- Make
magic-commas
rule mandatory and remove it from command line options - Rename
align-assignments
rule toalign-data
- Adopt Box for cleaner, leaner PHAR builds
- Remove upper limit on PHP version to allow running on PHP 8.3
- Suppress
E_COMPILE_WARNING
errors (they can't be caught or actioned, don't affect output and aren't user-friendly)
-
Fix issue where hanging indentation is not consistent within lists
e.g.
'e'
should be aligned with'g'
here:<?php $a = array('b' => array('c' => 'd', 'e' => 'f', 'g' => 'h'), 'i' => array(1, 2, 3), 'j' => array('k', 7 => 'l', 'm'));
v0.4.18 - 2023-08-07
- Add support for inline parameter attributes
- Suppress hanging indents in
match
expressions - Preserve blank lines between the arms of
match
expressions
- Fix header spacing issue caused by inconsistent handling of
?>
tags that double as statement terminators - Fix edge case where multi-line anonymous class interface lists are not indented
- Fix PHP 7.4 issue where
T_ATTRIBUTE_COMMENT
may not be the last token on the line
v0.4.17 - 2023-08-04
- Fix hanging indentation regression
v0.4.16 - 2023-08-04
- Add "Psr12" setting
- Write messages to an output channel instead of
console
- Preserve newline after
throw
- Add optional depth-first import sort order (available via
--sort-imports-by
) - Make heredoc indentation configurable via
--heredoc-indent
- Add
--operators-first
and--operators-last
flags (CLI only) - Apply strict PSR-12
<?php declare...
formatting and heredoc indentation when--psr12
is given (CLI only)
- Replace "Sort Imports" setting with "Sort Imports By"
- Replace "Indent Heredocs" setting with "Heredoc Indentation"
- Migrate previous values of replaced settings
- Don't apply hanging indentation in unambiguous single-expression contexts
- Improve comment formatting
- Normalise whitespace at the beginning and end of one-line C-style and docblock comments
- Reindent text in multi-line comments to maintain original alignment
- Expand leading tabs in comments to spaces (and unexpand leading spaces to tabs if using tabs for indentation)
- Only treat comments indented by at least one space (relative to code in the same context) as continuations of comments beside code
- Improve comment placement in
switch
structures
- Refactor
align-lists
- Improve consistency by removing complex eligibility checks and problematic enforcement of newlines between items
- Propagate alignment to adjacent code recursively and unconditionally, allowing structures like:
<?php [':', [$a, $b, $c], [$d, $e, $f], [$g, $h, $i]];
- Apply magic commas to
list
and other destructuring constructs, not just arrays and argument lists - Expand WordPress preset
- Optimize for improved performance (in a 200-file batch test, v0.4.16 is 17% faster than with v0.4.15)
- Remove
one-line-arguments
from available rules - Remove
--disable indent-heredocs
(replaced with--heredoc-indent none
)
- Detect more unary contexts
- Refactor block detection to fix alignment anomalies when PHP and markup are mixed
v0.4.15 - 2023-07-13
- Group alias/import statements by
use
,use function
,use const
for PSR-12 compliance (previous order wasuse
,use const
,use function
) - Sort trait imports
- Tighten the criteria for a DocBlock to follow a blank line
- Move every
->
in a multi-line method chain to a new line - In
align-chains
, collapse the first object operator after tokens with fewer characters than a soft tab - In
align-lists
, don't allow close bracket placement to be the only reason a list is not aligned, and refine the criteria for aligning lists with nested brackets - Rewrite the
align-assignments
rule- Align multiple tokens per line
- Vary context matching rules by token type, e.g. only align commas adjacent to comparable tokens over consecutive lines
- Apply spacing to the previous or following token as needed, e.g. right-align numeric columns in data arrays
- Allow aligned tokens to be separated by multiple lines when every inner line has a higher effective indentation level than the tokens
- Ignore series of alignable tokens that would otherwise be split and aligned separately due to a disruption (e.g. a comment, or nested code at a lower indentation level)
- Align statements in one-line
switch
cases (preserve-one-line
must also be enabled)
- Remove "preserve trailing spaces" option
- Don't report unnecessary parentheses
- Track and report output position to fix inaccurate problem report locations
v0.4.14 - 2023-07-05
- Remove "Preserve Trailing Spaces", "One Line Arguments" settings
- Add initial support for the WordPress code style via
--preset wordpress
(CLI only)
- Improve support for attributes when running on PHP 7.4
- Fix issue where
if
inelse if
is treated as a new statement
v0.4.13 - 2023-06-29
pretty-php for Visual Studio Code v0.4.13 was not released
- Remove Laravel-specific formatting rules (
--preset laravel
output is unchanged):space-after-fn
space-after-not
no-concat-spaces
-
Fix undesirable output when preserving newlines between brackets
Previously:
<?php $a = $b->c ($d);
Became:
$a = $b->c( $d );
And with
--preset laravel
, this:<?php function a($b) { c(); }
Became:
<?php function a($b ) { c(); }
-
Fix issue where indentation settings are not printed by
--print-config
v0.4.12 - 2023-06-22
- When a list of interfaces after
extends
orimplements
spans multiple lines, move every interface to its own line
- Shorten empty class and function bodies to
{}
and move them to the previous line - Improve formatting of anonymous classes and attributes
- Add a blank line between file-level docblocks and
declare
statements
- Many small bugs you probably hadn't noticed
v0.4.11 - 2023-06-16
- Improve handling of control structures where braced and unbraced bodies are combined and/or nested
- Fix possible exception when "Align Lists" and "Align Fn" are combined
v0.4.10 - 2023-06-15
pretty-php for Visual Studio Code v0.4.10 was not released
- Update dependencies
v0.4.9 - 2023-06-06
pretty-php for Visual Studio Code v0.4.9 was not released
- Fix issue where config files above the working directory are not found
- Fix issue where invalid or empty config files trigger an unrelated exception
v0.4.8 - 2023-05-25
- Improve formatting of chained method calls
- Ignore all but the last of any incompatible rules given on the command line
- Update
laravel
preset (CLI only)
- Fix issue where operators after
$object->{$property}
expressions are sometimes treated as unary operators - Fix issue where "Align Lists" adds newlines between method chain arguments
- Fix handling of one-line comments with a subsequent close bracket
- Add tests for idempotent output and fix issues subsequently detected in comment placement and "Align Fn"
v0.4.7 - 2023-05-23
- Add
--timers
and--fast
options topretty-php
(CLI only)
- Restore PHP 7.4 support, courtesy of upstream
PhpToken
polyfill - Normalise alias/import statements before sorting to fix inconsistent output between PHP 7.4 and PHP 8.0+ (grouped imports now appear after ungrouped ones)
v0.4.6 - 2023-05-18
- Update PrettyPHP to v0.4.6
v0.4.4 - 2023-05-16
- Peg the version of the extension to the bundled PrettyPHP version, e.g. this version comes with PrettyPHP v0.4.4
- Improve Windows support, including clearer feedback and instructions when PHP can't be found
- Remove the "Formatter Path" setting because versions other than the bundled version of PrettyPHP are likely to introduce compatibility issues
- Fix PHP 8.0 issue where PrettyPHP reports
Your Composer dependencies require a PHP version ">= 8.1.0"
(sorry!) - Fix regression where the "Format PHP without Preserving Newlines" command preserves newlines when a config file applicable to the file being formatted is found
v0.4.0 - 2023-04-27
- Add "Preserve Trailing Spaces", "Honour Configuration Files" settings
- Update PrettyPHP to v0.4.1
v0.3.5 - 2023-04-04
- Update PrettyPHP to v0.3.22
v0.3.4 - 2023-03-28
- Update documentation
v0.3.3 - 2023-03-27
-
Add settings:
- "Formatter Arguments"
- "Sort Imports"
- "Magic Commas"
- "Indent Heredocs"
- "Blank Before Return"
- "Strict Lists"
- "Align Chains"
- "Align Fn"
- "Align Lists"
- "Align Ternary Operators"
- Suppress error notification when syntax is invalid
- Rename "Blank Before Declaration" setting to "Declaration Spacing"
- Update PrettyPHP to v0.3.19
v0.3.2 - 2023-03-14
- Add "One Line Arguments" setting
- Update PrettyPHP to v0.3.17
v0.3.1 - 2023-03-07
- Add "Blank Before Declaration", "Align Comments" settings
- Update PrettyPHP to v0.3.13
v0.3.0 - 2023-02-24
- Add "Format PHP without Preserving Newlines" command
- Add "Simplify Strings", "Align Assignments", "Preserve One Line Statements" settings
- Require PHP 8+
- Update PrettyPHP to v0.3.6
v0.2.0 - 2023-02-06
- Update PrettyPHP to v0.2.0
v0.1.7 - 2023-01-27
- Update PrettyPHP to v0.1.10
v0.1.6 - 2023-01-25
- Add "Formatter Path" setting
- Update PrettyPHP to v0.1.8
- Report errors via VS Code notifications
v0.1.5 - 2023-01-23
- Add "PHP Path" setting
- Update PrettyPHP to v0.1.6
- Pass the active editor's indentation options to PrettyPHP
- Format code that uses PHP's short open tag (
<?
)
- Fix PHP startup errors appearing in formatted code
v0.1.4 - 2023-01-20
Initial release