diff --git a/src/big/json.cr b/src/big/json.cr index 44d4ba6726dc..26682c6e3698 100644 --- a/src/big/json.cr +++ b/src/big/json.cr @@ -3,7 +3,7 @@ require "big" class JSON::Builder # Writes a big decimal. - def number(number : BigDecimal) + def number(number : BigDecimal) : Nil scalar do @io << number end @@ -26,7 +26,7 @@ struct BigInt to_s end - def to_json(json : JSON::Builder) + def to_json(json : JSON::Builder) : Nil json.number(self) end end @@ -56,7 +56,7 @@ struct BigFloat to_s end - def to_json(json : JSON::Builder) + def to_json(json : JSON::Builder) : Nil json.number(self) end end @@ -86,7 +86,7 @@ struct BigDecimal to_s end - def to_json(json : JSON::Builder) + def to_json(json : JSON::Builder) : Nil json.number(self) end end diff --git a/src/compiler/crystal/tools/doc/type.cr b/src/compiler/crystal/tools/doc/type.cr index faa09f51bf50..e435b52e74ce 100644 --- a/src/compiler/crystal/tools/doc/type.cr +++ b/src/compiler/crystal/tools/doc/type.cr @@ -786,7 +786,7 @@ class Crystal::Doc::Type builder.field "full_name", full_name builder.field "name", name builder.field "abstract", abstract? - builder.field "superclass" { superclass.try(&.to_json_simple(builder)) || builder.scalar(nil) } + builder.field "superclass" { (s = superclass) ? s.to_json_simple(builder) : builder.null } builder.field "ancestors" do builder.array do ancestors.each &.to_json_simple(builder) @@ -821,7 +821,7 @@ class Crystal::Doc::Type including_types.each &.to_json_simple(builder) end end - builder.field "namespace" { namespace.try(&.to_json_simple(builder)) || builder.scalar(nil) } + builder.field "namespace" { (n = namespace) ? n.to_json_simple(builder) : builder.null } builder.field "doc", doc builder.field "summary", formatted_summary builder.field "class_methods", class_methods diff --git a/src/json/builder.cr b/src/json/builder.cr index 49af4b7bdb6d..65b10fc03c10 100644 --- a/src/json/builder.cr +++ b/src/json/builder.cr @@ -28,7 +28,7 @@ class JSON::Builder end # Starts a document. - def start_document + def start_document : Nil case state = @state.last when StartState @state[-1] = DocumentStartState.new @@ -62,28 +62,28 @@ class JSON::Builder end # Writes a `null` value. - def null + def null : Nil scalar do @io << "null" end end # Writes a boolean value. - def bool(value : Bool) + def bool(value : Bool) : Nil scalar do @io << value end end # Writes an integer. - def number(number : Int) + def number(number : Int) : Nil scalar do @io << number end end # Writes a float. - def number(number : Float) + def number(number : Float) : Nil scalar do case number when .nan? @@ -100,7 +100,7 @@ class JSON::Builder # by invoking `to_s` on it. # # This method can also be used to write the name of an object field. - def string(value) + def string(value) : Nil string = value.to_s scalar(string: true) do @@ -157,14 +157,14 @@ class JSON::Builder # the IO without processing. This is the only method that # might lead to invalid JSON being generated, so you must # be sure that *string* contains a valid JSON string. - def raw(string : String) + def raw(string : String) : Nil scalar do @io << string end end # Writes the start of an array. - def start_array + def start_array : Nil start_scalar increase_indent @state.push ArrayState.new(empty: true) @@ -172,7 +172,7 @@ class JSON::Builder end # Writes the end of an array. - def end_array + def end_array : Nil case state = @state.last when ArrayState @state.pop @@ -193,7 +193,7 @@ class JSON::Builder end # Writes the start of an object. - def start_object + def start_object : Nil start_scalar increase_indent @state.push ObjectState.new(empty: true, name: true) @@ -201,7 +201,7 @@ class JSON::Builder end # Writes the end of an object. - def end_object + def end_object : Nil case state = @state.last when ObjectState unless state.name @@ -235,12 +235,12 @@ class JSON::Builder end # :ditto: - def scalar(value : Int | Float) + def scalar(value : Int | Float) : Nil number(value) end # :ditto: - def scalar(value : String) + def scalar(value : String) : Nil string(value) end diff --git a/src/json/pull_parser.cr b/src/json/pull_parser.cr index 2f3758d99d3f..7258d6d958f0 100644 --- a/src/json/pull_parser.cr +++ b/src/json/pull_parser.cr @@ -265,7 +265,7 @@ class JSON::PullParser # Reads the new value and fill the a JSONĀ builder with it. # # Use this method with a `JSON::Builder` to read a JSON while building another one. - def read_raw(json) + def read_raw(json) : Nil case @kind when .null? read_next @@ -558,7 +558,7 @@ class JSON::PullParser # # It skips the whole value, not only the next lexer's token. # For example if the next value is an array, the whole array will be skipped. - def skip + def skip : Nil @lexer.skip = true skip_internal @lexer.skip = false diff --git a/src/json/to_json.cr b/src/json/to_json.cr index 0c0bcf482367..2b3224529e84 100644 --- a/src/json/to_json.cr +++ b/src/json/to_json.cr @@ -25,7 +25,7 @@ class Object end struct Nil - def to_json(json : JSON::Builder) + def to_json(json : JSON::Builder) : Nil json.null end @@ -35,13 +35,13 @@ struct Nil end struct Bool - def to_json(json : JSON::Builder) + def to_json(json : JSON::Builder) : Nil json.bool(self) end end struct Int - def to_json(json : JSON::Builder) + def to_json(json : JSON::Builder) : Nil json.number(self) end @@ -51,7 +51,7 @@ struct Int end struct Float - def to_json(json : JSON::Builder) + def to_json(json : JSON::Builder) : Nil json.number(self) end @@ -61,7 +61,7 @@ struct Float end class String - def to_json(json : JSON::Builder) + def to_json(json : JSON::Builder) : Nil json.string(self) end @@ -71,7 +71,7 @@ class String end struct Path - def to_json(json : JSON::Builder) + def to_json(json : JSON::Builder) : Nil @name.to_json(json) end @@ -81,7 +81,7 @@ struct Path end struct Symbol - def to_json(json : JSON::Builder) + def to_json(json : JSON::Builder) : Nil json.string(to_s) end @@ -91,7 +91,7 @@ struct Symbol end class Array - def to_json(json : JSON::Builder) + def to_json(json : JSON::Builder) : Nil json.array do each &.to_json(json) end @@ -99,7 +99,7 @@ class Array end class Deque - def to_json(json : JSON::Builder) + def to_json(json : JSON::Builder) : Nil json.array do each &.to_json(json) end @@ -107,7 +107,7 @@ class Deque end struct Set - def to_json(json : JSON::Builder) + def to_json(json : JSON::Builder) : Nil json.array do each &.to_json(json) end @@ -120,7 +120,7 @@ class Hash # Keys are serialized by invoking `to_json_object_key` on them. # Values are serialized with the usual `to_json(json : JSON::Builder)` # method. - def to_json(json : JSON::Builder) + def to_json(json : JSON::Builder) : Nil json.object do each do |key, value| json.field key.to_json_object_key do @@ -132,7 +132,7 @@ class Hash end struct Tuple - def to_json(json : JSON::Builder) + def to_json(json : JSON::Builder) : Nil json.array do {% for i in 0...T.size %} self[{{i}}].to_json(json) @@ -154,7 +154,7 @@ struct NamedTuple end struct Time::Format - def to_json(value : Time, json : JSON::Builder) + def to_json(value : Time, json : JSON::Builder) : Nil format(value).to_json(json) end end @@ -263,7 +263,7 @@ struct Time # a time value. # # See `#from_json` for reference. - def to_json(json : JSON::Builder) + def to_json(json : JSON::Builder) : Nil json.string(Time::Format::RFC_3339.format(self, fraction_digits: 0)) end end @@ -343,7 +343,7 @@ end # person.to_json # => %({"birth_date":1459859781}) # ``` module Time::EpochConverter - def self.to_json(value : Time, json : JSON::Builder) + def self.to_json(value : Time, json : JSON::Builder) : Nil json.number(value.to_unix) end end @@ -367,7 +367,7 @@ end # timestamp.to_json # => %({"value":1459860483856}) # ``` module Time::EpochMillisConverter - def self.to_json(value : Time, json : JSON::Builder) + def self.to_json(value : Time, json : JSON::Builder) : Nil json.number(value.to_unix_ms) end end @@ -394,7 +394,7 @@ end # raw.to_json # => %({"value":123456789876543212345678987654321}) # ``` module String::RawConverter - def self.to_json(value : String, json : JSON::Builder) + def self.to_json(value : String, json : JSON::Builder) : Nil json.raw(value) end end diff --git a/src/oauth2/access_token/bearer.cr b/src/oauth2/access_token/bearer.cr index 9e5a5c0148d3..c586dbb2cd47 100644 --- a/src/oauth2/access_token/bearer.cr +++ b/src/oauth2/access_token/bearer.cr @@ -13,7 +13,7 @@ class OAuth2::AccessToken::Bearer < OAuth2::AccessToken request.headers["Authorization"] = "Bearer #{access_token}" end - def to_json(json : JSON::Builder) + def to_json(json : JSON::Builder) : Nil json.object do json.field "token_type", "bearer" json.field "access_token", access_token diff --git a/src/oauth2/access_token/mac.cr b/src/oauth2/access_token/mac.cr index 670b57357662..6f7a8f44cbf4 100644 --- a/src/oauth2/access_token/mac.cr +++ b/src/oauth2/access_token/mac.cr @@ -45,7 +45,7 @@ class OAuth2::AccessToken::Mac < OAuth2::AccessToken Base64.strict_encode OpenSSL::HMAC.digest(digest, mac_key, normalized_request_string) end - def to_json(json : JSON::Builder) + def to_json(json : JSON::Builder) : Nil json.object do json.field "token_type", "mac" json.field "access_token", access_token diff --git a/src/uuid/json.cr b/src/uuid/json.cr index d9b56f7258ca..040668f4a6b8 100644 --- a/src/uuid/json.cr +++ b/src/uuid/json.cr @@ -32,7 +32,7 @@ struct UUID # uuid = UUID.new("87b3042b-9b9a-41b7-8b15-a93d3f17025e") # uuid.to_json # => "\"87b3042b-9b9a-41b7-8b15-a93d3f17025e\"" # ``` - def to_json(json : JSON::Builder) + def to_json(json : JSON::Builder) : Nil json.string(to_s) end diff --git a/src/yaml/any.cr b/src/yaml/any.cr index 880f0c75c330..71b6b2e2e379 100644 --- a/src/yaml/any.cr +++ b/src/yaml/any.cr @@ -312,7 +312,7 @@ struct YAML::Any raw.to_yaml(io) end - def to_json(builder : JSON::Builder) + def to_json(builder : JSON::Builder) : Nil if (raw = self.raw).is_a?(Slice) raise "Can't serialize #{raw.class} to JSON" else diff --git a/src/yaml/builder.cr b/src/yaml/builder.cr index 1e96dd5142a8..73ec669c25cf 100644 --- a/src/yaml/builder.cr +++ b/src/yaml/builder.cr @@ -61,7 +61,7 @@ class YAML::Builder end # Ends a YAML stream. - def end_stream + def end_stream : Nil emit stream_end flush end @@ -96,14 +96,14 @@ class YAML::Builder end # Starts a sequence. - def start_sequence(anchor : String? = nil, tag : String? = nil, style : YAML::SequenceStyle = YAML::SequenceStyle::ANY) + def start_sequence(anchor : String? = nil, tag : String? = nil, style : YAML::SequenceStyle = YAML::SequenceStyle::ANY) : Nil implicit = tag ? 0 : 1 emit sequence_start, get_anchor(anchor), string_to_unsafe(tag), implicit, style increase_nesting end # Ends a sequence. - def end_sequence + def end_sequence : Nil emit sequence_end decrease_nesting end @@ -115,14 +115,14 @@ class YAML::Builder end # Starts a mapping. - def start_mapping(anchor : String? = nil, tag : String? = nil, style : YAML::MappingStyle = YAML::MappingStyle::ANY) + def start_mapping(anchor : String? = nil, tag : String? = nil, style : YAML::MappingStyle = YAML::MappingStyle::ANY) : Nil implicit = tag ? 0 : 1 emit mapping_start, get_anchor(anchor), string_to_unsafe(tag), implicit, style increase_nesting end # Ends a mapping. - def end_mapping + def end_mapping : Nil emit mapping_end decrease_nesting end @@ -185,7 +185,7 @@ class YAML::Builder end # Closes the builder, freeing up resources. - def close + def close : Nil finalize @closed = true end diff --git a/src/yaml/nodes/parser.cr b/src/yaml/nodes/parser.cr index 20fd0aed550b..d63cf093196c 100644 --- a/src/yaml/nodes/parser.cr +++ b/src/yaml/nodes/parser.cr @@ -46,7 +46,7 @@ class YAML::Nodes::Parser < YAML::Parser node.start_column = @pull_parser.start_column.to_i end - def end_value(node) + def end_value(node) : Nil node.end_line = @pull_parser.end_line.to_i node.end_column = @pull_parser.end_column.to_i end @@ -72,15 +72,15 @@ class YAML::Nodes::Parser < YAML::Parser documents << document end - def add_to_document(document, node) + def add_to_document(document, node) : Nil document << node end - def add_to_sequence(sequence, node) + def add_to_sequence(sequence, node) : Nil sequence << node end - def add_to_mapping(mapping, key, value) + def add_to_mapping(mapping, key, value) : Nil mapping[key] = value end end diff --git a/src/yaml/parser.cr b/src/yaml/parser.cr index 547ff56a72e8..5b27cee2a3b9 100644 --- a/src/yaml/parser.cr +++ b/src/yaml/parser.cr @@ -157,7 +157,7 @@ abstract class YAML::Parser end # Closes this parser, freeing up resources. - def close + def close : Nil @pull_parser.close end diff --git a/src/yaml/pull_parser.cr b/src/yaml/pull_parser.cr index f24a8a5182a8..73742cb46e07 100644 --- a/src/yaml/pull_parser.cr +++ b/src/yaml/pull_parser.cr @@ -321,7 +321,7 @@ class YAML::PullParser LibYAML.yaml_event_delete(pointerof(@event)) end - def close + def close : Nil finalize @closed = true end diff --git a/src/yaml/schema/core/parser.cr b/src/yaml/schema/core/parser.cr index 0b4402b853a7..bc17ef63856d 100644 --- a/src/yaml/schema/core/parser.cr +++ b/src/yaml/schema/core/parser.cr @@ -36,15 +36,15 @@ class YAML::Schema::Core::Parser < YAML::Parser Any.new(Core.parse_scalar(@pull_parser)) end - def add_to_documents(documents, document) + def add_to_documents(documents, document) : Nil documents << document end - def add_to_document(document, node) + def add_to_document(document, node) : Nil document.as_a << node end - def add_to_sequence(sequence, node) + def add_to_sequence(sequence, node) : Nil sequence.as_a << node end diff --git a/src/yaml/schema/fail_safe.cr b/src/yaml/schema/fail_safe.cr index f309537f67b8..2518f104c447 100644 --- a/src/yaml/schema/fail_safe.cr +++ b/src/yaml/schema/fail_safe.cr @@ -50,19 +50,19 @@ module YAML::Schema::FailSafe Any.new(@pull_parser.value) end - def add_to_documents(documents, document) + def add_to_documents(documents, document) : Nil documents << document end - def add_to_document(document, node) + def add_to_document(document, node) : Nil document.as_a << node end - def add_to_sequence(sequence, node) + def add_to_sequence(sequence, node) : Nil sequence.as_a << node end - def add_to_mapping(mapping, key, value) + def add_to_mapping(mapping, key, value) : Nil mapping.as_h[key] = value end end