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

[Fix #3936] Add new Style/MixinGrouping cop #3982

Merged
merged 1 commit into from Jan 30, 2017

Conversation

Drenmi
Copy link
Collaborator

@Drenmi Drenmi commented Jan 28, 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.

It's currently Chinese New Year, so I didn't have time to add autocorrect. Will add it in at a later point, unless someone beats me to it. 😀


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Used the same coding conventions as the rest of the project.
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • All tests are passing.
  • The new code doesn't generate RuboCop offenses.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Updated cop documentation with rake generate_cops_documentation (required only when you've added a new cop or changed the configuration/documentation of an existing cop).

include ConfigurableEnforcedStyle

MIXIN_METHODS = [:extend, :include, :prepend].freeze
MSG = 'Put mixins in %s.'.freeze
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the message is a bit confusing and should definitely mention include or extend for extra clarity.

@@ -728,6 +728,12 @@ Style/MethodName:
- snake_case
- camelCase

Style/MixinGrouping:
EnforcedStyle: separated
SupportedStyles:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some explanations about the supported styles would be useful.

@bbatsov
Copy link
Collaborator

bbatsov commented Jan 29, 2017

A couple of points:

  • this needs a matching style guide rule
  • eventually we need cops for related things like attr_* and similar.

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.
@Drenmi
Copy link
Collaborator Author

Drenmi commented Jan 29, 2017

@bbatsov: Comments addressed. 😀

this needs a matching style guide rule

Opened a PR for this.

eventually we need cops for related things like attr_* and similar.

I was holding off on this one, because I didn't have time to deal with the visibility scopes of the attr_* methods, but I have opened a separate issue for it. 😀

@bbatsov bbatsov merged commit e868041 into rubocop:master Jan 30, 2017
@bbatsov
Copy link
Collaborator

bbatsov commented Jan 30, 2017

👍


# good
class Foo
include Bar

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include Bar, Qox

==

include Qox
include Bar


# good
class Foo
extend Bar, Qox

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include Bar
include Qox

==

include Qox, Bar

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

Successfully merging this pull request may close these issues.

None yet

3 participants