dprint-plugin-typescript icon indicating copy to clipboard operation
dprint-plugin-typescript copied to clipboard

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

Open joscha opened this issue 3 years ago • 1 comments

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

joscha avatar May 24 '22 02:05 joscha

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.

jakebailey avatar Sep 09 '22 04:09 jakebailey