Skip to content

Commit 9b06446

Browse files
committed
(PUP-11993) Style/NumericLiteralPrefix
This commit enables the Style/NumericLiteralPrefix cop and fixes 74 autocorrectable offenses.
1 parent 2c892c8 commit 9b06446

File tree

30 files changed

+67
-73
lines changed

30 files changed

+67
-73
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -629,12 +629,6 @@ Style/MultipleComparison:
629629
Style/MutableConstant:
630630
Enabled: false
631631

632-
# This cop supports safe auto-correction (--auto-correct).
633-
# Configuration parameters: EnforcedOctalStyle.
634-
# SupportedOctalStyles: zero_with_o, zero_only
635-
Style/NumericLiteralPrefix:
636-
Enabled: false
637-
638632
# This cop supports safe auto-correction (--auto-correct).
639633
# Configuration parameters: Strict, AllowedNumbers.
640634
Style/NumericLiterals:

lib/puppet/daemon.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def self.close_streams
6868
Puppet.debug("Finished closing streams for daemon mode")
6969
rescue => detail
7070
Puppet.err "Could not start #{Puppet.run_mode.name}: #{detail}"
71-
Puppet::Util.replace_file("/tmp/daemonout", 0644) do |f|
71+
Puppet::Util.replace_file("/tmp/daemonout", 0o644) do |f|
7272
f.puts "Could not start #{Puppet.run_mode.name}: #{detail}"
7373
end
7474
exit(12)

lib/puppet/file_bucket/dipper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def restore(file, sum)
139139
changed = nil
140140
if Puppet::FileSystem.exist?(file_handle) and !Puppet::FileSystem.writable?(file_handle)
141141
changed = Puppet::FileSystem.stat(file_handle).mode
142-
::File.chmod(changed | 0200, file)
142+
::File.chmod(changed | 0o200, file)
143143
end
144144
::File.open(file, ::File::WRONLY | ::File::TRUNC | ::File::CREAT) { |of|
145145
of.binmode

lib/puppet/file_serving/metadata.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def group
5959
end
6060

6161
def mode
62-
@source_permissions_ignore ? 0644 : @stat.mode
62+
@source_permissions_ignore ? 0o644 : @stat.mode
6363
end
6464

6565
def_delegators :@stat, :ftype
@@ -78,7 +78,7 @@ def initialize(stat, path, source_permissions)
7878

7979
{ :owner => 'S-1-5-32-544',
8080
:group => 'S-1-0-0',
81-
:mode => 0644 }.each do |method, default_value|
81+
:mode => 0o644 }.each do |method, default_value|
8282
define_method method do
8383
return default_value
8484
end
@@ -107,7 +107,7 @@ def collect(source_permissions = nil)
107107
@ftype = stat.ftype
108108

109109
# We have to mask the mode, yay.
110-
@mode = stat.mode & 007777
110+
@mode = stat.mode & 0o07777
111111

112112
case stat.ftype
113113
when "file"

lib/puppet/file_system/file_impl.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ def replace_file(path, mode = nil)
163163
stat = lstat(path)
164164
gid = stat.gid
165165
uid = stat.uid
166-
mode ||= stat.mode & 07777
166+
mode ||= stat.mode & 0o7777
167167
rescue Errno::ENOENT
168-
mode ||= 0640
168+
mode ||= 0o640
169169
end
170170

171171
tempfile = Puppet::FileSystem::Uniquefile.new(Puppet::FileSystem.basename_string(path), Puppet::FileSystem.dir_string(path))

lib/puppet/file_system/uniquefile.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def self.open_tmp(identifier)
2929
def initialize(basename, *rest)
3030
create_tmpname(basename, *rest) do |tmpname, _n, opts|
3131
mode = File::RDWR | File::CREAT | File::EXCL
32-
perm = 0600
32+
perm = 0o600
3333
if opts
3434
mode |= opts.delete(:mode) || 0
3535
opts[:perm] = perm

lib/puppet/file_system/windows.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ def replace_file(path, mode = nil)
136136
current_sid = Puppet::Util::Windows::SID.name_to_sid(Puppet::Util::Windows::ADSI::User.current_sam_compatible_user_name) unless current_sid
137137

