-
-
Notifications
You must be signed in to change notification settings - Fork 18
Fix method definition cop #44
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
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, |
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.
@kuahyeow This grammatical issue still needs to be fixed. It is incorrect to say it "the scope looks in the namespace", which may imply to some that the namespace is relevant to the scoping. It makes more sense to say it "appears as if it is in the namespace"... when in fact it is not.
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
@koic Please approve the workflow! |
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.
Needs a minor grammatical fix
# 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.
@kuahyeow This grammatical issue still needs to be fixed. It is incorrect to say it "the scope looks in the namespace", which may imply to some that the namespace is relevant to the scoping. It makes more sense to say it "appears as if it is in the namespace"... when in fact it is not.
# It is confusing because the scope looks in the namespace, | |
# It is confusing because the scope appears as if it is in the namespace, |
Thanks @pboling. I have updated the comment now. Please take a look !
…On Sat, 5 Apr 2025 at 13:52, Peter Boling ***@***.***> wrote:
***@***.**** commented on this pull request.
Needs a minor grammatical fix
------------------------------
In lib/rubocop/cop/rake/class_definition_in_namespace.rb
<#44 (comment)>:
> # 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,
@kuahyeow <https://github.com/kuahyeow> This grammatical issue still
needs to be fixed. It is incorrect to say it "the scope looks in the
namespace", which may imply to some that the namespace is relevant to the
scoping. It makes more sense to say it "appears as if it is in the
namespace"... when in fact it is not.
⬇️ Suggested change
- # It is confusing because the scope looks in the namespace,
+ # It is confusing because the scope appears as if it is in the namespace,
—
Reply to this email directly, view it on GitHub
<#44 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAECU2FTZUXA4FCTBFQWFD2X4SLLAVCNFSM6AAAAABXWCUPDWVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDONBUGM4DMMJWGM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
58eb199
to
7b9f68f
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 💯
Fixes #42
Fixes
ClassDefinitionInTask
, andMethodDefinitionInTask
to allow classes, modules and methods to defined inside tasks