Skip to content

Create rector for transforming Laravel validation rules to a prettier format#1914

Merged
TomasVotruba merged 11 commits intorectorphp:masterfrom
sashabeton:inline-validation-rules-to-array-definition-rector
Sep 17, 2019
Merged

Create rector for transforming Laravel validation rules to a prettier format#1914
TomasVotruba merged 11 commits intorectorphp:masterfrom
sashabeton:inline-validation-rules-to-array-definition-rector

Conversation

@sashabeton
Copy link
Copy Markdown
Contributor

#1766

This is the first simplest version that covers the most of situations, but it is not fully flexible.
Now it works, but it can be improved. I tried to implement some features, but I didn't succeed.

  1. Is there a way to include additional use statement instead of using full namespace? I mean I want to split \Illuminate\Validation\Rule::exists(...) into a use \Illuminate\Validation\Rule; statement and Rule::exists(...) statement.

  2. Is there a way to split each array element to the new line? All rules in one line don't look so beautiful.

@sashabeton sashabeton force-pushed the inline-validation-rules-to-array-definition-rector branch from ca36418 to e192c2f Compare August 28, 2019 15:16
@TomasVotruba
Copy link
Copy Markdown
Member

TomasVotruba commented Aug 29, 2019

Looks very robust, good job!

Looks at local $this-> methods, there are many helpers that you can leverage.

To both your points, this is job of coding standard tool, as they handle it better (AST sucks at coding standard by technology limits) and every project has different ruleset. Just see ecs.yaml in this project

@sashabeton
Copy link
Copy Markdown
Contributor Author

No ideas why isType() method is undefined.. This test passes locally
image

@TomasVotruba
Copy link
Copy Markdown
Member

Rebase on master, there were some method name change

@TomasVotruba
Copy link
Copy Markdown
Member

TomasVotruba commented Sep 10, 2019

I use this approach to update the forks: https://help.github.com/en/articles/syncing-a-fork

First it's a bit hard to understand, but then works pretty well 👍

@TomasVotruba
Copy link
Copy Markdown
Member

Could you rebase one more time?
It's ready then

@sashabeton
Copy link
Copy Markdown
Contributor Author

Thank you too much for help!

Do I need to do something more?

@TomasVotruba
Copy link
Copy Markdown
Member

CI passes, great 👍

Could you add 1-2 more test that would cover some other/skipped cases?

@sashabeton
Copy link
Copy Markdown
Contributor Author

I've created all cases that this rector can process, in future I'll try to expand its functionality and add other :)

@TomasVotruba TomasVotruba merged commit 2b00402 into rectorphp:master Sep 17, 2019
@TomasVotruba
Copy link
Copy Markdown
Member

Thank you for your contribution!

@sashabeton sashabeton deleted the inline-validation-rules-to-array-definition-rector branch September 20, 2019 11:42
TomasVotruba added a commit that referenced this pull request Mar 7, 2022
rectorphp/rector-src@72710eb Typo fix: ecs -> rector in ApplicationFileProcessor (#1914)
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