-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
Is your feature request related to a problem? Please describe.
Most RuboCop cops operate purely on AST/CST and their behaviour depends only on Ruby version, cop's implementation and explicit downstream dependencies (like regexp_parser or parser). However, some of them also take into account different things like loaded constants (and other runtime information).
One notable example is Lint/ShadowedException:
# constants.rb
A = Class.new(Exception)
B = Class.new(A)# test.rb
begin
rescue A
rescue B
end$ rubocop test.rb --only Lint/ShadowedException
1 file inspected, no offenses detected$ RUBYOPT=-r./constants rubocop test.rb --only Lint/ShadowedException
Offenses:
test.rb:2:1: W: Lint/ShadowedException: Do not shadow rescued Exceptions.
rescue A ...
^^^^^^^^
1 file inspected, 1 offense detectedI remember being confused by different RuboCop's output in test and development environments due to different loaded feature sets. I think that a read-only cop configuration (something like Pure: true/false can help people to better understand these kinds of mismatches.
I think I've seen a couple of other "impure" cops in the core departments, but Lint/ShadowedException is the only examples I can recall right now.
Describe the solution you'd like
For instance, a new read-only per-cop configuration option would be fine. Pure :: Boolean or RuntimeDependent :: Boolean, for instance.
Describe alternatives you've considered
N/A
Additional context
N/A