Skip to content

Commit

Permalink
Format project to fix warnings for Elixir 1.17
Browse files Browse the repository at this point in the history
  • Loading branch information
wkirschbaum committed Jun 4, 2024
1 parent 3d021eb commit e598596
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 43 deletions.
2 changes: 1 addition & 1 deletion lib/elixlsx/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ defmodule Elixlsx.Util do

to_string(
:io_lib.format(
'~4.10.0b-~2.10.0b-~2.10.0bT~2.10.0b:~2.10.0b:~2.10.0bZ',
~c"~4.10.0b-~2.10.0b-~2.10.0bT~2.10.0b:~2.10.0b:~2.10.0bZ",
[y, m, d, hours, minutes, seconds]
)
)
Expand Down
16 changes: 8 additions & 8 deletions lib/elixlsx/writer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ defmodule Elixlsx.Writer do
Returns a tuple `{'docProps/app.xml', "XML Data"}`.
"""
def get_docProps_app_xml(_) do
{'docProps/app.xml', XMLTemplates.docprops_app()}
{~c"docProps/app.xml", XMLTemplates.docprops_app()}
end

@spec get_docProps_core_xml(Workbook.t()) :: zip_tuple
def get_docProps_core_xml(workbook) do
timestamp = U.iso_timestamp(workbook.datetime)
{'docProps/core.xml', XMLTemplates.docprops_core(timestamp)}
{~c"docProps/core.xml", XMLTemplates.docprops_core(timestamp)}
end

@spec get_docProps_dir(Workbook.t()) :: list(zip_tuple)
Expand All @@ -53,7 +53,7 @@ defmodule Elixlsx.Writer do
Returns the filename `_rels/.rels` and it's content as a tuple.
"""
def get__rels_dotrels(_) do
{'_rels/.rels', XMLTemplates.rels_dotrels()}
{~c"_rels/.rels", XMLTemplates.rels_dotrels()}
end

@spec get__rels_dir(Workbook.t()) :: list(zip_tuple)
Expand All @@ -67,7 +67,7 @@ defmodule Elixlsx.Writer do
@spec get_xl_rels_dir(any, [SheetCompInfo.t()], non_neg_integer) :: list(zip_tuple)
def get_xl_rels_dir(_, sheetCompInfos, next_rId) do
[
{'xl/_rels/workbook.xml.rels',
{~c"xl/_rels/workbook.xml.rels",
~S"""
<?xml version="1.0" encoding="UTF-8"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
Expand All @@ -83,17 +83,17 @@ defmodule Elixlsx.Writer do

@spec get_xl_styles_xml(WorkbookCompInfo.t()) :: zip_tuple
def get_xl_styles_xml(wci) do
{'xl/styles.xml', XMLTemplates.make_xl_styles(wci)}
{~c"xl/styles.xml", XMLTemplates.make_xl_styles(wci)}
end

@spec get_xl_workbook_xml(Workbook.t(), [SheetCompInfo.t()]) :: zip_tuple
def get_xl_workbook_xml(data, sheetCompInfos) do
{'xl/workbook.xml', XMLTemplates.make_workbook_xml(data, sheetCompInfos)}
{~c"xl/workbook.xml", XMLTemplates.make_workbook_xml(data, sheetCompInfos)}
end

@spec get_xl_sharedStrings_xml(any, WorkbookCompInfo.t()) :: zip_tuple
def get_xl_sharedStrings_xml(_, wci) do
{'xl/sharedStrings.xml',
{~c"xl/sharedStrings.xml",
XMLTemplates.make_xl_shared_strings(StringDB.sorted_id_string_tuples(wci.stringdb))}
end

Expand All @@ -113,7 +113,7 @@ defmodule Elixlsx.Writer do
end

def get_contentTypes_xml(_, wci) do
{'[Content_Types].xml', XMLTemplates.make_contenttypes_xml(wci)}
{~c"[Content_Types].xml", XMLTemplates.make_contenttypes_xml(wci)}
end

def get_xl_dir(data, wci) do
Expand Down
36 changes: 9 additions & 27 deletions lib/elixlsx/xml_templates.ex
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ defmodule Elixlsx.XMLTemplates do
def make_xl_rel_sheet(sheet_comp_info) do
# I'd love to use string interpolation here, but unfortunately """< is heredoc notation, so i have to use
# string concatenation or escape all the quotes. Choosing the first.
"<Relationship Id=\"#{sheet_comp_info.rId}\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet\" Target=\"worksheets/#{
sheet_comp_info.filename
}\"/>"
"<Relationship Id=\"#{sheet_comp_info.rId}\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet\" Target=\"worksheets/#{sheet_comp_info.filename}\"/>"
end

@spec make_xl_rel_sheets(nonempty_list(SheetCompInfo.t())) :: String.t()
Expand Down Expand Up @@ -124,9 +122,7 @@ defmodule Elixlsx.XMLTemplates do
end

"""
<sheet name="#{xml_escape(sheet_info.name)}" sheetId="#{sheet_comp_info.sheetId}" state="visible" r:id="#{
sheet_comp_info.rId
}"/>
<sheet name="#{xml_escape(sheet_info.name)}" sheetId="#{sheet_comp_info.sheetId}" state="visible" r:id="#{sheet_comp_info.rId}"/>
"""
end

Expand Down Expand Up @@ -302,9 +298,7 @@ defmodule Elixlsx.XMLTemplates do

defp make_data_validation({start_cell, end_cell, values}) when is_bitstring(values) do
"""
<dataValidation type="list" allowBlank="1" showErrorMessage="1" sqref="#{start_cell}:#{
end_cell
}">
<dataValidation type="list" allowBlank="1" showErrorMessage="1" sqref="#{start_cell}:#{end_cell}">
<formula1>#{values}</formula1>
</dataValidation>
"""
Expand All @@ -319,9 +313,7 @@ defmodule Elixlsx.XMLTemplates do
|> Enum.join("&quot;&amp;&quot;")

"""
<dataValidation type="list" allowBlank="1" showErrorMessage="1" sqref="#{start_cell}:#{
end_cell
}">
<dataValidation type="list" allowBlank="1" showErrorMessage="1" sqref="#{start_cell}:#{end_cell}">
<formula1>&quot;#{joined_values}&quot;</formula1>
</dataValidation>
"""
Expand All @@ -334,11 +326,7 @@ defmodule Elixlsx.XMLTemplates do
defp xl_merge_cells(merge_cells) do
"""
<mergeCells count="#{Enum.count(merge_cells)}">
#{
Enum.map(merge_cells, fn {fromCell, toCell} ->
"<mergeCell ref=\"#{fromCell}:#{toCell}\"/>"
end)
}
#{Enum.map(merge_cells, fn {fromCell, toCell} -> "<mergeCell ref=\"#{fromCell}:#{toCell}\"/>" end)}
</mergeCells>
"""
end
Expand All @@ -348,9 +336,7 @@ defmodule Elixlsx.XMLTemplates do
Enum.zip(data, 1..length(data))
|> Enum.map_join(fn {row, rowidx} ->
"""
<row r="#{rowidx}" #{get_row_height_attr(row_heights, rowidx)}#{
get_row_grouping_attr(grouping_info, rowidx)
}>
<row r="#{rowidx}" #{get_row_height_attr(row_heights, rowidx)}#{get_row_grouping_attr(grouping_info, rowidx)}>
#{xl_sheet_cols(row, rowidx, wci)}
</row>
"""
Expand Down Expand Up @@ -423,7 +409,7 @@ defmodule Elixlsx.XMLTemplates do
outline_level_attr = if outline_level, do: " outlineLevel=\"#{outline_level}\"", else: ""
collapsed_attr = if collapsed, do: " collapsed=\"1\"", else: ""

'<col min="#{k}" max="#{k}"#{width_attr}#{hidden_attr}#{outline_level_attr}#{collapsed_attr} />'
~c'<col min="#{k}" max="#{k}"#{width_attr}#{hidden_attr}#{outline_level_attr}#{collapsed_attr} />'
end

defp make_cols(sheet) do
Expand Down Expand Up @@ -554,9 +540,7 @@ defmodule Elixlsx.XMLTemplates do
top_left_cell = U.to_excel_coords(row_idx + 1, col_idx + 1)

{"pane=\"#{pane}\"",
"<pane xSplit=\"#{col_idx}\" ySplit=\"#{row_idx}\" topLeftCell=\"#{top_left_cell}\" activePane=\"#{
pane
}\" state=\"frozen\" />"}
"<pane xSplit=\"#{col_idx}\" ySplit=\"#{row_idx}\" topLeftCell=\"#{top_left_cell}\" activePane=\"#{pane}\" state=\"frozen\" />"}

_any ->
{"", ""}
Expand All @@ -575,9 +559,7 @@ defmodule Elixlsx.XMLTemplates do

"""
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="#{len}" uniqueCount="#{
len
}">
<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="#{len}" uniqueCount="#{len}">
""" <>
Enum.map_join(stringlist, fn {_, value} ->
# the only two characters that *must* be replaced for safe XML encoding are & and <:
Expand Down
12 changes: 6 additions & 6 deletions test/elixlsx_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ defmodule ElixlsxTest do

xml = XMLTemplates.make_xl_shared_strings(StringDB.sorted_id_string_tuples(sdb))

assert xml_inner_strings(xml, '/sst/si/t') == ["Hello", "World"]
assert xml_inner_strings(xml, ~c"/sst/si/t") == ["Hello", "World"]
end

test "xml escaping StringDB functionality" do
Expand All @@ -65,7 +65,7 @@ defmodule ElixlsxTest do

xml = XMLTemplates.make_xl_shared_strings(StringDB.sorted_id_string_tuples(sdb))

assert xml_inner_strings(xml, '/sst/si/t') == ["Hello World & Goodbye Cruel World"]
assert xml_inner_strings(xml, ~c"/sst/si/t") == ["Hello World & Goodbye Cruel World"]
end

test "font color" do
Expand All @@ -75,9 +75,9 @@ defmodule ElixlsxTest do

{xmerl, []} = :xmerl_scan.string(String.to_charlist(xml))

[color] = :xmerl_xpath.string('/font/color/@rgb', xmerl)
[color] = :xmerl_xpath.string(~c"/font/color/@rgb", xmerl)

assert xmlAttribute(color, :value) == 'FF012345'
assert xmlAttribute(color, :value) == ~c"FF012345"
end

test "font name" do
Expand All @@ -87,9 +87,9 @@ defmodule ElixlsxTest do

{xmerl, []} = :xmerl_scan.string(String.to_charlist(xml))

[name] = :xmerl_xpath.string('/font/name/@val', xmerl)
[name] = :xmerl_xpath.string(~c"/font/name/@val", xmerl)

assert xmlAttribute(name, :value) == 'Arial'
assert xmlAttribute(name, :value) == ~c"Arial"
end

test "blank sheet name" do
Expand Down
1 change: 0 additions & 1 deletion test/util_test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use PropCheck

defmodule UtilTest do
Expand Down

0 comments on commit e598596

Please sign in to comment.