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
feat: Introduce NumericLiteralSeparatorFixer
#6761
Conversation
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.
Can we have this fixer configured to add or remove the separator, according to the config?
Neither way is any standard that is good and the other is bad.
Agree with it. Let's do:
I will try how easy it would be to do the other way around. Is the position in the Fixer structure fine? Thought "basic" would match the most from what I saw. |
not sure if agree, to be honest ;) I would go YAGNI here. |
@keradus I would prefer to remove it, also I can imagine ignoring it, but I cannot imagine adding numeric literals automatically, how would you fix these automatically: const ONE_EURO_IN_CENTS = 1_00;
const THOUSAND_EUROS_IN_CENTS = 1_000_00;
const HUNDRED_THOUSAND = 100_000;
const ONE_MILLION = 1_000_000; |
@kubawerlos, in a first step, I remove the “maybe wrongly placed” underscores and then apply the formatting. So, that would become:
But I agree that some may prefer removing it or leaving as is. But as a first step, I want to make sure adding works as expected before removing. |
A. why to remove B. I see the value in having "add _ when not used" (convert |
@keradus my reasoning is if we cannot automate adding |
Thats the reason I remove them first since you cannot be sure and one could misplaced them. I dont think someone wants them intentionally placed like that. I suggest to add it and wait for the community to ask for "remove", "keep as is" or possibilities to adjust the position etc. |
I believe #6761 (comment) case shows that we must have "don't touch _ if already present" by default.
Perfectly valid option, then just one not interested in it will not use the rule and that's it.
Can you elaborate on condition here? I believe this option is fine even if we don't automate checking - and because we cannot know what is the context of number, we will not be able to automate it. |
I believe we can follow this path to make sure we are ready with state of fixer. |
Since this pull request has not had any activity within the last 90 days, I have marked it as stale. I will close it if no further activity occurs within the next 14 days. Please keep your branch up-to-date by rebasing it when main branch is ahead of it, thanks in advance! |
- use naming convention (testFix + provideFixCases) - do not check PHP version within provider, use `@requires PHP` - simplify test cases (get rid of `sprintf`) - fix PHPStan issues - apply current CS rules
4db68ff
to
22f585e
Compare
NumericLiteralSeparatorFixer
21d00cf
to
5fa2fae
Compare
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'll let myself approve and merge this, as several things were already discussed, I've verified all open discussions, implemented missing pieces and fixed requested stuff. I believe it's good to go 🙂.
Thank you very much @muuvmuuv 🍻! |
|
||
Allowed values: ``'no_separator'`` and ``'use_separator'`` | ||
|
||
Default value: ``'no_separator'`` |
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'm not sure of the default.
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 was suggested by me here and agreed by @kubawerlos so I implemented it like this. All the years I've been programming I have never worked with codebase that used literal separators, that's why I believe it's sane default.
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.
well, it was not possible for long in PHP, no doubts there is not adoption.
I aim to use everywhere personally, basically a must have for me for TS or python.
if both of you think this set of defaults is good, let's keep the defaults as-is
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.
Must personally agree with @keradus, but I am OK with it as long as I have the option to set it for myself.
Co-authored-by: Greg Korba <greg@codito.dev>
Closes: #6755