rector icon indicating copy to clipboard operation
rector copied to clipboard

RemovedAndAddedFilesCollector no longer seems to add files

Open jtojnar opened this issue 3 years ago • 3 comments

Bug Report

Subject Details
Rector version ≥0.13.1

With Rector 0.13.0 running a custom Rector rule form https://github.com/j0k3r/graby/pull/293 is able to add files using RemovedAndAddedFilesCollector. It stops creating the files after updating Rector to 0.13.1 or newer version, even though the rule still performs the code transformation.

I do not see anything suspicious in the changes: https://github.com/rectorphp/rector-src/compare/0.13.0...0.13.1.

Minimal PHP Code Causing Issue

https://github.com/jtojnar/repro/tree/73e3e1813f7ef5ff39484fbe50de13c3c2d13e4b/rector-7231

1 file with changes
===================

1) test.php:0

    ---------- begin diff ----------
@@ @@
 <?php

+use Test\Foo;
 function test() {
 	new Foo;
 }
    ----------- end diff -----------

Applied rules:
 * TestRector


                                                                                                                        
 [OK] 1 file has been changed by Rector                                                                                 
It works with Rector 0.13.0

https://github.com/jtojnar/repro/tree/43c2b8890704e3f27090cb9376ef6b391dbe3ed3/rector-7231

 ! [NOTE] File "/home/jtojnar/Projects/repro/rector-7231/test" was added                                                

1 file with changes
===================

1) test.php:0

    ---------- begin diff ----------
@@ @@
 <?php

+use Test\Foo;
 function test() {
 	new Foo;
 }
    ----------- end diff -----------

Applied rules:
 * TestRector


 ! [NOTE] 1 files were added                                                                                            

                                                                                                                        
 [OK] 2 files have been changed by Rector                                                                               

Expected Behaviour

New files should be created.

jtojnar avatar Jun 11 '22 21:06 jtojnar

Hi, this part of Rector is quite complex. We'd need a simple reproducer repository to be able to find the bug.

If this is still relevant, share a repository with failing Github action and we can re-open the issue and check it.

TomasVotruba avatar Jul 20 '22 12:07 TomasVotruba

I have updated the repository with latest Rector (0.13.9) and added CI (not sure what it adds, when there is a already composer lockfile). It is still an issue.

jtojnar avatar Jul 26 '22 13:07 jtojnar

I have updated the repository with latest Rector (0.13.9) and added CI (not sure what it adds, when there is a already composer lockfile). It is still an issue.

I don't know whether this suits you, but as a workaround, by disabling the parallel processing, you can make it work:

// rector.php
$rectorConfig->disableParallel();

kaczenski avatar Aug 12 '22 10:08 kaczenski

We'll need a reproducible test case here in Rector.

TomasVotruba avatar Nov 11 '22 13:11 TomasVotruba

@TomasVotruba Should I open a PR copying the example above as a failing integration test?

jtojnar avatar Nov 11 '22 15:11 jtojnar

@jtojnar That would be great 👍

TomasVotruba avatar Nov 11 '22 18:11 TomasVotruba

Okay, opened https://github.com/rectorphp/rector-src/pull/3058.

jtojnar avatar Nov 12 '22 19:11 jtojnar