Skip to content

Commit f3bdfda

Browse files
authored
Format files and add linter (#202)
* format files * remove prints
1 parent 91be710 commit f3bdfda

30 files changed

+1795
-1871
lines changed

.github/workflows/lint.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Lint and format 💅
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
pull_request:
7+
branches:
8+
- main
9+
- develop
10+
11+
permissions:
12+
contents: read
13+
pull-requests: write
14+
15+
jobs:
16+
lint:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
submodules: recursive
22+
23+
- name: Install dependencies
24+
run: |
25+
sudo apt-get update
26+
sudo apt-get install -y \
27+
build-essential \
28+
cmake \
29+
clang-format \
30+
clang-tidy
31+
32+
- name: Lint and format 💅
33+
uses: cpp-linter/cpp-linter-action@v2
34+
id: linter
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
with:
38+
file-annotations: true
39+
files-changed-only: false
40+
ignore: "build|.github|cmake|fuzzing|.vscode|.idea"
41+
step-summary: true
42+
style: file # uses .clang-format
43+
thread-comments: true
44+
tidy-checks: "-*" # disable clang-tidy, only use clang-format
45+
format-review-errors: false # ignore parsing errors, only check formatting
46+
47+
- name: Fail if errors
48+
if: ${{ steps.linter.outputs['checks-failed'] > 0 }}
49+
run: |
50+
echo "Linter or formatter failed!"
51+
exit 1

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Simple Makefile for zxlib tests
22
# Wrapper around CMake build system
33

4-
.PHONY: all build test clean test-verbose test-filter
4+
.PHONY: all build test clean test-verbose test-filter format
55

66
# Default target
77
all: build
@@ -26,4 +26,7 @@ test-verbose: build
2626

2727
# Run specific test
2828
test-filter: build
29-
cd build && ./zxlib_tests --gtest_filter="$(FILTER)"
29+
cd build && ./zxlib_tests --gtest_filter="$(FILTER)"
30+
31+
format:
32+
find src evm tests include app \( -iname '*.h' -o -iname '*.c' -o -iname '*.cpp' -o -iname '*.hpp' \) | xargs clang-format -i

app/ui/view.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,15 @@ void view_review_init(viewfunc_getItem_t viewfuncGetItem, viewfunc_getNumItems_t
6060
#if defined(TARGET_NANOS) || defined(TARGET_NANOS2) || defined(TARGET_NANOX)
6161
viewdata.with_confirmation = false;
6262
#endif
63-
6463
}
6564

66-
void view_review_init_progressive(
67-
viewfunc_getItem_t viewfuncGetItem,
68-
viewfunc_getNumItems_t viewfuncGetNumItems,
69-
viewfunc_accept_t viewfuncAccept) {
70-
65+
void view_review_init_progressive(viewfunc_getItem_t viewfuncGetItem, viewfunc_getNumItems_t viewfuncGetNumItems,
66+
viewfunc_accept_t viewfuncAccept) {
7167
view_review_init(viewfuncGetItem, viewfuncGetNumItems, viewfuncAccept);
7268

7369
#if defined(TARGET_NANOS) || defined(TARGET_NANOS2) || defined(TARGET_NANOX)
7470
viewdata.with_confirmation = true;
7571
#endif
76-
7772
}
7873

7974
void view_initialize_init(viewfunc_initialize_t viewFuncInit) { viewdata.viewfuncInitialize = viewFuncInit; }

app/ui/view.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,8 @@ void view_blindsign_error_show();
120120
void view_review_init(viewfunc_getItem_t viewfuncGetItem, viewfunc_getNumItems_t viewfuncGetNumItems,
121121
viewfunc_accept_t viewfuncAccept);
122122

123-
void view_review_init_progressive(
124-
viewfunc_getItem_t viewfuncGetItem,
125-
viewfunc_getNumItems_t viewfuncGetNumItems,
126-
viewfunc_accept_t viewfuncAccept);
123+
void view_review_init_progressive(viewfunc_getItem_t viewfuncGetItem, viewfunc_getNumItems_t viewfuncGetNumItems,
124+
viewfunc_accept_t viewfuncAccept);
127125

128126
void view_inspect_init(viewfunc_getInnerItem_t view_funcGetInnerItem, viewfunc_getNumItems_t view_funcGetInnerNumItems,
129127
viewfunc_canInspectItem_t view_funcCanInspectItem);
@@ -150,4 +148,4 @@ typedef enum {
150148
} settings_list_e;
151149

152150
void view_set_switch_subtext(settings_list_e switch_id, const char *subtext);
153-
#endif // TARGET_STAX || TARGET_FLEX
151+
#endif // TARGET_STAX || TARGET_FLEX

app/ui/view_inspect_x.c

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
/*******************************************************************************
2-
* (c) 2018 - 2023 Zondax AG
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
********************************************************************************/
2+
* (c) 2018 - 2023 Zondax AG
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
********************************************************************************/
1616
#include "bolos_target.h"
1717

1818
#if defined(TARGET_NANOX) || defined(TARGET_NANOS2)
1919
#include "view_internal.h"
20+
#include "view_nano.h"
2021
#include "view_nano_inspect.h"
2122
#include "view_templates.h"
22-
#include "view_nano.h"
2323
#include "zxmacros.h"
2424

2525
extern const ux_flow_step_t *ux_review_flow[MAX_REVIEW_UX_SCREENS];
@@ -38,18 +38,22 @@ uint8_t flow_inside_inspect_loop;
3838
extern unsigned int review_type;
3939

4040
// Menu to recursively inspect elements from a transaction
41-
UX_STEP_VALID(ux_inspect_flow_root_step, pb, h_rootTxn(), { &C_icon_back, "Go to root" });
41+
UX_STEP_VALID(ux_inspect_flow_root_step, pb, h_rootTxn(), {&C_icon_back, "Go to root"});
4242

4343
UX_STEP_INIT(ux_inspect_flow_start_step, NULL, NULL, { h_inspect_loop_start(); });
44-
UX_STEP_CB_INIT(ux_inspect_flow_step, bnnn_paging, h_inspect_loop_inside(), h_inspect(), { .title = viewdata.key, .text = viewdata.value, });
44+
UX_STEP_CB_INIT(ux_inspect_flow_step, bnnn_paging, h_inspect_loop_inside(), h_inspect(),
45+
{
46+
.title = viewdata.key,
47+
.text = viewdata.value,
48+
});
4549

4650
UX_STEP_INIT(ux_inspect_flow_end_step, NULL, NULL, { h_inspect_loop_end(); });
4751

48-
UX_STEP_VALID(ux_inspect_flow_back_step, pb, h_back(), { &C_icon_back, "BACK" });
52+
UX_STEP_VALID(ux_inspect_flow_back_step, pb, h_back(), {&C_icon_back, "BACK"});
4953

50-
void view_inspect_show_impl(){
54+
void view_inspect_show_impl() {
5155
// h_inspect_loop_inside();
52-
if(G_ux.stack_count == 0) {
56+
if (G_ux.stack_count == 0) {
5357
ux_stack_push();
5458
}
5559

@@ -65,24 +69,23 @@ void view_inspect_show_impl(){
6569
}
6670

6771
void inspect_init() {
68-
#ifdef HAVE_INSPECT
69-
h_inspect_init();
70-
if (!viewdata.viewfuncCanInspectItem(viewdata.innerField.level,
71-
viewdata.innerField.trace,
72-
viewdata.innerField.paging.itemIdx)) {
73-
h_rootTxn();
74-
return;
75-
}
72+
#ifdef HAVE_INSPECT
73+
h_inspect_init();
74+
if (!viewdata.viewfuncCanInspectItem(viewdata.innerField.level, viewdata.innerField.trace,
75+
viewdata.innerField.paging.itemIdx)) {
76+
h_rootTxn();
77+
return;
78+
}
7679

77-
const zxerr_t err = h_inspect_update_data();
78-
if (err != zxerr_ok) {
79-
// Show error
80-
view_error_show();
81-
// h_rootTxn();
82-
return;
83-
}
84-
view_inspect_show_impl();
85-
#endif
80+
const zxerr_t err = h_inspect_update_data();
81+
if (err != zxerr_ok) {
82+
// Show error
83+
view_error_show();
84+
// h_rootTxn();
85+
return;
86+
}
87+
view_inspect_show_impl();
88+
#endif
8689
}
8790

8891
void h_inspect() {
@@ -93,9 +96,8 @@ void h_inspect() {
9396

9497
// Check if we can inspect this element
9598
if (viewdata.innerField.level >= MAX_DEPTH ||
96-
!viewdata.viewfuncCanInspectItem(viewdata.innerField.level+1,
97-
viewdata.innerField.trace,
98-
viewdata.innerField.paging.itemIdx)) {
99+
!viewdata.viewfuncCanInspectItem(viewdata.innerField.level + 1, viewdata.innerField.trace,
100+
viewdata.innerField.paging.itemIdx)) {
99101
flow_inside_inspect_loop = 0;
100102
h_inspect_update_data();
101103
view_inspect_show_impl();
@@ -190,7 +192,7 @@ void h_inspect_loop_end() {
190192
}
191193

192194
ux_layout_bnnn_paging_reset();
193-
CUR_FLOW.prev_index = CUR_FLOW.index-2;
195+
CUR_FLOW.prev_index = CUR_FLOW.index - 2;
194196
CUR_FLOW.index--;
195197
ux_flow_relayout();
196198
}

app/ui/view_nano.h

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
/*******************************************************************************
2-
* (c) 2018 - 2024 Zondax AG
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
********************************************************************************/
2+
* (c) 2018 - 2024 Zondax AG
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
********************************************************************************/
1616
#pragma once
17-
#include "bolos_target.h"
1817
#include <stdint.h>
1918

19+
#include "bolos_target.h"
20+
2021
#if defined(TARGET_NANOS)
2122
#define INCLUDE_ACTIONS_AS_ITEMS 2
22-
#define INCLUDE_ACTIONS_COUNT (INCLUDE_ACTIONS_AS_ITEMS-1)
23+
#define INCLUDE_ACTIONS_COUNT (INCLUDE_ACTIONS_AS_ITEMS - 1)
2324
typedef uint8_t max_char_display;
2425
#else
2526
#define INCLUDE_ACTIONS_COUNT 0

app/ui/view_nano_inspect.c

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
/*******************************************************************************
2-
* (c) 2018 - 2023 Zondax AG
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
********************************************************************************/
2+
* (c) 2018 - 2023 Zondax AG
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
********************************************************************************/
1616
#include "bolos_target.h"
1717

1818
#if defined(TARGET_NANOS) || defined(TARGET_NANOS2) || defined(TARGET_NANOX)
19-
#include "view_nano_inspect.h"
2019
#include "view_internal.h"
21-
#include "view_templates.h"
2220
#include "view_nano.h"
21+
#include "view_nano_inspect.h"
22+
#include "view_templates.h"
2323
#include "zxmacros.h"
2424

2525
void h_inspect_init() {
@@ -33,22 +33,20 @@ void h_inspect_init() {
3333
viewdata.innerField.paging.itemCount = 0xFF;
3434
}
3535

36-
void view_inspect_init(viewfunc_getInnerItem_t view_funcGetInnerItem,
37-
viewfunc_getNumItems_t view_funcGetInnerNumItems,
36+
void view_inspect_init(viewfunc_getInnerItem_t view_funcGetInnerItem, viewfunc_getNumItems_t view_funcGetInnerNumItems,
3837
viewfunc_canInspectItem_t view_funcCanInspectItem) {
3938
viewdata.viewfuncGetInnerItem = view_funcGetInnerItem;
4039
viewdata.viewfuncGetInnerNumItems = view_funcGetInnerNumItems;
4140
viewdata.viewfuncCanInspectItem = view_funcCanInspectItem;
4241
}
4342

4443
bool h_paging_inspect_go_to_root_screen() {
45-
return (viewdata.innerField.paging.itemIdx == 0)
46-
&& (viewdata.innerField.trace[0] != 0);
44+
return (viewdata.innerField.paging.itemIdx == 0) && (viewdata.innerField.trace[0] != 0);
4745
}
4846

4947
bool h_paging_inspect_back_screen() {
50-
return (viewdata.innerField.paging.itemIdx == (viewdata.innerField.paging.itemCount - 1))
51-
&& (viewdata.innerField.trace[0] != 0);
48+
return (viewdata.innerField.paging.itemIdx == (viewdata.innerField.paging.itemCount - 1)) &&
49+
(viewdata.innerField.trace[0] != 0);
5250
}
5351

5452
bool h_can_increase(paging_t *paging, uint8_t actionsCount) {
@@ -137,15 +135,15 @@ zxerr_t h_inspect_update_data() {
137135
viewdata.innerField.paging.itemCount += 2;
138136
viewdata.innerField.paging.pageCount = 1;
139137
if (h_paging_inspect_go_to_root_screen()) {
140-
snprintf(viewdata.key, MAX_CHARS_PER_KEY_LINE, "%s","");
138+
snprintf(viewdata.key, MAX_CHARS_PER_KEY_LINE, "%s", "");
141139
snprintf(viewdata.value, MAX_CHARS_PER_VALUE1_LINE, "%s", "Go to root");
142140
splitValueField();
143141
page.pageIdx = 0;
144142
return zxerr_ok;
145143
}
146144

147145
if (h_paging_inspect_back_screen()) {
148-
snprintf(viewdata.key, MAX_CHARS_PER_KEY_LINE, "%s","");
146+
snprintf(viewdata.key, MAX_CHARS_PER_KEY_LINE, "%s", "");
149147
snprintf(viewdata.value, MAX_CHARS_PER_VALUE1_LINE, "%s", "BACK");
150148
splitValueField();
151149
page.pageIdx = 0;
@@ -165,10 +163,7 @@ zxerr_t h_inspect_update_data() {
165163
.pageCount = &viewdata.innerField.paging.pageCount,
166164
};
167165

168-
CHECK_ZXERR(viewdata.viewfuncGetInnerItem(
169-
viewdata.innerField.level,
170-
viewdata.innerField.trace,
171-
&thisItem))
166+
CHECK_ZXERR(viewdata.viewfuncGetInnerItem(viewdata.innerField.level, viewdata.innerField.trace, &thisItem))
172167

173168
return zxerr_ok;
174169
}

0 commit comments

Comments
 (0)