-
-
Notifications
You must be signed in to change notification settings - Fork 277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LeakyConstantDeclaration - allow definitions on example group #1798
base: master
Are you sure you want to change the base?
Conversation
72f563f
to
51f9e38
Compare
Constant, classes, and modules that are defined on the example group do not leak into the global namespace. While doing this may not be a particularly good practice, it should ideally not result in an offense. The practice is described here: https://makandracards.com/makandra/47189-rspec-how-to-define-classes-for-specs#section-1-defining-the-constant-on-the-example-class
51f9e38
to
b11854b
Compare
Sorry, I didn’t read the article, but the description of this is misleading. I’m fine to accept this if we change the scope to ignore all const definitions with explicitly specified owner. |
The problem with the approach described in the article is that examples may litter class, and those changes would persist between examples. The cop was initially introduced to avoid side effects and surprises. I’d love it to keep what it’s doing. https://fili.pp.ru/leaky-constants.html I’m more inclined to close the PR. WDYT @rubocop/rubocop-rspec? |
This is true of any class defined in any location. The issue flagged by the cop is that it's quite easy to define classes in the global namespace without realizing that is happening. Using Allowing any explicitly specified namespace would make sense to me - even |
let(:klass) { Class.new { } } won’t suffer from this.
Agree. |
Constant, classes, and modules that are defined on the example group do
not leak into the global namespace. While doing this may not be
a particularly good practice, it should ideally not result in
an offense.
The practice is described here: https://makandracards.com/makandra/47189-rspec-how-to-define-classes-for-specs#section-1-defining-the-constant-on-the-example-class
Before submitting the PR make sure the following are checked:
master
(if not - rebase it).CHANGELOG.md
if the new code introduces user-observable changes.bundle exec rake
) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).If you have created a new cop:
config/default.yml
.Enabled: pending
inconfig/default.yml
.Enabled: true
in.rubocop.yml
.VersionAdded: "<<next>>"
indefault/config.yml
.If you have modified an existing cop's configuration options:
VersionChanged: "<<next>>"
inconfig/default.yml
.