ruff
bf0e5788 - [pylint] Implement misplaced-bare-raise (E0704) (#7961)

Commit
1 year ago
[pylint] Implement misplaced-bare-raise (E0704) (#7961) ## Summary ### What it does This rule triggers an error when a bare raise statement is not in an except or finally block. ### Why is this bad? If raise statement is not in an except or finally block, there is no active exception to re-raise, so it will fail with a `RuntimeError` exception. ### Example ```python def validate_positive(x): if x <= 0: raise ``` Use instead: ```python def validate_positive(x): if x <= 0: raise ValueError(f"{x} is not positive") ``` ## Test Plan Added unit test and snapshot. Manually compared ruff and pylint outputs on pylint's tests. ## References - [pylint documentation](https://pylint.pycqa.org/en/stable/user_guide/messages/error/misplaced-bare-raise.html) - [pylint implementation](https://github.com/pylint-dev/pylint/blob/main/pylint/checkers/exceptions.py#L339)
Author
Parents
Loading