Skip to content

Commit

Permalink
Make Style/AccessModifierDeclarations disabled by default
Browse files Browse the repository at this point in the history
Follow up of rubocop#5953, rubocop#6032

I think it is too difficult to enforce `group` (default) style
by default because it doesn't work for some methods.

For example, `def_delegator` doesn't work when using `group` style:

```ruby
require 'forwardable'

class Cat
  def meow
    puts "Meow!"
  end
end

class CatCage
  extend Forwardable

  def initialize(cat)
    @cat = cat
  end

  private

  def_delegator :@cat, :meow
end
```

```
[8] pry(main)> CatCage.new(Cat.new).meow
Meow!
=> nil
```

This is because `def_delegator` defines a method by `self.module_eval`.
Forcing group styles by default may be misleading for the above problems.

Maybe it is needed to add such methods to the whitelist and exclude
them from inspection, but it seems to be difficult for me.

First of all, I think it should make this cop disabled by default
and help users confused by this cop. WDYT? @brandonweiss
  • Loading branch information
wata727 committed Jul 1, 2018
1 parent 466d288 commit a290da0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -30,6 +30,7 @@
* [#5990](https://github.com/bbatsov/rubocop/pull/5990): Drop support for MRI 2.1. ([@drenmi][])
* [#3299](https://github.com/bbatsov/rubocop/issues/3299): `Lint/UselessAccessModifier` now warns when `private_class_method` is used without arguments. ([@Darhazer][])
* [#6026](https://github.com/rubocop-hq/rubocop/pull/6026): Exclude `refine` by default from `Metrics/BlockLength` cop. ([@kddeisz][])
* [#6066](https://github.com/rubocop-hq/rubocop/pull/6066): Make `Style/AccessModifierDeclarations` disabled by default. ([@wata727][])

## 0.57.2 (2018-06-12)

Expand Down
4 changes: 4 additions & 0 deletions config/disabled.yml
Expand Up @@ -52,6 +52,10 @@ Rails/SaveBang:
StyleGuide: 'https://github.com/rubocop-hq/rails-style-guide#save-bang'
Enabled: false

Style/AccessModifierDeclarations:
Description: 'Checks style of how access modifiers are used.'
Enabled: false

Style/AutoResourceCleanup:
Description: 'Suggests the usage of an auto resource cleanup version of a method (if available).'
Enabled: false
Expand Down
4 changes: 0 additions & 4 deletions config/enabled.yml
Expand Up @@ -1336,10 +1336,6 @@ Security/YAMLLoad:

#################### Style ###############################

Style/AccessModifierDeclarations:
Description: 'Checks style of how access modifiers are used.'
Enabled: true

Style/Alias:
Description: 'Use alias instead of alias_method.'
StyleGuide: '#alias-method'
Expand Down
2 changes: 1 addition & 1 deletion manual/cops_style.md
Expand Up @@ -4,7 +4,7 @@

Enabled by default | Supports autocorrection
--- | ---
Enabled | No
Disabled | No

Access modifiers should be declared to apply to a group of methods
or inline before each method, depending on configuration.
Expand Down

0 comments on commit a290da0

Please sign in to comment.