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: remove unnecessary escape sequences in strings #497

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shannonrothe
Copy link

@shannonrothe shannonrothe commented Feb 27, 2023

This fix ensures any unnecessary escape sequences in a string literal are omitted. It is largely based off the rules set out here. I've modified remove_needless_quote_backslashes to incorporate the additional "rules", whereby previously it only cared about escaped quotes depending on the type of string literal.

I'm pretty heavily relying on a few new test cases + ensuring existing tests didn't break, so there's a chance I might miss some edge cases

@CLAassistant
Copy link

CLAassistant commented Feb 27, 2023

CLA assistant check
All committers have signed the CLA.

@dsherret dsherret changed the title remove unnecessary escape sequences feat: remove unnecessary escape sequences in strings Mar 20, 2023
Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

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

Thanks! This seems very nice to have. However, when testing out what prettier does, it maintains escapes for numbers since "\5" !== "5". If we merge this I want to be absolute sure we can actually do this. It might be good to write a script in javascript that goes through all the character possibilities and finds all the scenarios where a character is not equal to itself escaped.

@dsherret
Copy link
Member

I was just thinking more about this and actually I think we should change this to only occur when the char is also .is_ascii_alphabetic(). That will be much safer to do.

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.

3 participants