Improvement for S1117 ("no shadow")

The SonarQube instance I use recently upgraded to the latest version of the TS/JS plugin and brought along a bunch of new rules. One of those is S1117, which caught code like this:

if (foo) {
  const ret = {...}
  return ret;

const ret = { ... }

Due to scope hoisting, the second ret is technically in-scope inside the if statement, but the actual r-value for the second ret isn’t evaluated and can never be used.

In my view, it’s kind of hard to argue that the above is actually an instance of shadowing, because exactly one of the two assignments can possibly happen, due to the early return inside the if block. Maybe there’s an edge case I’m not thinking of where it still makes sense to flag in this scenario?