rubocop: Drop "s" from Naming/MethodParameterName allowlist

- Most usages of this were in the `pretty_duration` method, where "s"
  is better described as "seconds" since we're calculating a duration.
- I also took the executive decision to do the same to "m" which refers
  to "minutes".
This commit is contained in:
Issy Long 2023-03-07 23:55:16 +00:00
parent 87042c0237
commit 89fb8c78e8
No known key found for this signature in database
GPG Key ID: 8247C390DADC67D4
4 changed files with 19 additions and 20 deletions

View File

@ -202,7 +202,6 @@ Naming/MethodParameterName:
"p",
"pr",
"r",
"s",
]
# Both styles are used depending on context,

View File

@ -192,20 +192,20 @@ module Kernel
end
end
def pretty_duration(s)
s = s.to_i
def pretty_duration(seconds)
seconds = seconds.to_i
res = +""
if s > 59
m = s / 60
s %= 60
res = +"#{m} #{Utils.pluralize("minute", m)}"
return res.freeze if s.zero?
if seconds > 59
minutes = seconds / 60
seconds %= 60
res = +"#{minutes} #{Utils.pluralize("minute", minutes)}"
return res.freeze if seconds.zero?
res << " "
end
res << "#{s} #{Utils.pluralize("second", s)}"
res << "#{seconds} #{Utils.pluralize("second", seconds)}"
res.freeze
end
@ -471,14 +471,14 @@ module Kernel
# preserving character encoding validity. The returned string will
# be not much longer than the specified max_bytes, though the exact
# shortfall or overrun may vary.
def truncate_text_to_approximate_size(s, max_bytes, options = {})
def truncate_text_to_approximate_size(str, max_bytes, options = {})
front_weight = options.fetch(:front_weight, 0.5)
raise "opts[:front_weight] must be between 0.0 and 1.0" if front_weight < 0.0 || front_weight > 1.0
return s if s.bytesize <= max_bytes
return str if str.bytesize <= max_bytes
glue = "\n[...snip...]\n"
max_bytes_in = [max_bytes - glue.bytesize, 1].max
bytes = s.dup.force_encoding("BINARY")
bytes = str.dup.force_encoding("BINARY")
glue_bytes = glue.encode("BINARY")
n_front_bytes = (max_bytes_in * front_weight).floor
n_back_bytes = max_bytes_in - n_front_bytes

View File

@ -23,8 +23,8 @@ module Homebrew
other =~ @text
end
def include?(s)
@text.include? s
def include?(str)
@text.include? str
end
def to_s

View File

@ -50,14 +50,14 @@ module Formatter
# so we always wrap one word before an option.
# @see https://github.com/Homebrew/brew/pull/12672
# @see https://macromates.com/blog/2006/wrapping-text-with-regular-expressions/
def format_help_text(s, width: 172)
def format_help_text(str, width: 172)
desc = OPTION_DESC_WIDTH
indent = width - desc
s.gsub(/(?<=\S) *\n(?=\S)/, " ")
.gsub(/([`>)\]]:) /, "\\1\n ")
.gsub(/^( +-.+ +(?=\S.{#{desc}}))(.{1,#{desc}})( +|$)(?!-)\n?/, "\\1\\2\n#{" " * indent}")
.gsub(/^( {#{indent}}(?=\S.{#{desc}}))(.{1,#{desc}})( +|$)(?!-)\n?/, "\\1\\2\n#{" " * indent}")
.gsub(/(.{1,#{width}})( +|$)(?!-)\n?/, "\\1\n")
str.gsub(/(?<=\S) *\n(?=\S)/, " ")
.gsub(/([`>)\]]:) /, "\\1\n ")
.gsub(/^( +-.+ +(?=\S.{#{desc}}))(.{1,#{desc}})( +|$)(?!-)\n?/, "\\1\\2\n#{" " * indent}")
.gsub(/^( {#{indent}}(?=\S.{#{desc}}))(.{1,#{desc}})( +|$)(?!-)\n?/, "\\1\\2\n#{" " * indent}")
.gsub(/(.{1,#{width}})( +|$)(?!-)\n?/, "\\1\n")
end
def url(string)