Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
object-literal-key-quotes flags negative number as not needing quot…
Browse files Browse the repository at this point in the history
…es (#2272)
  • Loading branch information
nchen63 authored Feb 28, 2017
1 parent 85e0400 commit b37e5d8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rules/objectLiteralKeyQuotesRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ function quotesAreInconsistent(properties: ts.ObjectLiteralElementLike[]): boole
}

function propertyNeedsQuotes(property: string): boolean {
return !IDENTIFIER_NAME_REGEX.test(property) && Number(property).toString() !== property;
return !IDENTIFIER_NAME_REGEX.test(property) && (Number(property).toString() !== property || property.startsWith("-"));
}

// This is simplistic. See https://mothereff.in/js-properties for the gorey details.
Expand Down
1 change: 1 addition & 0 deletions test/rules/object-literal-key-quotes/as-needed/test.ts.fix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const o = {
1.23: null,
'010': 'but this one does.',
'.123': 'as does this one',
'-1': 'and this one',
fn() { return },
true: 0,
"0x0": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const o = {
1.23: null,
'010': 'but this one does.',
'.123': 'as does this one',
'-1': 'and this one',
fn() { return },
true: 0,
"0x0": 0,
Expand Down

0 comments on commit b37e5d8

Please sign in to comment.