138138
dacl = case mode
139-
when 0644
139+
when 0o644
140140
dacl = secure_dacl(current_sid)
141141
dacl.allow(Puppet::Util::Windows::SID::BuiltinUsers, FILE_READ)
142142
dacl
143-
when 0660, 0640, 0600, 0440
143+
when 0o660, 0o640, 0o600, 0o440
144144
secure_dacl(current_sid)
145145
when nil
146146
get_dacl_from_file(path) || secure_dacl(current_sid)

lib/puppet/indirector/file_bucket_file/file.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def matches(paths_file, files_original_path)
125125
# given its possible that request.options[:bucket_path] or Puppet[:bucketdir]
126126
# contained characters in an encoding that are not represented the
127127
# same way when the bytes are decoded as UTF-8, continue using system encoding
128-
Puppet::FileSystem.open(paths_file, 0640, 'a+:external') do |f|
128+
Puppet::FileSystem.open(paths_file, 0o640, 'a+:external') do |f|
129129
path_match(f, files_original_path)
130130
end
131131
end
@@ -152,7 +152,7 @@ def path_match(file_handle, files_original_path)
152152
# existing and new backup
153153
# @api private
154154
def save_to_disk(bucket_file, files_original_path, contents_file, paths_file)
155-
Puppet::Util.withumask(0007) do
155+
Puppet::Util.withumask(0o007) do
156156
unless Puppet::FileSystem.dir_exist?(paths_file)
157157
Puppet::FileSystem.dir_mkpath(paths_file)
158158
end
@@ -161,7 +161,7 @@ def save_to_disk(bucket_file, files_original_path, contents_file, paths_file)
161161
# given its possible that request.options[:bucket_path] or Puppet[:bucketdir]
162162
# contained characters in an encoding that are not represented the
163163
# same way when the bytes are decoded as UTF-8, continue using system encoding
164-
Puppet::FileSystem.exclusive_open(paths_file, 0640, 'a+:external') do |f|
164+
Puppet::FileSystem.exclusive_open(paths_file, 0o640, 'a+:external') do |f|
165165
if Puppet::FileSystem.exist?(contents_file)
166166
if verify_identical_file(contents_file, bucket_file)
167167
# TRANSLATORS "FileBucket" should not be translated
@@ -257,7 +257,7 @@ def contents_file_matches_checksum?(contents_file, expected_checksum_data, check
257257
# @return [void]
258258
# @api private
259259
def copy_bucket_file_to_contents_file(contents_file, bucket_file)
260-
Puppet::FileSystem.replace_file(contents_file, 0440) do |of|
260+
Puppet::FileSystem.replace_file(contents_file, 0o440) do |of|
261261
# PUP-1044 writes all of the contents
262262
bucket_file.stream() do |src|
263263
FileUtils.copy_stream(src, of)

lib/puppet/indirector/json.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def save(request)
1616
filename = path(request.key)
1717
FileUtils.mkdir_p(File.dirname(filename))
1818

19-
Puppet::FileSystem.replace_file(filename, 0660) { |f| f.print to_json(request.instance).force_encoding(Encoding::BINARY) }
19+
Puppet::FileSystem.replace_file(filename, 0o660) { |f| f.print to_json(request.instance).force_encoding(Encoding::BINARY) }
2020
rescue TypeError => detail
2121
Puppet.log_exception(detail, _("Could not save %{json} %{request}: %{detail}") % { json: self.name, request: request.key, detail: detail })
2222
end

lib/puppet/indirector/msgpack.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def save(request)
2424
filename = path(request.key)
2525
FileUtils.mkdir_p(File.dirname(filename))
2626

27-
Puppet::FileSystem.replace_file(filename, 0660) { |f| f.print to_msgpack(request.instance) }
27+
Puppet::FileSystem.replace_file(filename, 0o660) { |f| f.print to_msgpack(request.instance) }
2828
rescue TypeError => detail
2929
Puppet.log_exception(detail, _("Could not save %{name} %{request}: %{detail}") % { name: self.name, request: request.key, detail: detail })
3030
end

0 commit comments

Comments
 (0)