Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a false positive for
Lint/InheritException
Fixes standardrb/standard#388 and reverts #3427. This PR prevents the following false positive and auto-correction. ```diff class TestClass - FatalError = Class.new(Interrupt) + FatalError = Class.new(RuntimeError) end ``` Below is an inheritance tree for the exception classes. ``` --------------- | BasicObject | --------------- ^ | --------------- | Kernel | --------------- ^ | --------------- | Object | --------------- ^ | --------------- | Exception | --------------- ^ | |------------------| --------------- ----------------- |StandardError| |SignalException| --------------- ----------------- ^ ^ | | --------------- ----------------- |RuntimeError | | Interrupt | --------------- ----------------- ``` As the inheritance tree shows, `Interrupt` is not `is_a?` in either `StandardError` or `RuntimeError`. ```ruby RuntimeError.new.is_a?(StandardError) #=> true Interrupt.new.is_a?(StandardError) #=> false Interrupt.new.is_a?(RuntimeError) #=> false ``` This goes against The Liskov Substitution Principle. `Interup` should not be replaced with `StandardError` or its subclasses. Also, according to The Open/Closed Principle, `Interrup` class should be open to inheritance. The same is true for `SystemStackError`, `NoMemoryError`, `SecurityError`, `NotImplementedError`, `LoadError`, `SyntaxError`, `ScriptError`, `SignalException`, and `SystemExit` classes. This PR allows for exception handling according to Object-oriented principles and Ruby exception handling mechanism.
- Loading branch information