Skip to content

JS: fix FP related to block-level flow type annotations#2581

Merged
semmle-qlci merged 2 commits intogithub:masterfrom
erik-krogh:FlowUselessExpr
Jan 6, 2020
Merged

JS: fix FP related to block-level flow type annotations#2581
semmle-qlci merged 2 commits intogithub:masterfrom
erik-krogh:FlowUselessExpr

Conversation

@erik-krogh
Copy link
Copy Markdown
Contributor

Block-level flow type annotations were falsely flagged as useless-expressions.

E.g:

  ...
  default:
     (type: empty); // flagged by `js/useless-expression`
     throw new Error(`Received invalid event property type ${type}`);
  ...

Currently the check is purely syntactical by inspecting the tokens to recognize the (e: type) pattern.
It doesn't seem like a nice way to do it, but it was the best I could get to work.

An evaluation shows that plenty of false positives are removed, and performance seems to be OK.

@erik-krogh erik-krogh added the JS label Jan 3, 2020
@erik-krogh erik-krogh requested a review from a team as a code owner January 3, 2020 08:57
Copy link
Copy Markdown
Contributor

@max-schaefer max-schaefer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! That's actually simpler than I thought. Could you add a test?

@semmle-qlci semmle-qlci merged commit 5dcc5b3 into github:master Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants