Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(typescript-estree): computed members discriminated unions #1349

Merged
merged 7 commits into from Dec 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/indent.ts
Expand Up @@ -392,7 +392,7 @@ export default util.createRule<Options, MessageIds>({
computed: false,
method: false,
shorthand: false,
},
} as any,
],

// location data
Expand Down
Expand Up @@ -63,7 +63,7 @@ export default util.createRule<Options, MessageIds>({
) {
return ignoredMethods.has(node.key.quasis[0].value.raw);
}
if (node.key.type === AST_NODE_TYPES.Identifier && !node.computed) {
if (!node.computed && node.key.type === AST_NODE_TYPES.Identifier) {
return ignoredMethods.has(node.key.name);
}

Expand Down
3 changes: 1 addition & 2 deletions packages/eslint-plugin/src/rules/prefer-for-of.ts
Expand Up @@ -149,9 +149,8 @@ export default util.createRule({
// ({ foo: a[i] }) = { foo: 0 }
if (
parent.type === AST_NODE_TYPES.Property &&
parent.parent !== undefined &&
parent.parent.type === AST_NODE_TYPES.ObjectExpression &&
parent.value === node &&
parent.parent?.type === AST_NODE_TYPES.ObjectExpression &&
isAssignee(parent.parent)
) {
return true;
Expand Down
22 changes: 4 additions & 18 deletions packages/eslint-plugin/src/util/misc.ts
Expand Up @@ -107,29 +107,16 @@ function getNameFromMember(
| TSESTree.TSPropertySignature,
sourceCode: TSESLint.SourceCode,
): string {
if (isLiteralOrIdentifier(member.key)) {
if (member.key.type === AST_NODE_TYPES.Identifier) {
return member.key.name;
}
if (member.key.type === AST_NODE_TYPES.Identifier) {
return member.key.name;
}
if (member.key.type === AST_NODE_TYPES.Literal) {
return `${member.key.value}`;
}

return sourceCode.text.slice(...member.key.range);
}

/**
* This covers both actual property names, as well as computed properties that are either
* an identifier or a literal at the top level.
*/
function isLiteralOrIdentifier(
node: TSESTree.Expression,
): node is TSESTree.Literal | TSESTree.Identifier {
return (
node.type === AST_NODE_TYPES.Literal ||
node.type === AST_NODE_TYPES.Identifier
);
}

type ExcludeKeys<
TObj extends Record<string, unknown>,
TKeys extends keyof TObj
Expand All @@ -148,7 +135,6 @@ export {
InferMessageIdsTypeFromRule,
InferOptionsTypeFromRule,
isDefinitionFile,
isLiteralOrIdentifier,
RequireKeys,
upperCaseFirst,
};