Skip to content

Commit

Permalink
Merge pull request #147 from floatpays/master
Browse files Browse the repository at this point in the history
Format project to fix warnings for Elixir 1.17
  • Loading branch information
xou committed Aug 7, 2024
2 parents 9b34729 + e598596 commit d24fa38
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 50 deletions.
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config
import Mix.Config

# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
Expand Down
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
13 changes: 7 additions & 6 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
%{
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
"credo": {:hex, :credo, "1.7.3", "05bb11eaf2f2b8db370ecaa6a6bda2ec49b2acd5e0418bc106b73b07128c0436", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "35ea675a094c934c22fb1dca3696f3c31f2728ae6ef5a53b5d648c11180a4535"},
"credo": {:hex, :credo, "1.7.6", "b8f14011a5443f2839b04def0b252300842ce7388f3af177157c86da18dfbeea", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "146f347fb9f8cbc5f7e39e3f22f70acbef51d441baa6d10169dd604bfbc55296"},
"dialyxir": {:hex, :dialyxir, "1.4.3", "edd0124f358f0b9e95bfe53a9fcf806d615d8f838e2202a9f430d59566b6b53b", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "bf2cfb75cd5c5006bec30141b131663299c661a864ec7fbbc72dfa557487a986"},
"earmark": {:hex, :earmark, "1.3.1", "73812f447f7a42358d3ba79283cfa3075a7580a3a2ed457616d6517ac3738cb9", [:mix], [], "hexpm", "000aaeff08919e95e7aea13e4af7b2b9734577b3e6a7c50ee31ee88cab6ec4fb"},
"earmark_parser": {:hex, :earmark_parser, "1.4.12", "b245e875ec0a311a342320da0551da407d9d2b65d98f7a9597ae078615af3449", [:mix], [], "hexpm", "711e2cc4d64abb7d566d43f54b78f7dc129308a63bc103fbd88550d2174b3160"},
"earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.23.0", "a069bc9b0bf8efe323ecde8c0d62afc13d308b1fa3d228b65bca5cf8703a529d", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "f5e2c4702468b2fd11b10d39416ddadd2fcdd173ba2a0285ebd92c39827a5a16"},
"ex_doc": {:hex, :ex_doc, "0.34.0", "ab95e0775db3df71d30cf8d78728dd9261c355c81382bcd4cefdc74610bef13e", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "60734fb4c1353f270c3286df4a0d51e65a2c1d9fba66af3940847cc65a8066d7"},
"excheck": {:hex, :excheck, "0.6.0", "f8595a8ac2c0abc0d060c1a4fce7d26f41574543366a52d5f3c84de30a69747b", [:mix], [], "hexpm", "50a94eb60e79c886be425af6b6f09c8055556ff8ad00e474dba72172574b8d28"},
"file_system": {:hex, :file_system, "1.0.0", "b689cc7dcee665f774de94b5a832e578bd7963c8e637ef940cd44327db7de2cd", [:mix], [], "hexpm", "6752092d66aec5a10e662aefeed8ddb9531d79db0bc145bb8c40325ca1d8536d"},
"jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"},
"libgraph": {:hex, :libgraph, "0.16.0", "3936f3eca6ef826e08880230f806bfea13193e49bf153f93edcf0239d4fd1d07", [:mix], [], "hexpm", "41ca92240e8a4138c30a7e06466acc709b0cbb795c643e9e17174a178982d6bf"},
"makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"},
"makeup_elixir": {:hex, :makeup_elixir, "0.15.1", "b5888c880d17d1cc3e598f05cdb5b5a91b7b17ac4eaf5f297cb697663a1094dd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "db68c173234b07ab2a07f645a5acdc117b9f99d69ebf521821d89690ae6c6ec8"},
"nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"},
"makeup": {:hex, :makeup, "1.1.2", "9ba8837913bdf757787e71c1581c21f9d2455f4dd04cfca785c70bbfff1a76a3", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cce1566b81fbcbd21eca8ffe808f33b221f9eee2cbc7a1706fc3da9ff18e6cac"},
"makeup_elixir": {:hex, :makeup_elixir, "0.16.2", "627e84b8e8bf22e60a2579dad15067c755531fea049ae26ef1020cad58fe9578", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "41193978704763f6bbe6cc2758b84909e62984c7752b3784bd3c218bb341706b"},
"makeup_erlang": {:hex, :makeup_erlang, "1.0.0", "6f0eff9c9c489f26b69b61440bf1b238d95badae49adac77973cbacae87e3c2e", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "ea7a9307de9d1548d2a72d299058d1fd2339e3d398560a0e46c27dab4891e4d2"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
"propcheck": {:hex, :propcheck, "1.4.1", "c12908dbe6f572032928548089b34ff9d40672d5d70f1562e3a9e9058d226cc9", [:mix], [{:libgraph, "~> 0.13", [hex: :libgraph, repo: "hexpm", optional: false]}, {:proper, "~> 1.4", [hex: :proper, repo: "hexpm", optional: false]}], "hexpm", "e1b088f574785c3c7e864da16f39082d5599b3aaf89086d3f9be6adb54464b19"},
"proper": {:hex, :proper, "1.4.0", "89a44b8c39d28bb9b4be8e4d715d534905b325470f2e0ec5e004d12484a79434", [:rebar3], [], "hexpm", "18285842185bd33efbda97d134a5cb5a0884384db36119fee0e3cfa488568cbb"},
"triq": {:hex, :triq, "1.3.0", "d9ed60f3cd2b6bacbb721bc9873e67e07b02e5b97c63d40db35b12670a7f1bf4", [:rebar3], [], "hexpm", "e01eb99fc53099ded985bb0c629ea0d2b0bfcf5b9a4178e0a93b08dbe51aa8cd"},
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 d24fa38

Please sign in to comment.