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

Commit

Permalink
Consider rest operator in object literal in `object-literal-key-quote…
Browse files Browse the repository at this point in the history
…s` rule (fix #1916) (#1917)
  • Loading branch information
rhysd authored and nchen63 committed Dec 24, 2016
1 parent be73295 commit 16e8d02
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/rules/objectLiteralKeyQuotesRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class ObjectLiteralKeyQuotesWalker extends Lint.RuleWalker {
}
break;
case "consistent-as-needed":
if (properties.some(({ name }) => name.kind === ts.SyntaxKind.StringLiteral && propertyNeedsQuotes(name.text))) {
if (properties.some(({ name }) => name !== undefined && name.kind === ts.SyntaxKind.StringLiteral && propertyNeedsQuotes(name.text))) {
this.allMustHaveQuotes(properties);
} else {
this.noneMayHaveQuotes(properties, true);
Expand All @@ -116,15 +116,15 @@ class ObjectLiteralKeyQuotesWalker extends Lint.RuleWalker {

private allMustHaveQuotes(properties: ts.ObjectLiteralElementLike[]) {
for (const { name } of properties) {
if (name.kind !== ts.SyntaxKind.StringLiteral && name.kind !== ts.SyntaxKind.ComputedPropertyName) {
if (name !== undefined && name.kind !== ts.SyntaxKind.StringLiteral && name.kind !== ts.SyntaxKind.ComputedPropertyName) {
this.addFailureAtNode(name, Rule.UNQUOTED_PROPERTY(name.getText()));
}
}
}

private noneMayHaveQuotes(properties: ts.ObjectLiteralElementLike[], noneNeedQuotes?: boolean) {
for (const { name } of properties) {
if (name.kind === ts.SyntaxKind.StringLiteral && (noneNeedQuotes || !propertyNeedsQuotes(name.text))) {
if (name !== undefined && name.kind === ts.SyntaxKind.StringLiteral && (noneNeedQuotes || !propertyNeedsQuotes(name.text))) {
this.addFailureAtNode(name, Rule.UNNEEDED_QUOTES(name.text));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ const o = {
"true": 0, // failure
~~~~~~ [Unnecessarily quoted property 'true' found.]
'': 'always quote the empty string',
...{},
};
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ const u = {
"egg": 2,
~~~~~ [Unnecessarily quoted property 'egg' found.]
}
};
};
const v = {
...o,
};

0 comments on commit 16e8d02

Please sign in to comment.