rubocop: Naming/MemoizedInstanceVariableName Cop doesn't work with methods that have a leading underscore
jekyll/convertible.rb has a private method named _renderer which memoizes using the ivar @_renderer as follows:
private
def _renderer
@_renderer ||= Jekyll::Renderer.new(site, self)
end
Expected behavior
Rubocop should not flag the above code when I configure the Naming/MemoizedInstanceVariableName with the provided directives for EnforcedStyleForLeadingUnderscores:
Actual behavior
- Configured with
EnforcedStyleForLeadingUnderscores: disallowed
Naming/MemoizedInstanceVariableName:
EnforcedStyleForLeadingUnderscores: disallowed
Offenses:
lib/jekyll/convertible.rb:244:7: C: Naming/MemoizedInstanceVariableName: Memoized variable
@_renderer does not match method name _renderer. Use @_renderer instead.
@_renderer ||= Jekyll::Renderer.new(site, self)
^^^^^^^^^^
- Configured with
EnforcedStyleForLeadingUnderscores: required
Naming/MemoizedInstanceVariableName:
EnforcedStyleForLeadingUnderscores: required
Offenses:
lib/jekyll/convertible.rb:244:7: C: Naming/MemoizedInstanceVariableName: Memoized variable
@_renderer does not match method name _renderer. Use @_renderer instead.
@_renderer ||= Jekyll::Renderer.new(site, self)
^^^^^^^^^^
- Configured with
EnforcedStyleForLeadingUnderscores: optional
Naming/MemoizedInstanceVariableName:
EnforcedStyleForLeadingUnderscores: optional
Offenses:
lib/jekyll/convertible.rb:244:7: C: Naming/MemoizedInstanceVariableName: Memoized variable
@_renderer does not match method name _renderer. Use @_renderer instead.
@_renderer ||= Jekyll::Renderer.new(site, self)
^^^^^^^^^^
All of the above scenario flags the variable @_renderer and suggests using the same variable @_renderer instead.
RuboCop version
$ rubocop -V
0.58.0
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 3
- Comments: 15 (11 by maintainers)
Commits related to this issue
- Changes to how to identify poorly named memoization This adds enhancements to #5843 based on feedback in #6084 With this change, disallowed is the keyword to disallow the use of underscore at the ... — committed to kenman345/rubocop by kenman345 6 years ago
- [Fix #6084] allow leading underscores for method names — committed to kenman345/rubocop by kenman345 6 years ago
- [Fix #6084] allow leading underscores for method names This adds enhancements to #5843 based on feedback in #6084 With this change, disallowed is the keyword to disallow the use of underscore at the... — committed to kenman345/rubocop by kenman345 6 years ago
Problem is the cop does not expect methods starting with
_.