Skip to content

Commit 2d22fe0

Browse files
committed
improve formatting
1 parent fdf75bc commit 2d22fe0

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ iex(6)> inspect(sql)
6161
[%User{id: 1, email: "john@example.com"}, %User{id: 2, email: "jane@example.com"}]
6262
```
6363

64-
## Compile time errors
64+
## Compile time warning
6565
run `mix sql.get` to generate your `sql.lock` file which is used for error reporting.
6666

6767
```elixir

lib/format.ex

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ defmodule SQL.Format do
1919

2020
defp indention(acc, [{_, {_,_,_,_,_,0}}|_], _), do: acc
2121
defp indention(acc, [{_, {_,_,_,_,_,0,_,_}}|_], _), do: acc
22+
defp indention(acc, [{_, {_,_,_,_,_,_}}|_], 0), do: [?\s|acc]
23+
defp indention(acc, [{_, {_,_,_,_,_,_,_,_}}|_], 0), do: [?\s|acc]
2224
defp indention(acc, 0, 0), do: acc
23-
defp indention(acc, _, 0), do: [?\s|acc]
25+
defp indention(acc, _, 0), do: acc
2426
defp indention(acc, _, 1), do: [?\s,?\s|acc]
2527
defp indention(acc, m, indent), do: indention([?\s,?\s|acc], m, indent-1)
2628

@@ -41,10 +43,10 @@ defmodule SQL.Format do
4143
end
4244
for atom <- newline do
4345
defp to_iodata({unquote(atom), _m, values}, binding, :lower=case, errors, indent, acc) do
44-
newline([@keyword, unquote("#{atom}"), @reset|newline(to_iodata(values, binding, case, errors, indent, acc), indent)], indent)
46+
newline([@keyword, unquote("#{atom}"), @reset|pad(to_iodata(values, binding, case, errors, indent+1, acc))], indent)
4547
end
4648
defp to_iodata({unquote(atom), _m, values}, binding, :upper=case, errors, indent, acc) do
47-
newline([@keyword, unquote(String.upcase("#{atom}")), @reset|newline(to_iodata(values, binding, case, errors, indent, acc), indent)], indent)
49+
newline([@keyword, unquote(String.upcase("#{atom}")), @reset|pad(to_iodata(values, binding, case, errors, indent+1, acc))], indent)
4850
end
4951
end
5052
for atom <- ~w[group order]a do
@@ -61,8 +63,8 @@ defmodule SQL.Format do
6163
defp to_iodata(:comma, _binding, _case, _errors, 0, acc) do
6264
[?,|acc]
6365
end
64-
defp to_iodata(:comma, _binding, _case, _errors, indent, acc) do
65-
[?,|newline(acc, indent)]
66+
defp to_iodata(:comma, _binding, _case, _errors, _indent, acc) do
67+
[?,|pad(acc)]
6668
end
6769
defp to_iodata(:dot, _binding, _case, _errors, _indent, acc) do
6870
[?.|acc]

test/sql_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ defmodule SQLTest do
4747

4848

4949
test "inspect/1" do
50-
assert ~s(\e[0m~SQL\"\"\"\n\e[35mselect\e[0m\n \e[35m+\e[0m\e[33m1000\e[0m\n\"\"\") == inspect(~SQL[select +1000])
50+
assert ~s(\e[0m~SQL\"\"\"\n\e[35mselect\e[0m\n \e[35m+\e[0m\e[33m1000\e[0m\n\"\"\") == inspect(~SQL[select +1000])
5151
end
5252

5353
test "to_sql/1" do

0 commit comments

Comments
 (0)