briandipalma / esformatter-quote-props

esformatter plugin that toggles the quotes around properties.
1 stars 1 forks source link

"Value needs to be a string" when handling numeric property names #2

Closed mkai closed 9 years ago

mkai commented 9 years ago

According to the MDN docs, numeric property names are valid in JavaScript. Thus, esformatter-quote-props does remove the quotes around them:

Before:

var choices = {
    '': true,
    '1': true,
    '0': true,
    '0777': true,
    'a_string': true,
    '0222a': true
};

After:

var choices = {
  '': true,
  1: true,
  0: true,
  0777: true,
  a_string: true,
  '0222a': true
};

However, esformatter-quote-props throws an error when it has to handle them itself. If I run esformatter again on the result, an error occurs:

$ esformatter --plugins esformatter-quote-props
var choices = {0777: true};
^D
Value needs to be a string

The attached pull request fixes this bug by simply making sure that the object passed to unquotedValidator is always a string. The tests were also updated to trigger the bug (see first commit).

Please merge if you like!

briandipalma commented 9 years ago

Thank you very much for the PR, sorry for being so slow to respond I was travelling. I've published the new version with your fix.