Skip to content
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

nested modules/classes syntax cop #868

Closed
geniou opened this issue Mar 11, 2014 · 7 comments
Closed

nested modules/classes syntax cop #868

geniou opened this issue Mar 11, 2014 · 7 comments

Comments

@geniou
Copy link
Contributor

geniou commented Mar 11, 2014

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.

@terlar
Copy link

terlar commented Mar 11, 2014

Sounds like a good idea 👍

@bbatsov
Copy link
Collaborator

bbatsov commented Mar 11, 2014

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.

@geniou
Copy link
Contributor Author

geniou commented Mar 11, 2014

Fell free to take a look at the new ClassAndModuleChildrenNested cop and let me know what you think about.

@geniou geniou closed this as completed Mar 16, 2014
@gshaw
Copy link

gshaw commented May 6, 2014

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.

@jonas054
Copy link
Collaborator

jonas054 commented May 6, 2014

@gshaw I happened to see this on Twitter the other day.

@gshaw
Copy link

gshaw commented May 6, 2014

@jonas054 👍 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

@justin808
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants