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

Handle special characters in property name #297

Open
Maxim-Mazurok opened this issue Aug 4, 2020 · 2 comments
Open

Handle special characters in property name #297

Maxim-Mazurok opened this issue Aug 4, 2020 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@Maxim-Mazurok
Copy link
Owner

Our formatPropertyName() function doesn't handle ? in property name, which may result in

interface AddChartResponse {
    /** The newly added chart. */
    embedded?Chart?: EmbeddedChart;
}

Originally posted by @Maxim-Mazurok in #208 (comment)

This probably should be handled using regular expressions. Check if a property name contains any non-letter characters and surround it with quotes in that case. Perhaps, quotes also should be handled somehow. And, perhaps, not all non-letter characters should be treated as "quotable".

@HoldYourWaffle
Copy link

Purely out of curiosity, what kind of property would have a '?' in its name?

As for checking if a property name should be quoted: the rules for a valid (non-quoted) identifier are well-defined. It should indeed be trivial to check if an identifier is valid without quotes using a regex like this one.
I think we'd be safe to assume that Google will only use ASCII characters, and even if they don't, it won't really hurt to "unnecessarily" quote property names.

@Maxim-Mazurok Maxim-Mazurok added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Aug 4, 2020
@Maxim-Mazurok
Copy link
Owner Author

what kind of property would have a '?' in its name?

I think we'd be safe to assume that Google will only use ASCII characters

We can't be 100% sure about that ;)

It should indeed be trivial to check if an identifier is valid without quotes using a regex

Yep, that's a good idea

it won't really hurt to "unnecessarily" quote property names

Actually, it will hurt, dtslint will fail if we do that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants