drift icon indicating copy to clipboard operation
drift copied to clipboard

[Rector] Ordering

Open olivernybroe opened this issue 5 years ago • 4 comments

Let's create a new rector which orders the test alphabetically

The reason for using a new rector is so we can optionally enable/disable it and decouple it from the base rector which is about just refactoring to pest test cases, not making them nicer.

olivernybroe avatar May 28 '20 12:05 olivernybroe

I've been looking into this, and I can't work out if this is actually possible. This is what I've started with, however the FuncCall doesn't appear to have access to other functions in the same file. I was looking at this set for ideas, but that's all about re-ordering class nodes, etc. 🤔

owenvoke avatar Sep 09 '20 11:09 owenvoke

Hmm...

@TomasVotruba how do we create a rector for reordering function calls in a file? Normally I would take the parent node, but the parent node is the file itself and I can't find a node type for that. Any help would be highly appreciated :heart:

olivernybroe avatar Sep 10 '20 20:09 olivernybroe

Quick answer from phone: use Class_ and stmts.

Best practice: Parents are hard to change, as in real life ;), so better go with the higher node and change its children.

Also check for Order Rector rules in core. There might be some inspiration ☺️

Let me know if you need more.

TomasVotruba avatar Sep 10 '20 21:09 TomasVotruba

Does Class_ work when there isn't a class in the file? It's just function calls such as:

it('does test1')->skip();
it('does test2')->skip();

owenvoke avatar Sep 10 '20 21:09 owenvoke