Skip to content

Commit 96c47b4

Browse files
authored
Add type restrictions to CSV (#15695)
1 parent 64a773a commit 96c47b4

File tree

7 files changed

+9
-9
lines changed

7 files changed

+9
-9
lines changed

src/csv.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class CSV
113113
# rows.next # => ["one", "two"]
114114
# rows.next # => ["three"]
115115
# ```
116-
def self.each_row(string_or_io : String | IO, separator : Char = DEFAULT_SEPARATOR, quote_char : Char = DEFAULT_QUOTE_CHAR)
116+
def self.each_row(string_or_io : String | IO, separator : Char = DEFAULT_SEPARATOR, quote_char : Char = DEFAULT_QUOTE_CHAR) : Iterator(Array(String))
117117
Parser.new(string_or_io, separator, quote_char).each_row
118118
end
119119

@@ -174,7 +174,7 @@ class CSV
174174
# Headers are always stripped.
175175
#
176176
# See `CSV.parse` about the *separator* and *quote_char* arguments.
177-
def initialize(string_or_io : String | IO, headers = false, @strip = false, separator : Char = DEFAULT_SEPARATOR, quote_char : Char = DEFAULT_QUOTE_CHAR)
177+
def initialize(string_or_io : String | IO, headers : Bool = false, @strip : Bool = false, separator : Char = DEFAULT_SEPARATOR, quote_char : Char = DEFAULT_QUOTE_CHAR)
178178
@parser = Parser.new(string_or_io, separator, quote_char)
179179
if headers
180180
headers = @parser.next_row || ([] of String)

src/csv/builder.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class CSV::Builder
8181
end
8282

8383
# :nodoc:
84-
def quote_cell(value : String)
84+
def quote_cell(value : String) : Nil
8585
append_cell do
8686
@io << @quote_char
8787
value.each_char do |char|

src/csv/error.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class CSV
1010
getter line_number : Int32
1111
getter column_number : Int32
1212

13-
def initialize(message, @line_number, @column_number)
13+
def initialize(message : String, @line_number : Int32, @column_number : Int32)
1414
super("#{message} at line #{@line_number}, column #{@column_number}")
1515
end
1616
end

src/csv/lexer.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ require "csv"
1515
# ```
1616
abstract class CSV::Lexer
1717
# Creates a CSV lexer from a `String`.
18-
def self.new(string : String, separator = DEFAULT_SEPARATOR, quote_char = DEFAULT_QUOTE_CHAR)
18+
def self.new(string : String, separator : Char = DEFAULT_SEPARATOR, quote_char : Char = DEFAULT_QUOTE_CHAR) : self
1919
StringBased.new(string, separator, quote_char)
2020
end
2121

2222
# Creates a CSV lexer from an `IO`.
23-
def self.new(io : IO, separator = DEFAULT_SEPARATOR, quote_char = DEFAULT_QUOTE_CHAR)
23+
def self.new(io : IO, separator : Char = DEFAULT_SEPARATOR, quote_char : Char = DEFAULT_QUOTE_CHAR) : self
2424
IOBased.new(io, separator, quote_char)
2525
end
2626

src/csv/lexer/io_based.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ require "csv"
22

33
# :nodoc:
44
class CSV::Lexer::IOBased < CSV::Lexer
5-
def initialize(@io : IO, separator = DEFAULT_SEPARATOR, quote_char = DEFAULT_QUOTE_CHAR)
5+
def initialize(@io : IO, separator : Char = DEFAULT_SEPARATOR, quote_char : Char = DEFAULT_QUOTE_CHAR)
66
super(separator, quote_char)
77
@current_char = @io.read_char || '\0'
88
end

src/csv/lexer/string_based.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ require "csv"
22

33
# :nodoc:
44
class CSV::Lexer::StringBased < CSV::Lexer
5-
def initialize(string, separator = DEFAULT_SEPARATOR, quote_char = DEFAULT_QUOTE_CHAR)
5+
def initialize(string : String, separator : Char = DEFAULT_SEPARATOR, quote_char : Char = DEFAULT_QUOTE_CHAR)
66
super(separator, quote_char)
77
@reader = Char::Reader.new(string)
88
if @reader.current_char == '\n'

src/csv/parser.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class CSV::Parser
2727
end
2828

2929
# Returns an `Iterator` of `Array(String)` for the remaining rows.
30-
def each_row
30+
def each_row : Iterator(Array(String))
3131
RowIterator.new(self)
3232
end
3333

0 commit comments

Comments
 (0)