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

Cop idea: enforce a style for include, extend, prepend, etc. #3936

Closed
backus opened this issue Jan 18, 2017 · 4 comments
Closed

Cop idea: enforce a style for include, extend, prepend, etc. #3936

backus opened this issue Jan 18, 2017 · 4 comments
Labels
feature request good first issue Easy task, suitable for newcomers to the project

Comments

@backus
Copy link
Contributor

backus commented Jan 18, 2017

I see two distinct styles for mixing in modules:

Style 1

class Foo
  extend Bar
  extend Baz
  include Qux
  include Norf
  include Grault
  include Thud
end

Style 2

class Foo
  extend Bar, Baz
  include Qux, Norf, Grault, Thud
end

It would be nice to be able to enforce either of these styles

@backus backus changed the title Cop idea: enforce a style for include and extend Cop idea: enforce a style for include, extend, prepend, etc. Jan 18, 2017
@bbatsov
Copy link
Collaborator

bbatsov commented Jan 19, 2017

I agree. That's a good idea. It would also need a style guide rule.

Same applies to the attr_* family of methods, btw.

@bbatsov bbatsov added the good first issue Easy task, suitable for newcomers to the project label Jan 19, 2017
Drenmi added a commit to Drenmi/rubocop that referenced this issue Jan 29, 2017
This cop checks for grouping of `mixins` in class and `module` bodies.
By default, it enforces a separated style, i.e.:

```
class Foo
  include Bar
  include Qux
end
```

but it can be configured to enforce a grouped style as well.
@backus
Copy link
Contributor Author

backus commented Jan 30, 2017

Thanks for implementing @Drenmi!

@PikachuEXE
Copy link

Note that the grouped style reverses the ancestor order
Not sure if worth mentioning

include TestModule1
include TestModule2
#=> TestModule1 before TestModule2

include TestModule1, TestModule2
include TestModule2
#=> TestModule2 before TestModule1

# You can run this in irb:
module TestModule1; end; module TestModule2; end; 
class TestClass1; include TestModule1, TestModule2; end; TestClass1.ancestors
class TestClass2; include TestModule1; include TestModule2; end; TestClass2.ancestors

@Drenmi
Copy link
Collaborator

Drenmi commented Feb 21, 2017

@PikachuEXE: Wow. Great catch! My assumptions were totally wrong here. 😅 Patch incoming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request good first issue Easy task, suitable for newcomers to the project
Projects
None yet
Development

No branches or pull requests

4 participants