-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Fix method definition cop #44
base: master
Are you sure you want to change the base?
Conversation
@koic Is the configured Circle CI still working. Am getting the error below:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is correct. The difference between which definition of a method or class wins is according to lexical order. The only one that works properly, without polluting the global Ruby Object namespace is inside a task, (whether or not it is inside a namespace is irrelevant).
# because it is defined to the top level. | ||
# It is confusing because the scope looks in the task or namespace, | ||
# It is confusing because the scope looks in the namespace, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# It is confusing because the scope looks in the namespace, | |
# It is confusing because the scope appears as if it is in the namespace, |
Ping! Just ran into this false positive again, and came looking to see if any activity here. |
bac9816
to
e116f67
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! ❤️
e116f67
to
2915482
Compare
Is this correctly handling when a task is nested inside a namespace? I believe that should be allowed, but the spec doesn't seem to cover it and it looks like it is disallowed. For example this test fails:
|
That's true. I have now pushed a fix for this.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@kuahyeow The build passed before your last fix, but now it failing on Ruby >= 2.7. Any ideas? |
000d0e2
to
0fd68b2
Compare
Looks like it's failing on unrelated rubocop errors....
|
@kuahyeow could you please rebase the branch? The CI specs should pass as expected now. |
LGTM still! |
As methods defined in task do not pollute top level For example, this rakefile below will show that `do_something` does not appear in top level methods ``` task :a do def do_something puts 'a' end do_something end task :b do def do_something puts 'b' end do_something end puts methods.include?(:do_something) ```
As classes defined in task do not pollute top level. For example, this Rakefile shows class C in task does not pollute top level ``` task :a do class C def do_something puts 'a' end end C.new.do_something end task :b do class C def do_something puts 'b' end end C.new.do_something end puts Object.const_defined?('C') ```
Since the cop is now fixed to warn against class in namespaces, update the cop name accordingly.
Since the cop is now fixed to warn against method in namespaces, update the cop name accordingly.
This is similar to definitions within a task (without a namespace).
0fd68b2
to
fc00ab1
Compare
Fixes #42
Fixes
ClassDefinitionInTask
, andMethodDefinitionInTask
to allow classes, modules and methods to defined inside tasks