The "extends": "eslint:recommended" property in a configuration file enables this rule.

JavaScript suspends the control flow statements of try and catch blocks until the execution of finally block finishes. So, when return, throw, break, or continue is used in finally, control flow statements inside try and catch are overwritten, which is considered as unexpected behavior. Such as:

// We expect this function to return 1;(()=>{try{return1;// 1 is returned but suspended until finally block ends}catch(err){return2;}finally{return3;// 3 is returned before 1, which we did not expect}})();// > 3

// We expect this function to throw an error, then return(()=>{try{thrownewError("Try");// error is thrown but suspended until finally block ends}finally{return3;// 3 is returned before the error is thrown, which we did not expect}})();// > 3

// We expect this function to throw Try(...) error from the catch block(()=>{try{thrownewError("Try")}catch(err){throwerr;// The error thrown from try block is caught and rethrown}finally{thrownewError("Finally");// Finally(...) is thrown, which we did not expect}})();// > Uncaught Error: Finally(...)

// We expect this function to return 0 from try block.(()=>{label:try{return0;// 1 is returned but suspended until finally block ends}finally{breaklabel;// It breaks out the try-finally block, before 0 is returned.}return1;})();// > 1

Rule Details

This rule disallows return, throw, break, and continue statements inside finally blocks. It allows indirect usages, such as in function or class definitions.