Skip to content
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 string_implicit_backslashes as escape_implicit_backslashes replacement #7669

Merged
merged 5 commits into from
Jan 29, 2024

Conversation

mvorisek
Copy link
Contributor

@mvorisek mvorisek commented Jan 3, 2024

fix #7621

if backslashes are disabled to be explicitly escaped, they must be unescaped

@mvorisek mvorisek force-pushed the norm_escape_7621 branch 2 times, most recently from d631add to 31692f9 Compare January 3, 2024 21:31
@mvorisek mvorisek marked this pull request as ready for review January 3, 2024 21:34
@mvorisek mvorisek marked this pull request as draft January 3, 2024 21:34
@mvorisek mvorisek marked this pull request as ready for review January 3, 2024 21:45
@mvorisek mvorisek changed the title fix: escape_implicit_backslashes must also unescape backslashed fix: escape_implicit_backslashes must also unescape backslashes Jan 3, 2024
@mvorisek mvorisek marked this pull request as draft January 4, 2024 00:51
@mvorisek mvorisek force-pushed the norm_escape_7621 branch 2 times, most recently from 51dbe67 to 16b0e15 Compare January 4, 2024 11:44
@mvorisek
Copy link
Contributor Author

mvorisek commented Jan 4, 2024

PR is done. Tested with

'escape_implicit_backslashes' => ['double_quoted' => false, 'heredoc_syntax' => false, 'single_quoted' => true],

configuration on the whole project, ie. the inverse configuration. Once removed and fixer is run again, all code returned to exactly the same version as before.

@mvorisek mvorisek marked this pull request as ready for review January 4, 2024 12:00
@mvorisek mvorisek force-pushed the norm_escape_7621 branch 2 times, most recently from a85f176 to f25d7a2 Compare January 5, 2024 21:46
@mvorisek
Copy link
Contributor Author

mvorisek commented Jan 6, 2024

Hi @Wirone, can you please review this PR?

@Wirone
Copy link
Member

Wirone commented Jan 6, 2024

I hope to do some reviews in the late evening 🤞.

@mvorisek
Copy link
Contributor Author

mvorisek commented Jan 8, 2024

@Wirone is now a good late evening?

@julienfalque
Copy link
Member

Shouldn't this new behavior be behind an option?

@Wirone
Copy link
Member

Wirone commented Jan 8, 2024

@Wirone is now a good late evening?

Hah, with 3 kids you can plan and end with totally different reality 😅. Today I am going on business trip for 2 days, many hours in the train, so I again plan to do some reviews 😉.

@mvorisek
Copy link
Contributor Author

mvorisek commented Jan 8, 2024

Shouldn't this new behavior be behind an option?

What about unescape: bool option?

It is easy to add, but I am a little worried to whom it will be helpful in reality.

@Wirone
Copy link
Member

Wirone commented Jan 8, 2024

To be honest, I don't know what to do with this PR 🤷‍♂️. In general, fixers are named after the state desired after fix is applied, in this case: all implicit backslashes should be escaped. It's clear that we can't change the current behaviour just like that, it must be introduced behind configuration option. But even if we do this, the idea behind fixer under this particular name would be broken, so in order to do it properly we should introduce new fixer, e.g. implicit_backslashes and modify escape_implicit_backslashes to be only proxy fixer to the new one, with proper config. I believe the options double_quoted, single_quoted and heredoc_syntax should be a three-state: ?bool or dictionary-like escape|unescape|ignore, in order to achieve both strategies and to be able to leave code as-is.

But it's only my perspective, I believe we need @keradus' opinion.

@Wirone Wirone requested a review from keradus January 8, 2024 18:07
@mvorisek
Copy link
Contributor Author

mvorisek commented Jan 8, 2024

I like the 3-state concept and new fixer name - is there any "proxy migration fixer PR" I can as a reference?

Other options is to keep this PR as is, I do not see any value in not unescaping implicit backslashes when they are not fixed to the oposite.

@Wirone
Copy link
Member

Wirone commented Jan 8, 2024

You can take a look at #7053, but I would recommend waiting for @keradus' opinion, as I won't merge it anyway without his decision about it 🙂.

@julienfalque
Copy link
Member

I also like @Wirone's proposal and agree the current name of the fixer might not be very accurate with this new behavior.

I do think unescaping should be the default behavior but that might be an unexpected change for users, hence the option. We might reconsider this when we'll prepare a new major version.

@mvorisek mvorisek marked this pull request as draft January 10, 2024 17:39
@mvorisek mvorisek changed the title fix: escape_implicit_backslashes must also unescape backslashes fix: introduce string_implicit_backslashes as escape_implicit_backslashes replacement Jan 11, 2024
@mvorisek mvorisek marked this pull request as ready for review January 11, 2024 10:53
@mvorisek mvorisek changed the title fix: introduce string_implicit_backslashes as escape_implicit_backslashes replacement feat: introduce string_implicit_backslashes as escape_implicit_backslashes replacement Jan 11, 2024
@mvorisek mvorisek requested a review from Wirone January 11, 2024 10:56
Copy link
Member

@Wirone Wirone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to see small improvement in tests, other than that - looks good.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: diff between new fixer and EscapeImplicitBackslashesFixerTest (not counting supported options, docs etc):

image

@Wirone Wirone merged commit e351af7 into PHP-CS-Fixer:master Jan 29, 2024
26 checks passed
@Wirone
Copy link
Member

Wirone commented Jan 29, 2024

Thank you @mvorisek 🍻!

@mvorisek mvorisek deleted the norm_escape_7621 branch January 29, 2024 12:01
danog pushed a commit to zoonru/PHP-CS-Fixer that referenced this pull request Feb 2, 2024
…kslashes` replacement (PHP-CS-Fixer#7669)

Co-authored-by: Greg Korba <wirone@gmail.com>
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.

escape_implicit_backslashes should also unfix escaped backslashed
3 participants