Enforce RuboCop ClassAndModuleChildren nested and forbid compact style
Description of the proposal
I propose we enforce RuboCop ClassAndModuleChildren
as nested
option.
Basically that means:
# Good
module Foo
class Bar
end
end
# Bad
class Foo::Bar
end
To my knowledge the latter is more compact and has the benefits of less indentation but it is problematic as it depends on ordering of defined modules. For example if you never define module Foo
in any file directly then the compact option will fail like:
irb(main):002:0> class Foo::Bar; end
NameError (uninitialized constant Foo)
I do see the compact option often used in Rubygems where the require
order is strictly controlled inside the gem so someone creates a gem called foo
and users can just require foo
which is an empty module file that then goes and requires all the other things after defining the module Foo
specifically. In a rails app we have less control over require order and it typically will happen that autoloader will just require things and if the wrong file is required we can end up with problems. At best, though, it usually requires us to have an empty module defined somewhere with module Foo
or we need at least one of our files to contain module Foo
which is inconsistent.
So therefore I think it's easier to just stick with the nested style at all times and forbid the compact style.
-
Mention the proposal in the next backend weekly call and the #backend channel to encourage contribution -
Proceed with the proposal once 50% of the maintainers have weighed in, and 80% of the votes are 👍 -
Once approved, mention it again in the next backend weekly call and the #backend channel