Skip to content

Naming/MethodName doesn't flag attr_reader / attr_writer / attr_accessor #7320

Closed
@dmolesUC

Description

@dmolesUC
Contributor

Expected behavior

Naming/MethodName should flag attr_reader, attr_writer, and attr_accessor for incorrect case.

Actual behavior

Only methods defined with explicit def statements are flagged.

Steps to reproduce the problem

Given the following code:

# Foo example
class Foo
  attr_accessor :fooBar
  attr_reader :barBaz
  attr_writer :bazQux

  def quxCorge
    'quxCorge'
  end

  def quxCorge=(_)
    raise 'not a thing'
  end
end

The Naming/MethodName cop should flag all five declarations -- fooBar, barBaz, bazQux, quxCorge, and quxCorge=

Instead, only the explicit def quxCorge and def quxCorge= are flagged:

Inspecting 1 file
C

Offenses:

/tmp/naming.rb:10:7: C: Naming/MethodName: Use snake_case for method names.
  def quxCorge
      ^^^^^^^^
/tmp/naming.rb:14:7: C: Naming/MethodName: Use snake_case for method names.
  def quxCorge=(_)
      ^^^^^^^^^

1 file inspected, 2 offenses detected

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler. Here's an example:

$ [bundle exec] rubocop -V
0.74.0 (using Parser 2.6.3.0, running on ruby 2.5.1 x86_64-darwin18)

Activity

Drenmi

Drenmi commented on Aug 30, 2019

@Drenmi
Collaborator

Good catch, @dmolesUC!

added a commit that references this issue on Oct 28, 2019

Fix rubocop#7320 support Naming/MethodName for attr_reader / attr_wri…

e6aaa5f
stale

stale commented on Feb 26, 2020

@stale

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

added
staleIssues that haven't been active in a while
on Feb 26, 2020
Drenmi

Drenmi commented on Feb 29, 2020

@Drenmi
Collaborator

Still relevant.

removed
staleIssues that haven't been active in a while
on Feb 29, 2020

5 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @koic@Drenmi@dmolesUC

    Issue actions

      Naming/MethodName doesn't flag attr_reader / attr_writer / attr_accessor · Issue #7320 · rubocop/rubocop