-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Clean up Rector skip config on SimplifyRegexPatternRector and RemoveUnusedPromotedPropertyRector #8944
Merged
samsonasik
merged 2 commits into
codeigniter4:develop
from
samsonasik:chore-clean-rector-skip-regex
Jun 10, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the SimplifyRegexPatternRector rule. Because it may change the behavior.
In PHP,
[0-9]
and\d
(also[a-zA-Z]
and\w
) are not exactly the same when usingu
option.https://3v4l.org/N8sQ5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, it seems due to called on
$rectorConfig->rule()
, I removed it and revert its change on tests files 48f36efThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, the
u
usage already skipped on rector :) https://getrector.com/demo/00372e82-e4bc-451b-a7a2-495637f29d88There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kenjis do you want to re-enable
SimplifyRegexPatternRector
? as it already skipped onu
usage, see https://getrector.com/demo/00372e82-e4bc-451b-a7a2-495637f29d88There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want. Because these patterns have a bit different meanings.
An answer by ChatGPT:
In PHP's PCRE,
\d
and[0-9]
both match digits but are not exactly the same.Meaning:
\d
matches any digit character, including Unicode digits in some cases.[0-9]
matches only ASCII digits (0-9).Compatibility:
\d
can match non-ASCII digits if Unicode is enabled.[0-9]
always matches ASCII digits only.Performance:
[0-9]
can be slightly faster since it's a simple character class.Example
Conclusion
Use
[0-9]
for consistent matching of ASCII digits. Use\d
if you need to match broader digit sets, considering encoding and Unicode support.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, where does this code https://github.com/rectorphp/rector/blob/main/rules/CodeQuality/Rector/FuncCall/SimplifyRegexPatternRector.php check for the
u
option?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It only check delimiter, which limited to
~
,#
,/
viaRegexPatternDetector
, sou
in the last will always be skipped.