Skip to content

Commit

Permalink
Merge pull request #58 from floatpays/master
Browse files Browse the repository at this point in the history
Fix warnings for Elixir 1.16 and update Elixir version requirement
  • Loading branch information
joshnuss committed Apr 23, 2024
2 parents 5b5ae47 + 730796f commit e05a22d
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 58 deletions.
39 changes: 26 additions & 13 deletions .github/workflows/elixir.yml
Expand Up @@ -4,20 +4,33 @@ on: [push, pull_request]

jobs:
build:
name: Elixir ${{matrix.elixir}} (Erlang/OTP ${{matrix.otp}})
name: Test (${{matrix.elixir}}/${{matrix.otp}})
runs-on: ubuntu-latest
strategy:
matrix:
otp: ['22.3']
elixir: ['1.11.2', '1.10.4', '1.9.4', '1.8.2', '1.7.4', '1.6.6']
otp: [24.x, 25.x, 26.x]
elixir: [1.12.x, 1.13.x, 1.14.x, 1.15.x, 1.16.x]
exclude:
- otp: 26.x
elixir: 1.13.x
- otp: 26.x
elixir: 1.12.x
- otp: 25.x
elixir: 1.12.x
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}
- run: mix deps.get
- run: mix compile --warnings-as-errors
- run: mix format --check-formatted
- run: mix credo --strict
- run: mix test
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
- name: Restore dependencies cache
uses: actions/cache@v4
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
- run: mix deps.get
- run: mix compile --warnings-as-errors
- run: mix format --check-formatted
- run: mix credo --strict
- run: mix test
2 changes: 1 addition & 1 deletion config/config.exs
@@ -1,7 +1,7 @@
# This file is responsible for configuring your application
# and its dependencies. The Mix.Config module provides functions
# to aid in doing so.
use Mix.Config
import Config

# Note this file is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
Expand Down
54 changes: 27 additions & 27 deletions lib/xml_builder.ex
Expand Up @@ -236,21 +236,21 @@ defmodule XmlBuilder do
nil -> ""
end

