Skip to main content

js/noUnsafeFinally

disallow control flow statements in finally blocks

ESLint Equivalent: no-unsafe-finally

Examples

Invalid

function greet1() {
	try {
		throw new Error('Try')
	} catch(err) {
		throw err;
	} finally {
		return 1;
	}
}

 file.ts:7:2 lint/js/noUnsafeFinally ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Using JSReturnStatement inside a finally clause is unsafe.

    5    throw err;
    6  } finally {
  > 7    return 1;
         ^^^^^^^^^
    8  }
    9}

  Do not use control flow statements inside finally clauses.


function greet2() {
	try {
		throw new Error('Try')
	} catch(err) {
		throw err;
	} finally {
		break;
	}
}

 file.ts:7:2 parse(js) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  No loop label found

    5    throw err;
    6  } finally {
  > 7    break;
         ^
    8  }
    9}


function greet3() {
	try {
		throw new Error('Try')
	} catch(err) {
		throw err;
	} finally {
		continue;
	}
}

 file.ts:7:2 parse(js) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  No loop label found

    5    throw err;
    6  } finally {
  > 7    continue;
         ^
    8  }
    9}


function greet4() {
	try {
		throw new Error('Try')
	} catch(err) {
		throw err;
	} finally {
		throw new Error('Finally');
	}
}

 file.ts:7:2 lint/js/noUnsafeFinally ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Using JSThrowStatement inside a finally clause is unsafe.

    5    throw err;
    6  } finally {
  > 7    throw new Error('Finally');
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    8  }
    9}

  Do not use control flow statements inside finally clauses.