From 406725d64d63ca59a81babdc686ee390f3a260c5 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Mon, 2 Aug 2021 15:21:45 +0200 Subject: [PATCH] Change nonsense return types to Nil in formatter classes (#10623) --- src/mime/multipart/builder.cr | 20 +++--- src/option_parser.cr | 4 +- src/pretty_print.cr | 10 +-- src/string/formatter.cr | 2 +- src/time.cr | 2 +- src/time/format/custom/iso_8601.cr | 10 +-- src/time/format/formatter.cr | 108 ++++++++++++++--------------- 7 files changed, 78 insertions(+), 78 deletions(-) diff --git a/src/mime/multipart/builder.cr b/src/mime/multipart/builder.cr index e96d6fe121b1..7e2d364680f4 100644 --- a/src/mime/multipart/builder.cr +++ b/src/mime/multipart/builder.cr @@ -41,7 +41,7 @@ module MIME::Multipart # if `#body_part` is called before this method. # # Can be called multiple times to append to the preamble multiple times. - def preamble(string : String) + def preamble(string : String) : Nil preamble { |io| string.to_s(io) } end @@ -49,7 +49,7 @@ module MIME::Multipart # if `#body_part` is called before this method. # # Can be called multiple times to append to the preamble multiple times. - def preamble(data : Bytes) + def preamble(data : Bytes) : Nil preamble { |io| io.write data } end @@ -57,7 +57,7 @@ module MIME::Multipart # Throws if `#body_part` is called before this method. # # Can be called multiple times to append to the preamble multiple times. - def preamble(preamble_io : IO) + def preamble(preamble_io : IO) : Nil preamble { |io| IO.copy(preamble_io, io) } end @@ -74,21 +74,21 @@ module MIME::Multipart # Appends a body part to the multipart message with the given *headers* # and *string*. Throws if `#finish` or `#epilogue` is called before this # method. - def body_part(headers : HTTP::Headers, string : String) + def body_part(headers : HTTP::Headers, string : String) : Nil body_part_impl(headers) { |io| string.to_s(io) } end # Appends a body part to the multipart message with the given *headers* # and *data*. Throws if `#finish` or `#epilogue` is called before this # method. - def body_part(headers : HTTP::Headers, data : Bytes) + def body_part(headers : HTTP::Headers, data : Bytes) : Nil body_part_impl(headers) { |io| io.write data } end # Appends a body part to the multipart message with the given *headers* # and data from *body_io*. Throws if `#finish` or `#epilogue` is called # before this method. - def body_part(headers : HTTP::Headers, body_io : IO) + def body_part(headers : HTTP::Headers, body_io : IO) : Nil body_part_impl(headers) { |io| IO.copy(body_io, io) } end @@ -102,7 +102,7 @@ module MIME::Multipart # Appends a body part to the multipart message with the given *headers* # and no body data. Throws is `#finish` or `#epilogue` is called before # this method. - def body_part(headers : HTTP::Headers) + def body_part(headers : HTTP::Headers) : Nil body_part_impl(headers, empty: true) { } end @@ -131,7 +131,7 @@ module MIME::Multipart # appended. # # Can be called multiple times to append to the epilogue multiple times. - def epilogue(string : String) + def epilogue(string : String) : Nil epilogue { |io| string.to_s(io) } end @@ -140,7 +140,7 @@ module MIME::Multipart # appended. # # Can be called multiple times to append to the epilogue multiple times. - def epilogue(data : Bytes) + def epilogue(data : Bytes) : Nil epilogue { |io| io.write data } end @@ -149,7 +149,7 @@ module MIME::Multipart # been appended. # # Can be called multiple times to append to the epilogue multiple times. - def epilogue(epilogue_io : IO) + def epilogue(epilogue_io : IO) : Nil epilogue { |io| IO.copy(epilogue_io, io) } end diff --git a/src/option_parser.cr b/src/option_parser.cr index a7d6727f2a21..ec3f891759e3 100644 --- a/src/option_parser.cr +++ b/src/option_parser.cr @@ -220,7 +220,7 @@ class OptionParser # before, and the flags registered after the call. # # This way, you can group the different options in an easier to read way. - def separator(message = "") + def separator(message = "") : Nil @flags << message.to_s end @@ -259,7 +259,7 @@ class OptionParser # Stops the current parse and returns immediately, leaving the remaining flags # unparsed. This is treated identically to `--` being inserted *behind* the # current parsed flag. - def stop + def stop : Nil @stop = true end diff --git a/src/pretty_print.cr b/src/pretty_print.cr index 7dbf4be6a7cf..8d13bc7577f3 100644 --- a/src/pretty_print.cr +++ b/src/pretty_print.cr @@ -63,7 +63,7 @@ class PrettyPrint end # Appends a text element. - def text(obj) + def text(obj) : Nil obj = obj.to_s width = obj.size return if width == 0 @@ -84,7 +84,7 @@ class PrettyPrint end # Appends an element that can turn into a newline if necessary. - def breakable(sep = " ") + def breakable(sep = " ") : Nil width = sep.size group = @group_stack.last if group.break? @@ -102,7 +102,7 @@ class PrettyPrint # Similar to `#breakable` except # the decision to break or not is determined individually. - def fill_breakable(sep = " ") + def fill_breakable(sep = " ") : Nil group { breakable sep } end @@ -149,7 +149,7 @@ class PrettyPrint # text "," # breakable # ``` - def comma + def comma : Nil text "," breakable end @@ -249,7 +249,7 @@ class PrettyPrint @break = false end - def break + def break : Nil @break = true end end diff --git a/src/string/formatter.cr b/src/string/formatter.cr index 55b32c1b22e4..be080bdadb3a 100644 --- a/src/string/formatter.cr +++ b/src/string/formatter.cr @@ -323,7 +323,7 @@ struct String::Formatter(A) pad size, flags end - def char(char) + def char(char) : Nil @io << char end diff --git a/src/time.cr b/src/time.cr index fd090773bebd..d85fe3f3ab03 100644 --- a/src/time.cr +++ b/src/time.cr @@ -1113,7 +1113,7 @@ struct Time # # Number of seconds decimals can be selected with *fraction_digits*. # Values accepted are 0 (the default, no decimals), 3 (milliseconds), 6 (microseconds) or 9 (nanoseconds). - def to_rfc3339(io : IO, *, fraction_digits : Int = 0) + def to_rfc3339(io : IO, *, fraction_digits : Int = 0) : Nil Format::RFC_3339.format(to_utc, io, fraction_digits) end diff --git a/src/time/format/custom/iso_8601.cr b/src/time/format/custom/iso_8601.cr index 6d1331e2ee08..3cdaa4dd33e7 100644 --- a/src/time/format/custom/iso_8601.cr +++ b/src/time/format/custom/iso_8601.cr @@ -1,19 +1,19 @@ struct Time::Format module Pattern - def date_time_iso_8601 + def date_time_iso_8601 : Nil year_month_day_iso_8601 char? 'T' time_iso_8601 end - def time_iso_8601 + def time_iso_8601 : Nil hour_minute_second_iso8601 time_zone_z_or_offset end end struct Parser - def year_month_day_iso_8601 + def year_month_day_iso_8601 : Nil year extended_format = char? '-' if current_char == 'W' @@ -58,7 +58,7 @@ struct Time::Format end end - def hour_minute_second_iso8601 + def hour_minute_second_iso8601 : Nil hour_24_zero_padded decimal_seconds = Time::SECONDS_PER_HOUR @@ -106,7 +106,7 @@ struct Time::Format end struct Formatter - def year_month_day_iso_8601 + def year_month_day_iso_8601 : Nil year_month_day end diff --git a/src/time/format/formatter.cr b/src/time/format/formatter.cr index 1abe28655104..3eafed806857 100644 --- a/src/time/format/formatter.cr +++ b/src/time/format/formatter.cr @@ -11,143 +11,143 @@ struct Time::Format def initialize(@time : Time, @io : IO) end - def year + def year : Nil pad4(time.year, '0') end - def year_modulo_100 + def year_modulo_100 : Nil pad2(time.year % 100, '0') end - def year_divided_by_100 + def year_divided_by_100 : Nil io << time.year // 100 end - def full_or_short_year + def full_or_short_year : Nil year end - def calendar_week_year + def calendar_week_year : Nil pad4(time.calendar_week[0], '0') end - def calendar_week_year_modulo100 + def calendar_week_year_modulo100 : Nil pad2(time.calendar_week[0] % 100, '0') end - def month + def month : Nil io << time.month end - def month_zero_padded + def month_zero_padded : Nil pad2 time.month, '0' end - def month_blank_padded + def month_blank_padded : Nil pad2 time.month, ' ' end - def month_name + def month_name : Nil io << get_month_name end - def month_name_upcase + def month_name_upcase : Nil io << get_month_name.upcase end - def short_month_name + def short_month_name : Nil io << get_short_month_name end - def short_month_name_upcase + def short_month_name_upcase : Nil io << get_short_month_name.upcase end - def calendar_week_week + def calendar_week_week : Nil pad2(time.calendar_week[1], '0') end - def day_of_month + def day_of_month : Nil io << time.day end - def day_of_month_zero_padded + def day_of_month_zero_padded : Nil pad2 time.day, '0' end - def day_of_month_blank_padded + def day_of_month_blank_padded : Nil pad2 time.day, ' ' end - def day_name + def day_name : Nil io << get_day_name end - def day_name_upcase + def day_name_upcase : Nil io << get_day_name.upcase end - def short_day_name + def short_day_name : Nil io << get_short_day_name end - def short_day_name_upcase + def short_day_name_upcase : Nil io << get_short_day_name.upcase end - def short_day_name_with_comma? + def short_day_name_with_comma? : Nil short_day_name char ',' whitespace end - def day_of_year_zero_padded + def day_of_year_zero_padded : Nil pad3 time.day_of_year, '0' end - def hour_24_zero_padded + def hour_24_zero_padded : Nil pad2 time.hour, '0' end - def hour_24_blank_padded + def hour_24_blank_padded : Nil pad2 time.hour, ' ' end - def hour_12_zero_padded + def hour_12_zero_padded : Nil h = (time.hour % 12) pad2 (h == 0 ? 12 : h), '0' end - def hour_12_blank_padded + def hour_12_blank_padded : Nil h = (time.hour % 12) pad2 (h == 0 ? 12 : h), ' ' end - def minute + def minute : Nil pad2 time.minute, '0' end - def second + def second : Nil pad2 time.second, '0' end - def milliseconds + def milliseconds : Nil pad3 time.millisecond, '0' end - def microseconds + def microseconds : Nil pad6 time.nanosecond // 1000, '0' end - def nanoseconds + def nanoseconds : Nil pad9 time.nanosecond, '0' end - def second_fraction + def second_fraction : Nil nanoseconds end - def second_fraction?(fraction_digits : Int = 9) + def second_fraction?(fraction_digits : Int = 9) : Nil case fraction_digits when 0 when 3 then char '.'; milliseconds @@ -158,31 +158,31 @@ struct Time::Format end end - def am_pm + def am_pm : Nil io << (time.hour < 12 ? "am" : "pm") end - def am_pm_upcase + def am_pm_upcase : Nil io << (time.hour < 12 ? "AM" : "PM") end - def day_of_week_monday_1_7 + def day_of_week_monday_1_7 : Nil io << time.day_of_week.value end - def day_of_week_sunday_0_6 + def day_of_week_sunday_0_6 : Nil io << time.day_of_week.value % 7 end - def unix_seconds + def unix_seconds : Nil io << time.to_unix end - def time_zone(with_seconds = false) + def time_zone(with_seconds = false) : Nil time_zone_offset(format_seconds: with_seconds) end - def time_zone_z_or_offset(**options) + def time_zone_z_or_offset(**options) : Nil if time.utc? io << 'Z' else @@ -194,23 +194,23 @@ struct Time::Format time.zone.format(io, with_colon: force_colon, with_seconds: format_seconds) end - def time_zone_colon(with_seconds = false) + def time_zone_colon(with_seconds = false) : Nil time_zone_offset(force_colon: true, format_seconds: with_seconds) end - def time_zone_colon_with_seconds + def time_zone_colon_with_seconds : Nil time_zone_colon(with_seconds: true) end - def time_zone_gmt + def time_zone_gmt : Nil io << "GMT" end - def time_zone_rfc2822 + def time_zone_rfc2822 : Nil time_zone_offset(allow_colon: false) end - def time_zone_gmt_or_rfc2822(**options) + def time_zone_gmt_or_rfc2822(**options) : Nil if time.utc? || time.location.name == "UT" || time.location.name == "GMT" time_zone_gmt else @@ -218,7 +218,7 @@ struct Time::Format end end - def time_zone_name(zone = false) + def time_zone_name(zone = false) : Nil if zone io << time.zone.name else @@ -226,7 +226,7 @@ struct Time::Format end end - def char(char, *alternatives) + def char(char, *alternatives) : Nil io << char end @@ -234,7 +234,7 @@ struct Time::Format char(char, *alternatives) end - def whitespace + def whitespace : Nil io << ' ' end @@ -254,28 +254,28 @@ struct Time::Format get_day_name[0, 3] end - def pad2(value, padding) + def pad2(value, padding) : Nil io.write_byte padding.ord.to_u8 if value < 10 io << value end - def pad3(value, padding) + def pad3(value, padding) : Nil io.write_byte padding.ord.to_u8 if value < 100 pad2 value, padding end - def pad4(value, padding) + def pad4(value, padding) : Nil io.write_byte padding.ord.to_u8 if value < 1000 pad3 value, padding end - def pad6(value, padding) + def pad6(value, padding) : Nil io.write_byte padding.ord.to_u8 if value < 100000 io.write_byte padding.ord.to_u8 if value < 10000 pad4 value, padding end - def pad9(value, padding) + def pad9(value, padding) : Nil io.write_byte padding.ord.to_u8 if value < 100000000 io.write_byte padding.ord.to_u8 if value < 10000000 io.write_byte padding.ord.to_u8 if value < 1000000