['<?xml version="1.0" encoding="', to_string(encoding), ?", standalone, '?>']
[~c"<?xml version=\"1.0\" encoding=\"", to_string(encoding), ?", standalone, ~c"?>"]
end

defp format({:doctype, {:system, name, system}}, 0, _options),
do: ['<!DOCTYPE ', to_string(name), ' SYSTEM "', to_string(system), '">']
do: [~c"<!DOCTYPE ", to_string(name), ~c" SYSTEM \"", to_string(system), ~c"\">"]

defp format({:doctype, {:public, name, public, system}}, 0, _options),
do: [
'<!DOCTYPE ',
~c"<!DOCTYPE ",
to_string(name),
' PUBLIC "',
~c" PUBLIC \"",
to_string(public),
'" "',
~c"\" \"",
to_string(system),
'">'
~c"\">"
]

defp format(string, level, options) when is_bitstring(string),
Expand All @@ -268,22 +268,22 @@ defmodule XmlBuilder do

defp format({name, attrs, content}, level, options)
when is_blank_attrs(attrs) and is_blank_list(content),
do: [indent(level, options), '<', to_string(name), '/>']
do: [indent(level, options), ~c"<", to_string(name), ~c"/>"]

defp format({name, attrs, content}, level, options) when is_blank_list(content),
do: [indent(level, options), '<', to_string(name), ' ', format_attributes(attrs), '/>']
do: [indent(level, options), ~c"<", to_string(name), ~c" ", format_attributes(attrs), ~c"/>"]

defp format({name, attrs, content}, level, options)
when is_blank_attrs(attrs) and not is_list(content),
do: [
indent(level, options),
'<',
~c"<",
to_string(name),
'>',
~c">",
format_content(content, level + 1, options),
'</',
~c"</",
to_string(name),
'>'
~c">"
]

defp format({name, attrs, content}, level, options)
Expand All @@ -292,31 +292,31 @@ defmodule XmlBuilder do

[
indent(level, options),
'<',
~c"<",
to_string(name),
'>',
~c">",
format_content(content, level + 1, options),
format_char,
indent(level, options),
'</',
~c"</",
to_string(name),
'>'
~c">"
]
end

defp format({name, attrs, content}, level, options)
when not is_blank_attrs(attrs) and not is_list(content),
do: [
indent(level, options),
'<',
~c"<",
to_string(name),
' ',
~c" ",
format_attributes(attrs),
'>',
~c">",
format_content(content, level + 1, options),
'</',
~c"</",
to_string(name),
'>'
~c">"
]

defp format({name, attrs, content}, level, options)
Expand All @@ -325,17 +325,17 @@ defmodule XmlBuilder do

[
indent(level, options),
'<',
~c"<",
to_string(name),
' ',
~c" ",
format_attributes(attrs),
'>',
~c">",
format_content(content, level + 1, options),
format_char,
indent(level, options),
'</',
~c"</",
to_string(name),
'>'
~c">"
]
end

Expand Down Expand Up @@ -369,7 +369,7 @@ defmodule XmlBuilder do
defp format_attributes(attrs),
do:
map_intersperse(attrs, " ", fn {name, value} ->
[to_string(name), '=', quote_attribute_value(value)]
[to_string(name), ~c"=", quote_attribute_value(value)]
end)

defp indent(level, options) do
Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Expand Up @@ -7,7 +7,7 @@ defmodule XmlBuilder.Mixfile do
[
app: :xml_builder,
version: "2.2.0",
elixir: "~> 1.6",
elixir: "~> 1.12",
deps: deps(),
docs: docs(),
package: [
Expand All @@ -25,7 +25,7 @@ defmodule XmlBuilder.Mixfile do

defp deps do
[
{:credo, ">= 1.4.0 and < 1.5.0", only: [:dev, :test], runtime: false},
{:credo, "~> 1.7.5", only: [:dev, :test], runtime: false},
{:ex_doc, github: "elixir-lang/ex_doc", only: :dev}
]
end
Expand Down
18 changes: 10 additions & 8 deletions mix.lock
@@ -1,11 +1,13 @@
%{
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"},
"credo": {:hex, :credo, "1.4.1", "16392f1edd2cdb1de9fe4004f5ab0ae612c92e230433968eab00aafd976282fc", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "155f8a2989ad77504de5d8291fa0d41320fdcaa6a1030472e9967f285f8c7692"},
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
"credo": {:hex, :credo, "1.7.5", "643213503b1c766ec0496d828c90c424471ea54da77c8a168c725686377b9545", [: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", "f799e9b5cd1891577d8c773d245668aa74a2fcd15eb277f51a0131690ebfb3fd"},
"earmark": {:hex, :earmark, "1.4.0", "397e750b879df18198afc66505ca87ecf6a96645545585899f6185178433cc09", [:mix], [], "hexpm", "4bedcec35de03b5f559fd2386be24d08f7637c374d3a85d3fe0911eecdae838a"},
"earmark_parser": {:hex, :earmark_parser, "1.4.10", "6603d7a603b9c18d3d20db69921527f82ef09990885ed7525003c7fe7dc86c56", [:mix], [], "hexpm", "8e2d5370b732385db2c9b22215c3f59c84ac7dda7ed7e544d7c459496ae519c0"},
"ex_doc": {:git, "https://github.com/elixir-lang/ex_doc.git", "2cc44d503287e31581657513463c68a172a95916", []},
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
"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.0", "98312c9f0d3730fde4049985a1105da5155bfe5c11e47bdc7406d88e01e4219b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "75ffa34ab1056b7e24844c90bfc62aaf6f3a37a15faa76b07bc5eba27e4a8b4a"},
"nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"},
"earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"},
"ex_doc": {:git, "https://github.com/elixir-lang/ex_doc.git", "72bb75889d0eef8df71cbf40bfd9d7bb8ed16120", []},
"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"},
"makeup": {:hex, :makeup, "1.1.1", "fa0bc768698053b2b3869fa8a62616501ff9d11a562f3ce39580d60860c3a55e", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5dc62fbdd0de44de194898b6710692490be74baa02d9d108bc29f007783b0b48"},
"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, "0.1.5", "e0ff5a7c708dda34311f7522a8758e23bfcd7d8d8068dc312b5eb41c6fd76eba", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "94d2e986428585a21516d7d7149781480013c56e30c6a233534bedf38867a59a"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
}
20 changes: 13 additions & 7 deletions test/xml_builder_test.exs
Expand Up @@ -162,8 +162,10 @@ defmodule XmlBuilderTest do
test "element with attributes" do
warning =
capture_io(:stderr, fn ->
assert doc(:person, %{occupation: "Developer", city: "Montreal"}) ==
~s|<?xml version="1.0" encoding="UTF-8"?>\n<person city="Montreal" occupation="Developer"/>|
assert doc(:person, %{occupation: "Developer", city: "Montreal"}) in [
~s|<?xml version="1.0" encoding="UTF-8"?>\n<person city="Montreal" occupation="Developer"/>|,
~s|<?xml version="1.0" encoding="UTF-8"?>\n<person occupation="Developer" city="Montreal"/>|
]

assert doc(:person, %{}) == ~s|<?xml version="1.0" encoding="UTF-8"?>\n<person/>|
end)
Expand All @@ -174,11 +176,15 @@ defmodule XmlBuilderTest do
test "element with attributes and content" do
warning =
capture_io(:stderr, fn ->
assert doc(:person, %{occupation: "Developer", city: "Montreal"}, "Josh") ==
~s|<?xml version="1.0" encoding="UTF-8"?>\n<person city="Montreal" occupation="Developer">Josh</person>|
assert doc(:person, %{occupation: "Developer", city: "Montreal"}, "Josh") in [
~s|<?xml version="1.0" encoding="UTF-8"?>\n<person city="Montreal" occupation="Developer">Josh</person>|,
~s|<?xml version="1.0" encoding="UTF-8"?>\n<person occupation="Developer" city="Montreal">Josh</person>|
]

assert doc(:person, %{occupation: "Developer", city: "Montreal"}, nil) ==
~s|<?xml version="1.0" encoding="UTF-8"?>\n<person city="Montreal" occupation="Developer"/>|
assert doc(:person, %{occupation: "Developer", city: "Montreal"}, nil) in [
~s|<?xml version="1.0" encoding="UTF-8"?>\n<person city="Montreal" occupation="Developer"/>|,
~s|<?xml version="1.0" encoding="UTF-8"?>\n<person occupation="Developer" city="Montreal"/>|
]

assert doc(:person, %{}, "Josh") ==
~s|<?xml version="1.0" encoding="UTF-8"?>\n<person>Josh</person>|
Expand Down Expand Up @@ -301,7 +307,7 @@ defmodule XmlBuilderTest do

assert XmlBuilder.element(:person, {:iodata, ["test", ?i, "ng 123"]})
|> XmlBuilder.generate_iodata() ==
["", '<', "person", '>', ["test", ?i, "ng 123"], '</', "person", '>']
["", ~c"<", "person", ~c">", ["test", ?i, "ng 123"], ~c"</", "person", ~c">"]
end

test "multi level indentation" do
Expand Down

0 comments on commit e05a22d

Please sign in to comment.