From b37e5d8130b84b34659e7ea407151f9ee4c1efbe Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Tue, 28 Feb 2017 11:17:47 -0500 Subject: [PATCH] `object-literal-key-quotes` flags negative number as not needing quotes (#2272) --- src/rules/objectLiteralKeyQuotesRule.ts | 2 +- test/rules/object-literal-key-quotes/as-needed/test.ts.fix | 1 + test/rules/object-literal-key-quotes/as-needed/test.ts.lint | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rules/objectLiteralKeyQuotesRule.ts b/src/rules/objectLiteralKeyQuotesRule.ts index 9be27c2a570..d2609713481 100644 --- a/src/rules/objectLiteralKeyQuotesRule.ts +++ b/src/rules/objectLiteralKeyQuotesRule.ts @@ -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. diff --git a/test/rules/object-literal-key-quotes/as-needed/test.ts.fix b/test/rules/object-literal-key-quotes/as-needed/test.ts.fix index 9dd05ac5201..d4e6146b179 100644 --- a/test/rules/object-literal-key-quotes/as-needed/test.ts.fix +++ b/test/rules/object-literal-key-quotes/as-needed/test.ts.fix @@ -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, diff --git a/test/rules/object-literal-key-quotes/as-needed/test.ts.lint b/test/rules/object-literal-key-quotes/as-needed/test.ts.lint index 4a7facdccfe..3e4e2cefd43 100644 --- a/test/rules/object-literal-key-quotes/as-needed/test.ts.lint +++ b/test/rules/object-literal-key-quotes/as-needed/test.ts.lint @@ -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,