royriojas / esformatter-jsx

esformatter plugin: format jsx files (or js files with Facebook React JSX Syntax)
MIT License
142 stars 25 forks source link

Add an option to control if StringLiterals in JSXAttributes' value should use double quotes or single ones #93

Closed royriojas closed 7 years ago

royriojas commented 7 years ago
  1. Let's call that property JSXAttributeQuotes
  2. if the property has a value of empty, null or undefined (in short if falsy) then ignore it, quotes should remain as they were received
  3. If the property has a value different from single or double, just ignore it.
  4. if the property has a value of single, then make sure all stringLiterals in JSXProperties use single quotes.
  5. if the property has a value of double, then make sure all stringLiterals in JSXProperties use double quotes.

Note. Strings should be escaped when needed.

Example:

Given

function render(count) {
  return <input type="text"
 />;
}

and JSXAttributeQuotes is single

then the expected output will be

function render(count) {
  return <input type='text' />;
}

if JSXAttributeQuotes is double and the input is

function render(count) {
  return <input type='text'
 />;
}

then the output should be

function render(count) {
  return <input type="text" />;
}