Skip to content

Commit adad141

Browse files
committed
CI: add check-formatting.yaml
Adapted from atomvm repo Signed-off-by: Peter M <petermm@gmail.com>
1 parent 23f6b12 commit adad141

8 files changed

Lines changed: 105 additions & 50 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#
2+
# Copyright 2022 Davide Bettio <davide@uninstall.it>
3+
#
4+
# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
5+
#
6+
7+
name: "Check formatting"
8+
9+
on:
10+
push:
11+
paths:
12+
- ".github/workflows/**"
13+
- "**/*.ex"
14+
- "**/*.exs"
15+
- "**/*.erl"
16+
pull_request:
17+
paths:
18+
- ".github/workflows/**"
19+
- "**/*.ex"
20+
- "**/*.exs"
21+
- "**/*.erl"
22+
23+
concurrency:
24+
group: ${{ github.workflow }}-${{ github.ref != 'refs/heads/main' && github.ref || github.run_id }}
25+
cancel-in-progress: true
26+
27+
jobs:
28+
erlfmt-check:
29+
runs-on: ubuntu-24.04
30+
container: erlang:28
31+
steps:
32+
- uses: actions/checkout@v4
33+
- name: "Check formatting with Erlang fmt"
34+
run: |
35+
cd ..
36+
git clone --depth 1 -b v1.7.0 https://github.com/WhatsApp/erlfmt.git
37+
cd erlfmt
38+
rebar3 as release escriptize
39+
cd ../atomvm_examples
40+
find . -name *.erl | xargs ../erlfmt/_build/release/bin/erlfmt -c
41+
42+
mix-format-check:
43+
runs-on: ubuntu-24.04
44+
container: elixir:1.17.1
45+
steps:
46+
- uses: actions/checkout@v4
47+
- name: "Check formatting with Elixir mix format"
48+
run: |
49+
mix format --check-formatted "**/*.{ex,exs}"

build.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,5 @@ for i in ${ERLANG_EXAMPLES}; do
2626
cd $i
2727
rm -rf _build
2828
${REBAR} atomvm packbeam -l || exit 1
29-
${REBAR} as check fmt -c || exit 1
3029
cd ..
3130
done

demos/lisp_faces/lib/main.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ defmodule Main do
4141
:gen_server.call(
4242
t,
4343
{:write,
44-
:erlang.integer_to_list(:erlang.system_info(:process_count)) ++ ' running processes.\n'},
44+
:erlang.integer_to_list(:erlang.system_info(:process_count)) ++ ~c" running processes.\n"},
4545
60000
4646
)
4747

demos/morse_server/src/morse_server.app.src

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
{applications, [
2626
kernel, stdlib
2727
]},
28-
{env,[]},
28+
{env, []},
2929
{modules, []},
3030
{licenses, ["Apache 2.0"]},
3131
{links, []}
32-
]}.
32+
]}.

