Cleanup unnecessary lint suppresions (#682)

We often construct case statements over union-typed variables, and then
in the default case, we use a `(type: empty)` assertion to ensure that
failing to account for all the cases results in a flow error.

In the past, we created an extra line for this assertion, which required
some eslint suppressions. We've realized it's cleaner to inline the type
assertion in the runtime error that we throw in these defaults.

This code cleans everything to the new style, and removes every existing
`// no-unused-expressions` invocation in the codebase.

Test plan: `yarn test`
This commit is contained in:
Dandelion Mané 2018-08-16 11:15:00 -07:00 committed by GitHub
parent f1afd5a248
commit ac8b9147c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 14 additions and 36 deletions

View File

@ -71,9 +71,7 @@ class GraphCreator {
target = {type: GN.COMMIT_TYPE, hash: entry.hash}; target = {type: GN.COMMIT_TYPE, hash: entry.hash};
break; break;
default: default:
// eslint-disable-next-line no-unused-expressions throw new Error(String((entry.type: empty)));
(entry.type: empty);
throw new Error(String(entry.type));
} }
this.graph.addNode(GN.toRaw(target)); this.graph.addNode(GN.toRaw(target));
this.graph.addEdge(GE.createEdge.hasContents(entryNode, target)); this.graph.addEdge(GE.createEdge.hasContents(entryNode, target));

View File

@ -237,8 +237,6 @@ export function toRaw(x: StructuredAddress): RawAddress {
...lengthEncode(GitNode.toRaw(x.treeEntry)) ...lengthEncode(GitNode.toRaw(x.treeEntry))
); );
default: default:
// eslint-disable-next-line no-unused-expressions throw new Error((x.type: empty));
(x.type: empty);
throw new Error(x.type);
} }
} }

View File

@ -102,8 +102,6 @@ export function toRaw(x: StructuredAddress): RawAddress {
case TREE_ENTRY_TYPE: case TREE_ENTRY_TYPE:
return NodeAddress.append(_Prefix.treeEntry, x.treeHash, x.name); return NodeAddress.append(_Prefix.treeEntry, x.treeHash, x.name);
default: default:
// eslint-disable-next-line no-unused-expressions throw new Error(`Unexpected type ${(x.type: empty)}`);
(x.type: empty);
throw new Error(`Unexpected type ${x.type}`);
} }
} }

View File

@ -215,8 +215,6 @@ export function toRaw(x: StructuredAddress): RawAddress {
...lengthEncode(GithubNode.toRaw(x.referent)) ...lengthEncode(GithubNode.toRaw(x.referent))
); );
default: default:
// eslint-disable-next-line no-unused-expressions throw new Error((x.type: empty));
(x.type: empty);
throw new Error(x.type);
} }
} }

View File

@ -261,15 +261,11 @@ export function toRaw(x: StructuredAddress): RawAddress {
x.id x.id
); );
default: default:
// eslint-disable-next-line no-unused-expressions throw new Error(`Bad comment parent type: ${(x.parent.type: empty)}`);
(x.parent.type: empty);
throw new Error(`Bad comment parent type: ${x.parent.type}`);
} }
case USERLIKE_TYPE: case USERLIKE_TYPE:
return NodeAddress.append(_Prefix.userlike, x.login); return NodeAddress.append(_Prefix.userlike, x.login);
default: default:
// eslint-disable-next-line no-unused-expressions throw new Error(`Unexpected type ${(x.type: empty)}`);
(x.type: empty);
throw new Error(`Unexpected type ${x.type}`);
} }
} }

View File

@ -108,9 +108,7 @@ export function deformat(ast: Node): void {
case "custom_block": case "custom_block":
break; break;
default: default:
// eslint-disable-next-line no-unused-expressions throw new Error("unexpected type: " + (type: empty));
(type: empty);
throw new Error("unexpected type: " + type);
} }
} }
} }

View File

@ -322,9 +322,9 @@ export class RelationalView {
case N.REVIEW_TYPE: case N.REVIEW_TYPE:
return reviewCommentUrlToId(json.url); return reviewCommentUrlToId(json.url);
default: default:
// eslint-disable-next-line no-unused-expressions throw new Error(
(parent.type: empty); `Unexpected comment parent type: ${(parent.type: empty)}`
throw new Error(`Unexpected comment parent type: ${parent.type}`); );
} }
})(); })();
const address: CommentAddress = {type: N.COMMENT_TYPE, id, parent}; const address: CommentAddress = {type: N.COMMENT_TYPE, id, parent};
@ -405,9 +405,7 @@ export class RelationalView {
this._addExtraAuthor(e, userlike); this._addExtraAuthor(e, userlike);
break; break;
default: default:
// eslint-disable-next-line no-unused-expressions throw new Error(`Unexpected refType: ${(refType: empty)}`);
(refType: empty);
throw new Error(`Unexpected refType: ${refType}`);
} }
} }
} }
@ -461,10 +459,8 @@ export class RelationalView {
entity = this.comment(address); entity = this.comment(address);
break; break;
default: default:
// eslint-disable-next-line no-unused-expressions
(address.type: empty);
throw new Error( throw new Error(
`Unexpected referrer address type: ${address.type}` `Unexpected referrer address type: ${(address.type: empty)}`
); );
} }
if (entity == null) { if (entity == null) {
@ -506,10 +502,8 @@ export class RelationalView {
entity = this.userlike(address); entity = this.userlike(address);
break; break;
default: default:
// eslint-disable-next-line no-unused-expressions
(address.type: empty);
throw new Error( throw new Error(
`Unexpected referent address type: ${address.type}` `Unexpected referent address type: ${(address.type: empty)}`
); );
} }
if (entity == null) { if (entity == null) {
@ -758,9 +752,7 @@ export class Comment extends _Entity<CommentEntry> {
parent = this._view.review(address); parent = this._view.review(address);
break; break;
default: default:
// eslint-disable-next-line no-unused-expressions throw new Error(`Bad parent address type: ${(address.type: empty)}`);
(address.type: empty);
throw new Error(`Unexpected parent address: ${stringify(address)}`);
} }
return assertExists(parent, address); return assertExists(parent, address);
} }