Skip to content

indentation: a comment at the level of the body before } catch / } else stays with the body - #10

Closed
kukulich wants to merge 23 commits into
dg:masterfrom
slevomat:indentation
Closed

kukulich wants to merge 23 commits into
dg:masterfrom
slevomat:indentation

Conversation

@kukulich

Copy link
Copy Markdown
Contributor
  • bug fix: yes
  • BC break no

indentation.unit moved every comment on a line of its own above } followed by else, elseif, catch, finally or the while of a do to the level of the brace. It treated each such comment as the heading of the next branch. That breaks common code where the comment is the last line of the branch the brace closes:

try {
    $transaction->commit();
} catch (UniqueConstraintViolationException $e) {
    $transaction->rollback($e);
    // OK
} catch (Throwable $e) {

became

    $transaction->rollback($e);
// OK
} catch (Throwable $e) {

Change

IndentationPlan keeps the comments above a continuing brace at the level of the content when every one of them is written exactly there. Every other case works as before:

• a comment written at the level of the brace still heads the next branch,
• a comment at another level, such as one level too deep, is still moved to the level of the brace,
• comments at both levels each keep their own (hasCommentsAtTwoLevels).

dg and others added 23 commits November 15, 2026 21:21
A sample of UpgradingTester reports first, a risky fix by name runs in workers over two files, processCode writes
nothing, the resolution of names is in the array of the resolved configuration, the lexicon finds what breaks it, and
the meta-tests over the rules and the corpus fail where they find nothing to check. An assertion names the value it
expects: the messages of the configuration errors written out, the skeleton of a report of an empty scope, the values
of every decision explained, the standard init chooses, a member access found with its class, name and declaration.
No assertion repeats a signature, the test's own data or another test: the defaults of Config give way to the plugin
set apart in use, PhpDoc is tested for the tree of its own every parse gives, and the duplicates are gone.

2667d7cd-0a12-4f0d-b9b9-8d5d0199362e
…R and turns off

2667d7cd-0a12-4f0d-b9b9-8d5d0199362e
…looping rule being only one of the causes

40bb0a12-ee5e-4b02-af5a-8b38e807effb
…ps in there too

IndentationPlan takes Indentation::opensMatchArm() of PhpSyntax 1.0.1 for its own copy.
The line a fixer breaks before an operator in the condition of an arm got the level of the
arm from infer() and read as the next one, wherever binaryOperator left the line alone.

fe4be4e9-648f-4383-82eb-6fbb875bd83a
A tree with millions of them no longer runs out of memory.

`fix` and `check` over 1.8 million violations held every one of them to the end of the run, about 1.5 GB in the parent,
only to count them; the limit of 512 MB the program sets ends such a run sooner. A reporter still sees each file whole
in `reportFile()`, and what a run keeps of it is `ViolationTally`. The baseline and the probes need
the violations one by one, so they take them through `CollectingReporter`.

b0961ab5-dcf4-44a9-a919-74d28c9f3060
…uires

In the style the project keeps.

dresscode upgrade today lays the set deprecations, with --modernize also modernizations, over the presets the
configuration uses and beneath its own decisions and overrides, so that what the project keeps stays kept, lets in the
plugins of the packages of upgrading data, adds the types of the code and fixes. Without a configuration file it takes
the scope init would write and no style. With one it keeps the scope, the target, the types, fixRisky, the baseline and
the maps, and of the style only the decisions the code keeps: a check without the types and the sets runs first, every
decision it finds violated anywhere is left out, and the run is narrowed by only to the rest, the sets and the packages
whose data reach the project, which a worker gets through --only. It takes --only, --fix-risky and --ask-risky. The
upgrade goes to the lowest versions of PHP and of the libraries the project allows; the console says which libraries it
takes, which packages are installed newer than that, whose declarations then say nothing of what it deprecates, advising
composer update --prefer-lowest, and, where it rewrote a file, to run it again. The files a generator wrote are left out,
and the console says how many.
…alled beside DressCode

A package of upgrading data says which packages it is about under extra.dresscode.packages, and
UpgradingTester::collectPackageProblems() refuses a list that is not exactly the packages its upgrading files are about.
upgrade today learns of the packages from Packagist, asked once a day and remembered in the cache directory, for now of
the vendor dresscode alone, and PackageDiscovery finds those installed beside DressCode by their type dresscode-plugin,
not only those of the project. A project requiring one of their libraries itself gets a missing package installed
first, through Upgrade\Composer: composer require into the installation of DressCode, or require --dev into the project
where its lock holds DressCode, in a terminal after asking and without one only with --yes, otherwise it refuses with
the command to run. The command then starts again in a new process, as the program of this package, whose autoloader
knows the installed packages and the plugins they bring.
Layer names the library, the section and the version `from` says its fixes are right from, and a rule reporting an
entry passes it on to Violation::$source, which the format json writes as `source`; ForbiddenSymbolsRule and
ForbiddenMembersRule tell an entry of a package by it, and an entry of an attribute map names its origin as
MemberMapEntry does. A package of upgrading data named in only stands for the requirement laying its data too.
A string naming a class the maps rename or forbid and a place reached by a computed name, which an upgrade cannot see.

UnseenReferencesRule reports them under upgrading.unseen.* with the word `reported` and fixes nothing.
…nging nothing

Upgrade\Estimator measures it by one check over the sets of the upgrade and the upgrading data, in workers, the targets of
the command line, PHP and packages, laid over those of the configuration before the data are cut, so that the sections of
versions the project has not moved to yet count as reached, and the names resolved for certain where the configuration
says nothing of them. Every place is told by its topic, the library of its entry or its decision, by the bridge or the
jump, and by what a run can do about it; the estimate goes topic by topic with what works today and what after the raise,
as text or as a JSON document. It counts what an upgrade cannot see (BlindSpots): what UnseenReferencesRule reports, the
files no rule reads by their extension and the generated files it leaves out. It names the package of upgrading data a
library of the project has and DressCode lacks; --offline takes the catalogue of Packagist as the cache remembers it.

The estimate says that it changed nothing, who fixes each finding, DressCode or the project, what upgrade today can
rewrite right now and, under Rules for, how far the data reach.
…uld move

What of the lock refuses each target, and which packages raising the constraints would move across a major version.

The lock is asked as composer why-not --locked answers offline, the moves as the dry run of composer require says, which
--offline leaves out.
… for the team to edit

The steps are what a human has to make way for a target, the bridge, the raise of Composer, the jump, the cleanup, the
modernizations left out and, for an application, the update to the newest versions the constraints allow, written into
dresscode-upgrade.neon with the commands of the tests, each writing a JUnit report; a library, told by its type and its
lock, asked about in a terminal, or named by --library and --no-library, widens its constraints to the targets instead
and its plan is the bridge alone. The estimate ends with the command that orders it into steps.
…m back

upgrade abort takes back what an unfinished run changed.

A run makes them topic by topic in the style the code keeps (Upgrade\PlanRunner), a step whose tests newly fail going back
byte for byte, and tells where it stopped. Whether a step is done is read from the code and the lock alone, so a run goes
on from a working tree a team committed, squashed or rebased. It waits at a step of Composer with the command to run,
runs the whole suite after the jump and the last step, and warns of a working tree with changes of its own. A step
resolves the names with what the namespaces of the scope declare, as the estimate does. What a run keeps lies in the
directory of the git repository of the project (Upgrade\RunState), from which upgrade abort restores the files of an
interrupted step. A run is written as text or as a JSON document with how far it got, the estimate it opens with not
saying that nothing was changed.
…w process

It shows what the update changes first, and goes on with the jump in the new process.

In a terminal after asking or with --yes. A raise no fix follows is tested after it all the same, and upgrade abort
restores the composer.json and the lock a raise changed too.
A dresscode:ignore with its reason confirms one.
… human

In the code as it stands, and the suppressions about an upgrade giving no reason, exiting with 1 where one is left. Until the raise of the plan is made, the tasks of the steps after it do not show, and the last line and `due` of the JSON name the step they wait for. A run that leaves more than twenty tasks counts them by topic and names this command.
… the workers included

`--profile <file>` writes as JSON where the time of a run went, in nanoseconds: the phases (the start of the process,
the start of the container of PHPStan or of a derived one and its scopes, the parse, the passes, the gaps, the print,
the cycle collection, the run as a whole), every rule by the time of its callbacks, how often they ran and how often
they changed the tree, every gap rule by the time of its claims, every file with its size, rounds and passes, and the
peak memory of every process. A worker measures its own files and hands that over with every result and the parent
adds it up, so the totals do not depend on the number of workers. A run with the option leaves the result cache out,
a file served from the cache having nothing to measure.

It says where the time of a run goes, not only how much of it: a comparison of two revisions then names the rule or
the claim that moved. Without the option the engine only asks whether there is a profiler, and wraps a claim in
a measurement only when there is one.
dg pushed a commit that referenced this pull request Nov 23, 2026
@dg
dg force-pushed the master branch 2 times, most recently from 040900e to 0410f1d Compare November 23, 2026 15:48
@dg

dg commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Hi Jaroslav, thank you! This is a real bug, and a nasty one: the comment ends up looking like the heading of the next branch, so the fix quietly changes what the code tells the reader.

It's merged and released in 1.4.1, with one change I'd like you to look at.

hasCommentsOnlyAt() compared the indentation of the comment as written with the indentation the body is going to get. The two match only when the file is already indented by the style. On the first run over a project, where the indentation is fixed too (4 spaces to tabs, say), the comment still moved to the level of the brace:

} catch (UniqueConstraintViolationException $e) {
    $transaction->rollback($e);
    // OK
} catch (Throwable $e) {

with indentation.unit: tab still became

	$transaction->rollback($e);
// OK
} catch (Throwable $e) {

So the check now compares widths instead of strings: a comment written deeper than the brace is placed ends the branch the brace closes, whatever unit the file uses, and one written at the level of the brace or above it still heads the next branch.

The consequence is that a comment written too deep stays with the body too, instead of moving to the brace. That changed the two cases at the top of comments-before-continuation and one line of statement-basic. I think it's right, since a comment written deeper than the brace can hardly be the heading of the branch after it, but tell me if you see a case where it isn't. There's also a new fixture, comments-before-continuation-spaces, with code written in spaces, and two cases where the brace itself is written at the wrong level, which is why the comment is compared with where the brace is placed rather than where it is written.

Does it work for the code you ran into this on?

@dg dg closed this Nov 23, 2026
@kukulich

Copy link
Copy Markdown
Contributor Author

Thank you, the fix still works for us 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants