Skip to content

Commit 5ea901b

Browse files
authored
Format files using DocumentFormat
1 parent af796d2 commit 5ea901b

File tree

3 files changed

+57
-57
lines changed

3 files changed

+57
-57
lines changed

Diff for: docs/make.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
using Documenter, TableShowUtils
22

33
makedocs(
4-
modules = [TableShowUtils],
5-
sitename = "TableShowUtils.jl",
6-
analytics="UA-132838790-1",
7-
pages = [
4+
modules=[TableShowUtils],
5+
sitename="TableShowUtils.jl",
6+
analytics="UA-132838790-1",
7+
pages=[
88
"Introduction" => "index.md"
99
]
1010
)
1111

1212
deploydocs(
13-
repo = "github.com/queryverse/TableShowUtils.jl.git"
13+
repo="github.com/queryverse/TableShowUtils.jl.git"
1414
)

Diff for: src/TableShowUtils.jl

+45-45
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ function printtable(io::IO, source, typename::AbstractString; force_unknown_rows
99
if force_unknown_rows
1010
rows = nothing
1111
data = Iterators.take(source, 10) |> collect
12-
elseif Base.IteratorSize(source) isa Union{Base.HasLength, Base.HasShape{1}}
12+
elseif Base.IteratorSize(source) isa Union{Base.HasLength,Base.HasShape{1}}
1313
rows = length(source)
1414
data = Iterators.take(source, 10) |> collect
1515
else
1616
data_plus_one = Iterators.take(source, 11) |> collect
17-
if length(data_plus_one)<11
17+
if length(data_plus_one) < 11
1818
rows = length(data_plus_one)
1919
data = data_plus_one
2020
else
@@ -29,14 +29,14 @@ function printtable(io::IO, source, typename::AbstractString; force_unknown_rows
2929

3030
colnames = String.(fieldnames(eltype(source)))
3131

32-
NAvalues = [r==0 ? false : DataValues.isna(data[r][c]) for r in 0:length(data), c in 1:cols]
32+
NAvalues = [r == 0 ? false : DataValues.isna(data[r][c]) for r in 0:length(data), c in 1:cols]
3333

34-
data = [r==0 ? colnames[c] : isa(data[r][c], AbstractString) ? data[r][c] : sprint(io->show(IOContext(io, :compact => true), data[r][c])) for r in 0:length(data), c in 1:cols]
34+
data = [r == 0 ? colnames[c] : isa(data[r][c], AbstractString) ? data[r][c] : sprint(io -> show(IOContext(io, :compact => true), data[r][c])) for r in 0:length(data), c in 1:cols]
3535

36-
maxwidth = [maximum(Unicode.textwidth.(data[:,c])) for c in 1:cols]
36+
maxwidth = [maximum(Unicode.textwidth.(data[:, c])) for c in 1:cols]
3737

3838
available_heigth, available_width = displaysize(io)
39-
available_width -=1
39+
available_width -= 1
4040

4141
shortened_rows = Set{Int}()
4242

@@ -47,67 +47,67 @@ function printtable(io::IO, source, typename::AbstractString; force_unknown_rows
4747
return string(s, ' '^m)
4848
end
4949

50-
while sum(maxwidth) + (size(data,2)-1) * 3 > available_width
51-
if size(data,2)==1
52-
for r in 1:size(data,1)
53-
if length(data[r,1])>available_width
54-
data[r,1] = data[r,1][1:nextind(data[r,1], 0, available_width-2)] * "\""
50+
while sum(maxwidth) + (size(data, 2) - 1) * 3 > available_width
51+
if size(data, 2) == 1
52+
for r in 1:size(data, 1)
53+
if length(data[r, 1]) > available_width
54+
data[r, 1] = data[r, 1][1:nextind(data[r, 1], 0, available_width - 2)] * "\""
5555
push!(shortened_rows, r)
5656
end
5757
end
5858
maxwidth[1] = available_width
5959
break
6060
else
61-
data = data[:,1:end-1]
61+
data = data[:, 1:end-1]
6262

63-
maxwidth = [maximum(length.(data[:,c])) for c in 1:size(data,2)]
63+
maxwidth = [maximum(length.(data[:, c])) for c in 1:size(data, 2)]
6464
end
6565
end
6666

67-
for c in 1:size(data,2)
67+
for c in 1:size(data, 2)
6868
print(io, rpad(colnames[c], maxwidth[c]))
69-
if c<size(data,2)
69+
if c < size(data, 2)
7070
print(io, "")
7171
end
7272
end
7373
println(io)
74-
for c in 1:size(data,2)
74+
for c in 1:size(data, 2)
7575
print(io, repeat("", maxwidth[c]))
76-
if c<size(data,2)
76+
if c < size(data, 2)
7777
print(io, "─┼─")
7878
end
7979
end
80-
for r in 2:size(data,1)
80+
for r in 2:size(data, 1)
8181
println(io)
82-
for c in 1:size(data,2)
82+
for c in 1:size(data, 2)
8383

8484
if r in shortened_rows
85-
print(io, data[r,c],)
85+
print(io, data[r, c],)
8686
print(io, "")
8787
else
88-
if NAvalues[r,c]
89-
printstyled(io, rpad(data[r,c], maxwidth[c]), color=:light_black)
88+
if NAvalues[r, c]
89+
printstyled(io, rpad(data[r, c], maxwidth[c]), color=:light_black)
9090
else
91-
print(io, textwidth_based_rpad(data[r,c], maxwidth[c]))
91+
print(io, textwidth_based_rpad(data[r, c], maxwidth[c]))
9292
end
9393
end
94-
if c<size(data,2)
94+
if c < size(data, 2)
9595
print(io, "")
9696
end
9797
end
9898
end
9999

100-
if rows===nothing
100+
if rows === nothing
101101
row_post_text = "more rows"
102-
elseif rows > size(data,1)-1
102+
elseif rows > size(data, 1) - 1
103103
extra_rows = rows - 10
104104
row_post_text = "$extra_rows more $(extra_rows==1 ? "row" : "rows")"
105105
else
106106
row_post_text = ""
107107
end
108108

109-
if size(data,2)!=cols
110-
extra_cols = cols-size(data,2)
109+
if size(data, 2) != cols
110+
extra_cols = cols - size(data, 2)
111111
col_post_text = "$extra_cols more $(extra_cols==1 ? "column" : "columns"): "
112112
col_post_text *= Base.join([colnames[cols-extra_cols+1:end]...], ", ")
113113
else
@@ -116,7 +116,7 @@ function printtable(io::IO, source, typename::AbstractString; force_unknown_rows
116116

117117
if !isempty(row_post_text) || !isempty(col_post_text)
118118
println(io)
119-
print(io,"... with ")
119+
print(io, "... with ")
120120
if !isempty(row_post_text)
121121
print(io, row_post_text)
122122
end
@@ -136,11 +136,11 @@ function printHTMLtable(io, source; force_unknown_rows=false)
136136

137137
if force_unknown_rows
138138
rows = nothing
139-
elseif Base.IteratorSize(source) isa Union{Base.HasLength, Base.HasShape{1}}
139+
elseif Base.IteratorSize(source) isa Union{Base.HasLength,Base.HasShape{1}}
140140
rows = length(source)
141141
else
142-
count_needed_plus_one = Iterators.count(i->true, Iterators.take(source, max_elements+1))
143-
rows = count_needed_plus_one<max_elements+1 ? count_needed_plus_one : nothing
142+
count_needed_plus_one = Iterators.count(i -> true, Iterators.take(source, max_elements + 1))
143+
rows = count_needed_plus_one < max_elements + 1 ? count_needed_plus_one : nothing
144144
end
145145

146146
haslimit = get(io, :limit, true)
@@ -166,18 +166,18 @@ function printHTMLtable(io, source; force_unknown_rows=false)
166166
for c in values(r)
167167
print(io, "<td>")
168168
if c isa Dates.AbstractTime
169-
Markdown.htmlesc(io, sprint(io->print(IOContext(io, :compact => true),c)))
169+
Markdown.htmlesc(io, sprint(io -> print(IOContext(io, :compact => true), c)))
170170
elseif c isa DataValues.DataValue && DataValues.hasvalue(c) && c[] isa Dates.AbstractDateTime
171-
Markdown.htmlesc(io, sprint(io->print(IOContext(io, :compact => true),c[])))
171+
Markdown.htmlesc(io, sprint(io -> print(IOContext(io, :compact => true), c[])))
172172
else
173-
Markdown.htmlesc(io, sprint(io->show(IOContext(io, :compact => true),c)))
173+
Markdown.htmlesc(io, sprint(io -> show(IOContext(io, :compact => true), c)))
174174
end
175175
print(io, "</td>")
176176
end
177177
print(io, "</tr>")
178178
end
179179

180-
if rows==nothing
180+
if rows == nothing
181181
row_post_text = "... with more rows."
182182
elseif rows > max_elements
183183
extra_rows = rows - max_elements
@@ -215,38 +215,38 @@ julia_type_to_schema_type(::Type{T}) where {T<:Dates.Time} = "time"
215215
julia_type_to_schema_type(::Type{T}) where {T<:Dates.Date} = "date"
216216
julia_type_to_schema_type(::Type{T}) where {T<:Dates.DateTime} = "datetime"
217217
julia_type_to_schema_type(::Type{T}) where {T<:AbstractString} = "string"
218-
julia_type_to_schema_type(::Type{T}) where {S, T<:DataValues.DataValue{S}} = julia_type_to_schema_type(S)
218+
julia_type_to_schema_type(::Type{T}) where {S,T<:DataValues.DataValue{S}} = julia_type_to_schema_type(S)
219219

220220
own_json_formatter(io, x) = JSON.print(io, x)
221-
own_json_formatter(io, x::DataValues.DataValue) = DataValues.isna(x) ? JSON.print(io,nothing) : own_json_formatter(io, x[])
221+
own_json_formatter(io, x::DataValues.DataValue) = DataValues.isna(x) ? JSON.print(io, nothing) : own_json_formatter(io, x[])
222222

223223
function printdataresource(io::IO, source)
224224
if Base.IteratorEltype(source) isa Base.EltypeUnknown
225225
first_el = first(source)
226226
col_names = String.(propertynames(first_el))
227-
col_types = [fieldtype(typeof(first_el), i) for i=1:length(col_names)]
227+
col_types = [fieldtype(typeof(first_el), i) for i = 1:length(col_names)]
228228
else
229229
col_names = String.(fieldnames(eltype(source)))
230-
col_types = [fieldtype(eltype(source), i) for i=1:length(col_names)]
230+
col_types = [fieldtype(eltype(source), i) for i = 1:length(col_names)]
231231
end
232-
schema = Dict("fields" => [Dict("name"=>string(i[1]), "type"=>julia_type_to_schema_type(i[2])) for i in zip(col_names, col_types)])
232+
schema = Dict("fields" => [Dict("name" => string(i[1]), "type" => julia_type_to_schema_type(i[2])) for i in zip(col_names, col_types)])
233233

234234
print(io, "{")
235235
JSON.print(io, "schema")
236236
print(io, ":")
237-
JSON.print(io,schema)
238-
print(io,",")
237+
JSON.print(io, schema)
238+
print(io, ",")
239239
JSON.print(io, "data")
240240
print(io, ":[")
241241

242242
for (row_i, row) in enumerate(source)
243-
if row_i>1
243+
if row_i > 1
244244
print(io, ",")
245245
end
246246

247247
print(io, "{")
248248
for col in 1:length(col_names)
249-
if col>1
249+
if col > 1
250250
print(io, ",")
251251
end
252252
JSON.print(io, col_names[col])

Diff for: test/test_tableshowutils.jl

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@testitem "TableShowUtils" begin
22
using DataValues, Dates
33

4-
source = [(a=1,b="A"),(a=2,b="B")]
4+
source = [(a=1, b="A"), (a=2, b="B")]
55

66
@test sprint(TableShowUtils.printtable, source, "foo file") == """
77
2x2 foo file
@@ -13,15 +13,15 @@
1313
@test sprint(TableShowUtils.printHTMLtable, source) == """
1414
<table><thead><tr><th>a</th><th>b</th></tr></thead><tbody><tr><td>1</td><td>&quot;A&quot;</td></tr><tr><td>2</td><td>&quot;B&quot;</td></tr></tbody></table>"""
1515

16-
@test sprint((stream) -> TableShowUtils.printtable(stream, source, "foo file", force_unknown_rows = true)) == "?x2 foo file\na │ b\n──┼──\n1 │ A\n2 │ B\n... with more rows"
16+
@test sprint((stream) -> TableShowUtils.printtable(stream, source, "foo file", force_unknown_rows=true)) == "?x2 foo file\na │ b\n──┼──\n1 │ A\n2 │ B\n... with more rows"
1717

18-
source_with_many_columns = [(a0=1,b0=1,c0=1,a1=1,b1=1,c1=1,a2=1,b2=1,c2=1,a3=1,b3=1,c3=1,a4=1,b4=1,c4=1,a5=1,b5=1,c5=1,a6=1,b6=1,c6=1,a7=1,b7=1,c7=1,a8=1,b8=1,c8=1,a9=1,b9=1,c9=1,a10=1,b10=1,c10=1)]
18+
source_with_many_columns = [(a0=1, b0=1, c0=1, a1=1, b1=1, c1=1, a2=1, b2=1, c2=1, a3=1, b3=1, c3=1, a4=1, b4=1, c4=1, a5=1, b5=1, c5=1, a6=1, b6=1, c6=1, a7=1, b7=1, c7=1, a8=1, b8=1, c8=1, a9=1, b9=1, c9=1, a10=1, b10=1, c10=1)]
1919
@test sprint(TableShowUtils.printtable, source_with_many_columns, "foo file") == "1x33 foo file\na0 │ b0 │ c0 │ a1 │ b1 │ c1 │ a2 │ b2 │ c2 │ a3 │ b3 │ c3 │ a4 │ b4 │ c4 │ a5\n───┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼───\n1 │ 1 │ 1 │ 1 │ 1 │ 1 │ 1 │ 1 │ 1 │ 1 │ 1 │ 1 │ 1 │ 1 │ 1 │ 1 \n... with 17 more columns: b5, c5, a6, b6, c6, a7, b7, c7, a8, b8, c8, a9, b9, c9, a10, b10, c10"
2020

21-
source_with_NA = [(a=1,b="A"),(a=2,b=NA)]
21+
source_with_NA = [(a=1, b="A"), (a=2, b=NA)]
2222
@test sprint(TableShowUtils.printtable, source_with_NA, "foo file") == "2x2 foo file\na │ b \n──┼────\n1 │ A \n2 │ #NA"
2323

24-
@test sprint((stream) -> TableShowUtils.printHTMLtable(stream, source, force_unknown_rows = true)) == "<table><thead><tr><th>a</th><th>b</th></tr></thead><tbody><tr><td>1</td><td>&quot;A&quot;</td></tr><tr><td>2</td><td>&quot;B&quot;</td></tr><tr><td>&vellip;</td><td>&vellip;</td></tr></tbody></table><p>... with more rows.</p>"
24+
@test sprint((stream) -> TableShowUtils.printHTMLtable(stream, source, force_unknown_rows=true)) == "<table><thead><tr><th>a</th><th>b</th></tr></thead><tbody><tr><td>1</td><td>&quot;A&quot;</td></tr><tr><td>2</td><td>&quot;B&quot;</td></tr><tr><td>&vellip;</td><td>&vellip;</td></tr></tbody></table><p>... with more rows.</p>"
2525

2626
@test sprint(TableShowUtils.printdataresource, source) == "{\"schema\":{\"fields\":[{\"name\":\"a\",\"type\":\"integer\"},{\"name\":\"b\",\"type\":\"string\"}]},\"data\":[{\"a\":1,\"b\":\"A\"},{\"a\":2,\"b\":\"B\"}]}"
2727

@@ -38,12 +38,12 @@ end
3838
@testitem "DateTime" begin
3939
using Dates, DataValues
4040

41-
source = [(a=1,b=DateTime(2010, 5, 6)),(a=2,b=DateTime(2011, 5, 6))]
41+
source = [(a=1, b=DateTime(2010, 5, 6)), (a=2, b=DateTime(2011, 5, 6))]
4242

4343
@test sprint(TableShowUtils.printHTMLtable, source) == """
4444
<table><thead><tr><th>a</th><th>b</th></tr></thead><tbody><tr><td>1</td><td>2010-05-06T00:00:00</td></tr><tr><td>2</td><td>2011-05-06T00:00:00</td></tr></tbody></table>"""
4545

46-
source2 = [(a=1,b=DataValue(DateTime(2010, 5, 6))),(a=2,b=NA)]
46+
source2 = [(a=1, b=DataValue(DateTime(2010, 5, 6))), (a=2, b=NA)]
4747

4848
@test sprint(TableShowUtils.printHTMLtable, source2) == """
4949
<table><thead><tr><th>a</th><th>b</th></tr></thead><tbody><tr><td>1</td><td>2010-05-06T00:00:00</td></tr><tr><td>2</td><td>#NA</td></tr></tbody></table>"""

0 commit comments

Comments
 (0)