You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now that Zeitwerk is out, I prefer defining classes in a single line -- namespace and all.
# OLD (Bad)namespaceMyModuleclassMyPrimaryClassendend# NEW (Good)classMyModule::MyPrimaryClassend
Sometimes, however, I want to be able to define a minor, sibling class on the current namespace without creating a new file.
# Old Way (Bad -- non-collapsed namespace/class)namespaceMyModule# Defines: MyModule::MyPrimaryClass (Good)classMyPrimaryClassend# Defines: MyModule::MySiblingClass (Good)classMySiblingClassendend# New Way (Good -- collapsed namespace/class)classMyModule::MyPrimaryClass# Bad# - Don't want this, because it defines a sub-class, not a sibling class: # MyModule::MyPrimaryClass::MySiblingClassclassMySiblingClassend# Good# - Defines the intended sibling class: MyModule::MySiblingClassclassmodule_parent::MySiblingClassendend
Expected behavior
The Naming/ClassAndModuleCamelCase cop should allow module_parent::MySiblingClass since this is valid syntax that produces the wanted result and since module_parent is a class method and is not (nor is intended to be) a constant name.
Perhaps the cop can allow a few keywords that aren't camel-cased as part of a class name? Namely module_parent. (I'm not sure if others would be relevant here.)
This fix, if accepted, might add the following to the documentation for this cop:
# goodclassmodule_parent::MyClassend
Actual behavior
Offense raised on this line class module_parent::MySiblingClass:
Naming/ClassAndModuleCamelCase: Use CamelCase for classes and modules. (https://rubystyle.guide#camelcase-classes)
Naming/ClassAndModuleCamelCase: Use CamelCase for classes and modules. (https://rubystyle.guide#camelcase-classes)
Now that Zeitwerk is out, I prefer defining classes in a single line -- namespace and all.
Sometimes, however, I want to be able to define a minor, sibling class on the current namespace without creating a new file.
Expected behavior
The Naming/ClassAndModuleCamelCase cop should allow
module_parent::MySiblingClass
since this is valid syntax that produces the wanted result and sincemodule_parent
is a class method and is not (nor is intended to be) a constant name.Perhaps the cop can allow a few keywords that aren't camel-cased as part of a class name? Namely
module_parent
. (I'm not sure if others would be relevant here.)This fix, if accepted, might add the following to the documentation for this cop:
Actual behavior
Offense raised on this line
class module_parent::MySiblingClass
:Steps to reproduce the problem
rubocop app/models/my_module/my_primary_class.rb
RuboCop version
The text was updated successfully, but these errors were encountered: