dprint / dprint-plugin-typescript

TypeScript and JavaScript code formatting plugin for dprint.
https://dprint.dev/plugins/typescript
MIT License
248 stars 55 forks source link

`"quoteStyle": "preferSingle"` should also affect completely cosmetic template literals #371

Open joscha opened 2 years ago

joscha commented 2 years ago

Obviously template literals have advantages in terms of interpolation, escaping and newline handling, however we want to encourage use of template literals only for strings that are making use of these features, not for ones that are just plain old strings. E.g.:

describe(':tada:', () => {
  it(`this string should be in single quotes`, () => {
      // some test here
  });
});

should actually be:

describe(':tada:', () => {
  it('this string should be in single quotes', () => {
      // some test here
  });
});

with "quoteStyle": "preferSingle"

Exceptions:

const x = `not this one ${nono}`;
const y = `neither
    this
    one`;
const z = `and not "this" 'one'`; // for both " and ' in the string

references https://github.com/dprint/dprint-plugin-typescript/issues/345

jakebailey commented 2 years ago

FWIW I feel like this won't turn out well for people who have dprint on an on-save handler; if I'm in the middle of typing a template literal and I save (usually out of muscle memory, or, an auto-save after a timeout), then it'd be annoying to have to redo my template literal again to be able to use it.