Basically there are two (or more) ways to nest modules/classes in ruby:
module Foo
module Bar
end
end
or
module Foo::Bar
end
What do you think a about the idea of having a cop to check the syntax of nested modules/classes. Personally I would prefer the first one. I also heard, that it has some benefits and the ruby-style-guide only use the first one.
Maybe I'm able to write such a cop, but first I wanted to know what you think about this.
Sounds like a good idea :+1:
I'd accept such a cop if it were submitted. I might even write it, but given my workload these days that might not happen soon.
Fell free to take a look at the new ClassAndModuleChildrenNested cop and let me know what you think about.
Can anybody give a specific reason why the compact form is not preferred in the Ruby style guide? It seems like if you are keeping a single class per file it keeps the code closer to the left margin rather than indenting n levels deep based on the namespace structure.
I've Googled and haven't come up with anything. What I'm looking for is a reason why I should consider moving to the longer style with more reasoning than that's the way Rails does it.
@gshaw I happened to see this on Twitter the other day.
@jonas054 :+1: for the link.
If anybody else finds this here is a gist that gives a working example regarding the tweet.
https://gist.github.com/gshaw/4adbebcba6ac954636e9
I put links to many of the articles. I'm still not convinced that compact is incorrect so long as one properly namespaces constants, and classes, rather than depending on the default lookup rules, which i think could get ambiguous. http://forum.railsonmaui.com/t/ruby-linting-class-vs-lexical-scope/253
Most helpful comment
@jonas054 :+1: for the link.
If anybody else finds this here is a gist that gives a working example regarding the tweet.
https://gist.github.com/gshaw/4adbebcba6ac954636e9