demos/morse_server/src/morse_server.erl

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ start() ->
2727
Config = [
2828
{sta, [
2929
{ssid, esp:nvs_get_binary(atomvm, sta_ssid, <<"myssid">>)},
30-
{psk, esp:nvs_get_binary(atomvm, sta_psk, <<"mypsk">>)},
30+
{psk, esp:nvs_get_binary(atomvm, sta_psk, <<"mypsk">>)},
3131
{connected, fun() -> Self ! connected end},
3232
{got_ip, fun(IpInfo) -> Self ! {ok, IpInfo} end},
3333
{disconnected, fun() -> Self ! disconnected end}
@@ -41,18 +41,20 @@ start() ->
4141
end.
4242

4343
handle_req("GET", [], Conn) ->
44-
Body = <<"<html>
45-
<body>
46-
<h1>Morse Encoder</h1>
47-
<form method=\"post\">
48-
<p>Text: <input type=\"text\" name=\"text\"></p>
49-
<p>GPIO: <input type=\"text\" name=\"gpio\" value=\"2\"></p>
50-
<input type=\"submit\" value=\"Submit\">
51-
</form>
52-
</body>
53-
</html>">>,
44+
Body =
45+
<<
46+
"<html>\n"
47+
" <body>\n"
48+
" <h1>Morse Encoder</h1>\n"
49+
" <form method=\"post\">\n"
50+
" <p>Text: <input type=\"text\" name=\"text\"></p>\n"
51+
" <p>GPIO: <input type=\"text\" name=\"gpio\" value=\"2\"></p>\n"
52+
" <input type=\"submit\" value=\"Submit\">\n"
53+
" </form>\n"
54+
" </body>\n"
55+
" </html>"
56+
>>,
5457
http_server:reply(200, Body, Conn);
55-
5658
handle_req("POST", [], Conn) ->
5759
ParamsBody = proplists:get_value(body_chunk, Conn),
5860
Params = http_server:parse_query_string(ParamsBody),
@@ -65,14 +67,21 @@ handle_req("POST", [], Conn) ->
6567

6668
spawn(fun() -> blink_led(GPIONum, MorseText) end),
6769

68-
Body = [<<"<html>
69-
<body>
70-
<h1>Text Encoded</h1>">>,
71-
<<"<p>">>, MorseText, <<"</p1>
72-
</body>
73-
</html>">>],
70+
Body = [
71+
<<
72+
"<html>\n"
73+
" <body>\n"
74+
" <h1>Text Encoded</h1>"
75+
>>,
76+
<<"<p>">>,
77+
MorseText,
78+
<<
79+
"</p1>\n"
80+
" </body>\n"
81+
" </html>"
82+
>>
83+
],
7484
http_server:reply(200, Body, Conn);
75-
7685
handle_req(Method, Path, Conn) ->
7786
erlang:display(Conn),
7887
erlang:display({Method, Path}),
@@ -108,34 +117,29 @@ get_gpio() ->
108117
undefined ->
109118
GPIO = gpio:open(),
110119
GPIO;
111-
112120
GPIO ->
113121
GPIO
114122
end.
115123

116124
blink_led(undefined, _L) ->
117125
ok;
118-
119126
blink_led(GPIONum, L) ->
120127
GPIO = get_gpio(),
121128
gpio:set_direction(GPIO, GPIONum, output),
122129
blink_led(GPIO, GPIONum, L).
123130

124131
blink_led(_GPIO, _GPIONum, []) ->
125132
ok;
126-
127133
blink_led(GPIO, GPIONum, [H | T]) ->
128134
case H of
129135
$\s ->
130136
gpio:set_level(GPIO, GPIONum, low),
131137
timer:sleep(120);
132-
133138
$. ->
134139
gpio:set_level(GPIO, GPIONum, high),
135140
timer:sleep(120),
136141
gpio:set_level(GPIO, GPIONum, low),
137142
timer:sleep(120);
138-
139143
$- ->
140144
gpio:set_level(GPIO, GPIONum, high),
141145
timer:sleep(120 * 3),
@@ -149,7 +153,6 @@ morse_encode(L) ->
149153

150154
morse_encode([], Acc) ->
151155
Acc;
152-
153156
morse_encode([H | L], Acc) ->
154157
M = to_morse(string:to_upper(H)),
155158
morse_encode(L, Acc ++ M).
@@ -167,7 +170,7 @@ to_morse(C) ->
167170
$7 -> "--... ";
168171
$8 -> "---.. ";
169172
$9 -> "----. ";
170-
$A -> ".-" ;
173+
$A -> ".-";
171174
$B -> "-... ";
172175
$C -> "-.-. ";
173176
$D -> "-.. ";

elixir/Blinky/lib/Blinky.ex

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ defmodule Blinky do
3030
end
3131

3232
defp loop(pin, level) do
33-
:io.format('Setting pin ~p ~p~n', [pin, level])
33+
:io.format(~c"Setting pin ~p ~p~n", [pin, level])
3434
GPIO.digital_write(pin, level)
3535
Process.sleep(1000)
3636
loop(pin, toggle(level))
@@ -55,19 +55,25 @@ defmodule Blinky do
5555

5656
defp platform_gpio_setup() do
5757
case :atomvm.platform() do
58-
:esp32 -> GPIO.set_pin_mode(pin(), :output)
59-
:stm32 -> GPIO.set_pin_mode(pin(), :output)
58+
:esp32 ->
59+
GPIO.set_pin_mode(pin(), :output)
60+
61+
:stm32 ->
62+
GPIO.set_pin_mode(pin(), :output)
63+
6064
:pico ->
6165
case @pin do
62-
{:wl, 0} -> :ok
66+
{:wl, 0} ->
67+
:ok
68+
6369
pin ->
6470
GPIO.init(pin)
6571
GPIO.set_pin_mode(pin, :output)
6672
end
73+
6774
unsupported ->
6875
:io.format("Platform ~p is not supported.~n", [unsupported])
6976
:erlang.exit({:error, {:unsupported_platform, unsupported}})
7077
end
7178
end
72-
7379
end

elixir/HelloWorld/lib/HelloWorld.ex

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
#
2020

2121
defmodule HelloWorld do
22-
2322
def start() do
24-
:io.format('Hello World~n')
23+
:io.format(~c"Hello World~n")
2524
end
26-
2725
end

elixir/LEDC_Example/lib/LEDC_Example.ex

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ defmodule LedcExample do
3939
ledc_hs_timer = [
4040
{:duty_resolution, 13},
4141
{:freq_hz, 5000},
42-
{:speed_mode, LEDC.high_speed_mode},
42+
{:speed_mode, LEDC.high_speed_mode()},
4343
{:timer_num, @high_speed_timer}
4444
]
4545

@@ -48,7 +48,7 @@ defmodule LedcExample do
4848
ledc_ls_timer = [
4949
{:duty_resolution, 13},
5050
{:freq_hz, 5000},
51-
{:speed_mode, LEDC.low_speed_mode},
51+
{:speed_mode, LEDC.low_speed_mode()},
5252
{:timer_num, @low_speed_timer}
5353
]
5454

@@ -59,31 +59,31 @@ defmodule LedcExample do
5959
{:channel, 0},
6060
{:duty, 0},
6161
{:gpio_num, @led_1},
62-
{:speed_mode, LEDC.high_speed_mode},
62+
{:speed_mode, LEDC.high_speed_mode()},
6363
{:hpoint, 0},
6464
{:timer_sel, @high_speed_timer}
6565
],
6666
[
6767
{:channel, 1},
6868
{:duty, 0},
6969
{:gpio_num, @led_2},
70-
{:speed_mode, LEDC.high_speed_mode},
70+
{:speed_mode, LEDC.high_speed_mode()},
7171
{:hpoint, 0},
7272
{:timer_sel, @high_speed_timer}
7373
],
7474
[
7575
{:channel, 2},
7676
{:duty, 0},
7777
{:gpio_num, @led_3},
78-
{:speed_mode, LEDC.low_speed_mode},
78+
{:speed_mode, LEDC.low_speed_mode()},
7979
{:hpoint, 0},
8080
{:timer_sel, @low_speed_timer}
8181
],
8282
[
8383
{:channel, 3},
8484
{:duty, 0},
8585
{:gpio_num, @led_4},
86-
{:speed_mode, LEDC.low_speed_mode},
86+
{:speed_mode, LEDC.low_speed_mode()},
8787
{:hpoint, 0},
8888
{:timer_sel, @low_speed_timer}
8989
]
@@ -95,19 +95,19 @@ defmodule LedcExample do
9595
end
9696

9797
def loop(ledc_channel) do
98-
:io.format('1. LEDC fade up to duty = ~p~n', [@test_duty])
98+
:io.format(~c"1. LEDC fade up to duty = ~p~n", [@test_duty])
9999
Enum.each(ledc_channel, fn channel_config -> do_stage_1(channel_config) end)
100100
Process.sleep(@test_fade_time)
101101

102-
:io.format('2. LEDC fade down to duty = 0~n')
102+
:io.format(~c"2. LEDC fade down to duty = 0~n")
103103
Enum.each(ledc_channel, fn channel_config -> do_stage_2(channel_config) end)
104104
Process.sleep(@test_fade_time)
105105

106-
:io.format('3. LEDC set duty = ~p without fade~n', [@test_duty])
106+
:io.format(~c"3. LEDC set duty = ~p without fade~n", [@test_duty])
107107
Enum.each(ledc_channel, fn channel_config -> do_stage_3(channel_config) end)
108108
Process.sleep(@test_fade_time)
109109

110-
:io.format('4. LEDC set duty = 0 without fade~n')
110+
:io.format(~c"4. LEDC set duty = 0 without fade~n")
111111
Enum.each(ledc_channel, fn channel_config -> do_stage_4(channel_config) end)
112112
Process.sleep(@test_fade_time)
113113

@@ -118,14 +118,14 @@ defmodule LedcExample do
118118
speed_mode = :proplists.get_value(:speed_mode, channel_config)
119119
channel = :proplists.get_value(:channel, channel_config)
120120
:ok = LEDC.set_fade_with_time(speed_mode, channel, @test_duty, @test_fade_time)
121-
:ok = LEDC.fade_start(speed_mode, channel, LEDC.fade_no_wait)
121+
:ok = LEDC.fade_start(speed_mode, channel, LEDC.fade_no_wait())
122122
end
123123

124124
defp do_stage_2(channel_config) do
125125
speed_mode = :proplists.get_value(:speed_mode, channel_config)
126126
channel = :proplists.get_value(:channel, channel_config)
127127
:ok = LEDC.set_fade_with_time(speed_mode, channel, 0, @test_fade_time)
128-
:ok = LEDC.fade_start(speed_mode, channel, LEDC.fade_no_wait)
128+
:ok = LEDC.fade_start(speed_mode, channel, LEDC.fade_no_wait())
129129
end
130130

131131
defp do_stage_3(channel_config) do

0 commit comments

Comments
 (0)