Class CheckUselessBlocks

  • All Implemented Interfaces:
    CompilerPass, NodeTraversal.Callback

    public final class CheckUselessBlocks
    extends java.lang.Object
    implements NodeTraversal.Callback, CompilerPass
    Check for useless blocks. A block is considered useful if it is part of a control structure like if / else / while / switch / etc. or if it contains any block-scoped variables (let, const, class, or function declarations). Otherwise there is no reason to use it so it is likely a mistake. This would catch the classic error:

    return {foo: 'bar'};

    or more contrived cases like:

    if (denied) { showAccessDenied(); } { grantAccess(); }

    Inspired by ESLint (https://github.com/eslint/eslint/blob/master/lib/rules/no-lone-blocks.js)