Skip to content

Commit aca2f4b

Browse files
committed
Naming/MemoizedInstanceVariableName
Because renaming memoized instance variables can be potentially dangerous, to address the Rubocop Naming/MemoizedInstanceVariableName cop, this commit excludes existing violations while enabling the cop for new code.
1 parent 81372fb commit aca2f4b

File tree

23 files changed

+54
-9
lines changed

23 files changed

+54
-9
lines changed

.rubocop.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,13 @@ Naming/ConstantName:
8484
Naming/HeredocDelimiterNaming:
8585
Enabled: false
8686

87+
# Exclude existing violations to avoid breaking changes
88+
Naming/MemoizedInstanceVariableName:
89+
Exclude:
90+
- 'lib/puppet/module_tool/applications/installer.rb'
91+
- 'lib/puppet/pops/types/type_factory.rb'
92+
- 'lib/puppet/provider/package/portage.rb'
93+
- 'lib/puppet/resource.rb'
94+
8795
Naming/MethodParameterName:
8896
Enabled: false

.rubocop_todo.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -656,11 +656,6 @@ Naming/BlockParameterName:
656656
- 'lib/puppet/util/windows/daemon.rb'
657657
- 'lib/puppet/util/windows/user.rb'
658658

659-
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
660-
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
661-
Naming/MemoizedInstanceVariableName:
662-
Enabled: false
663-
664659
# Configuration parameters: EnforcedStyle, AllowedPatterns, IgnoredPatterns.
665660
# SupportedStyles: snake_case, camelCase
666661
Naming/MethodName:

lib/puppet/etc.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def group
132132
# these fields as well. API compatible with Etc::Passwd. Because Struct.new
133133
# defines a new Class object, we memoize to avoid superfluous extra Class
134134
# instantiations.
135+
# rubocop:disable Naming/MemoizedInstanceVariableName
135136
def puppet_etc_passwd_class
136137
@password_class ||= Struct.new(*Etc::Passwd.members, *Etc::Passwd.members.map { |member| "canonical_#{member}".to_sym })
137138
end
@@ -145,6 +146,7 @@ def puppet_etc_passwd_class
145146
def puppet_etc_group_class
146147
@group_class ||= Struct.new(*Etc::Group.members, *Etc::Group.members.map { |member| "canonical_#{member}".to_sym })
147148
end
149+
# rubocop:enable Naming/MemoizedInstanceVariableName
148150

149151
# Utility method for overriding the String values of a struct returned by
150152
# the Etc module to UTF-8. Structs returned by the ruby Etc module contain

lib/puppet/forge.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ def prepare
195195
# Obtain a suitable temporary path for unpacking tarballs
196196
#
197197
# @return [Pathname] path to temporary unpacking location
198+
# rubocop:disable Naming/MemoizedInstanceVariableName
198199
def tmpdir
199200
@dir ||= Dir.mktmpdir(name, Puppet::Forge::Cache.base_path)
200201
end
@@ -204,6 +205,7 @@ def tmpfile
204205
f.binmode
205206
end
206207
end
208+
# rubocop:enable Naming/MemoizedInstanceVariableName
207209

208210
def download(uri, destination)
209211
response = @source.make_http_request(uri, destination)

lib/puppet/module_tool/applications/unpacker.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,11 @@ def move_into(dir)
9393
#
9494
# @api private
9595
# @return [String] path to temporary unpacking location
96+
# rubocop:disable Naming/MemoizedInstanceVariableName
9697
def tmpdir
9798
@dir ||= Dir.mktmpdir('tmp', Puppet::Forge::Cache.base_path)
9899
end
100+
# rubocop:enable Naming/MemoizedInstanceVariableName
99101
end
100102
end
101103
end

lib/puppet/module_tool/applications/upgrader.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,15 @@ def installed_release.priority
220220
end
221221

222222
private
223+
# rubocop:disable Naming/MemoizedInstanceVariableName
223224
def module_repository
224225
@repo ||= Puppet::Forge.new(Puppet[:module_repository])
225226
end
226227

227228
def installed_modules_source
228229
@installed ||= Puppet::ModuleTool::InstalledModules.new(@environment)
229230
end
231+
# rubocop:enable Naming/MemoizedInstanceVariableName
230232

231233
def installed_modules
232234
installed_modules_source.modules

lib/puppet/module_tool/local_tarball.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ def prepare
7676
# Obtain a suitable temporary path for unpacking tarballs
7777
#
7878
# @return [String] path to temporary unpacking location
79+
# rubocop:disable Naming/MemoizedInstanceVariableName
7980
def tmpdir
8081
@dir ||= Dir.mktmpdir('local-tarball', Puppet::Forge::Cache.base_path)
8182
end
83+
# rubocop:enable Naming/MemoizedInstanceVariableName
8284

8385
def unpack(file, destination)
8486
begin

lib/puppet/pal/json_catalog_encoder.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ def encode_resource(type, title)
6262
# or the catalog itself if filtering was not needed.
6363
# The result is cached.
6464
# @api private
65-
#
65+
# rubocop:disable Naming/MemoizedInstanceVariableName
6666
def possibly_filtered_catalog
6767
@filtered ||= (exclude_virtual ? catalog.filter { |r| r.virtual? } : catalog)
6868
end
6969
private :possibly_filtered_catalog
70+
# rubocop:enable Naming/MemoizedInstanceVariableName
7071
end
7172
end
7273
end

lib/puppet/pops/adaptable.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,11 @@ def self.type_name
188188
# Adapter#instance_var_name and then cached.
189189
# @return [String] the instance variable name for _name_
190190
# @api private
191-
#
191+
# rubocop:disable Naming/MemoizedInstanceVariableName
192192
def self.self_attr_name
193193
@attr_name_sym ||= :"@#{instance_var_name(type_name)}"
194194
end
195+
# rubocop:enable Naming/MemoizedInstanceVariableName
195196
end
196197
end
197198
end

lib/puppet/pops/evaluator/closure.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,11 @@ def return_type
135135
end
136136

137137
# @api public
138+
# rubocop:disable Naming/MemoizedInstanceVariableName
138139
def type
139140
@callable ||= create_callable_type
140141
end
142+
# rubocop:enable Naming/MemoizedInstanceVariableName
141143

142144
# @api public
143145
def params_struct

0 commit comments

Comments
 (0)