meganrogge / template-string-converter

Autocorrect from quotes to backticks
MIT License
194 stars 24 forks source link

adds option to automatically revert backticks (again) and fixes some bugs related to it #48

Closed xNocken closed 3 years ago

xNocken commented 3 years ago

related issues: #47 #43

karlhorky commented 3 years ago

In case this gets merged, then https://github.com/meganrogge/template-string-converter/issues/44 can be reopened too

karlhorky commented 3 years ago

In reviewing whether this should be merged or not, some things to check are:

meganrogge commented 3 years ago

Thanks for resolving the issues @xNocken and for the bug reporting @karlhorky.

karlhorky commented 3 years ago

So this has been released in 0.4.9 right?

Just taking a look at the extension page, it seems like this option is not documented.

@xNocken could you add this to the README.md, maybe with a gif illustrating the feature?

meganrogge commented 3 years ago

Done @karlhorky

karlhorky commented 3 years ago

Thanks!! I'll have to re-enable this and give it a try extensively.

karlhorky commented 2 years ago

Ok, so it seems this feature is still somewhat buggy:

It erroneously makes the following tagged template string into a double-quoted string, when hitting backspace anywhere inside the template string.

Notice there are no interpolations. It's important that it stay as a tagged template string.

export async function down(sql: Sql<{}>) {
  await sql`DROP TABLE reset_password_requests`;
}
karlhorky commented 2 years ago

I'm guessing the logic for this code for this feature is:

  1. If the user is inside a template string AND hits backspace:
    1. switch to double quotes

This is maybe almost ok, but should probably do some better checks:

  1. If the user is inside a template string AND there is an interpolation (${ and } present in the string) AND there is NO interpolation AFTER hitting backspace:
    1. switch to double quotes

That seems like it would be a much more robust start of an implementation (probably also has weird edge cases, but at least it's much better than what's there now).