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 #9734] Add new Style/TopLevelMethodDefinitions
cop
#9755
Conversation
baba60e
to
aa1488f
Compare
I think you can also use |
Style/GlobalMethod
copStyle/TopLevelMethodDefinitions
cop
c1294d7
to
4dedd2a
Compare
I probably wouldn't want these to be allowed anyways, but I could see an argument for allowing a ie. def MyClass.foo
# ...
end I'm fine with this being disallowed but anyone have an opinion there? |
I think it can be allowed if a receiver is explicitly specified. I think top-level methods that are implicitly declared directly to |
config/default.yml
Outdated
@@ -4632,6 +4632,11 @@ Style/TernaryParentheses: | |||
- require_parentheses_when_complex | |||
AllowSafeAssignment: true | |||
|
|||
Style/TopLevelMethodDefinitions: |
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.
Let's use singular here (Definition) to be aligned with how most of the cops are named.
You forgot to update the commit message itself. Btw, I'm thinking that it would be hard to add some check whether the file being analyzed is a script (if it has a shebang) and disable to the cop just for scripts, but probably that's an overkill at this point. |
I guess we should also document this in the Ruby style guide. I'm surprised we haven't done so already. |
@bbatsov Changed to singular and created PR for styleguide. |
Thanks! |
Closes #9734
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.