Rubocop: Style/BisectedAttrAccessor doesn't respect public/private

Created on 7 Jul 2020  路  5Comments  路  Source: rubocop-hq/rubocop

Is your feature request related to a problem? Please describe.

Often times I only want to make the attr_reader public, but still define the attr_writer privately for internal use. However, with this cop enabled (especially with autocorrect turned on) this totally changes the access rules and therefore the API of the class.

Describe the solution you'd like

I have no idea how easy this would be to implement, but it would be great if the cop could only "fire" (is that the correct term?) if the reader and writer have the same access level, i.e. both public, private, or protected.

bug

All 5 comments

Dup with #8253.

Ah, the above comment is my mistaken. this is a different cop that is similar to Style/AccessorGrouping cop.

Also just run into it when upgraded rubocop version.

Basic example:

class A
  attr_reader :q

  private

  attr_writer :q
end
qwe.rb:2:15: C: Style/BisectedAttrAccessor: Combine both accessors into attr_accessor :q.
  attr_reader :q
              ^^
qwe.rb:6:15: C: Style/BisectedAttrAccessor: Combine both accessors into attr_accessor :q.
  attr_writer :q
              ^^

@koic could you reopen it?

Will look into this.

Was this page helpful?
0 / 5 - 0 ratings