Skip to content

Commit f5d8c7d

Browse files
Apply Clang-tidy (#918)
1 parent 535290b commit f5d8c7d

32 files changed

+160
-110
lines changed

.clang-tidy

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Checks: "*,
2727
-readability-simplify-boolean-expr,
2828
-readability-static-accessed-through-instance,
2929
-readability-use-anyofallof,
30+
-readability-avoid-nested-conditional-operator,
3031
-zircon-*,
3132
"
3233
WarningsAsErrors: ''

examples/component/homescreen.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,8 @@ int main() {
490490
},
491491
&tab_index);
492492

493-
auto exit_button = Button(
494-
"Exit", [&] { screen.Exit(); }, ButtonOption::Animated());
493+
auto exit_button =
494+
Button("Exit", [&] { screen.Exit(); }, ButtonOption::Animated());
495495

496496
auto main_container = Container::Vertical({
497497
Container::Horizontal({

include/ftxui/screen/pixel.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ struct Pixel {
4949

5050
} // namespace ftxui
5151

52-
#endif // FTXUI_SCREEN_PIXEL_HPP
52+
#endif // FTXUI_SCREEN_PIXEL_HPP

src/ftxui/component/button.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ Component Button(ButtonOption option) {
205205
Component Button(ConstStringRef label,
206206
std::function<void()> on_click,
207207
ButtonOption option) {
208-
option.label = label;
208+
option.label = std::move(label);
209209
option.on_click = std::move(on_click);
210210
return Make<ButtonBase>(std::move(option));
211211
}

src/ftxui/component/collapsible.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Component Collapsible(ConstStringRef label, Component child, Ref<bool> show) {
4747
return hbox({prefix, t});
4848
};
4949
Add(Container::Vertical({
50-
Checkbox(label, show_.operator->(), opt),
50+
Checkbox(std::move(label), show_.operator->(), opt),
5151
Maybe(std::move(child), show_.operator->()),
5252
}));
5353
}

src/ftxui/component/component.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <cassert> // for assert
66
#include <cstddef> // for size_t
77
#include <iterator> // for begin, end
8+
#include <memory> // for unique_ptr, make_unique
89
#include <utility> // for move
910
#include <vector> // for vector, __alloc_traits<>::value_type
1011

src/ftxui/component/component_options.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
// the LICENSE file.
44
#include "ftxui/component/component_options.hpp"
55

6-
#include <ftxui/dom/linear_gradient.hpp> // for LinearGradient
76
#include <ftxui/screen/color.hpp> // for Color, Color::White, Color::Black, Color::GrayDark, Color::Blue, Color::GrayLight, Color::Red
87
#include <memory> // for shared_ptr
98
#include <utility> // for move
10-
119
#include "ftxui/component/animation.hpp" // for Function, Duration
10+
#include "ftxui/dom/direction.hpp"
1211
#include "ftxui/dom/elements.hpp" // for operator|=, Element, text, bgcolor, inverted, bold, dim, operator|, color, borderEmpty, hbox, automerge, border, borderLight
1312

1413
namespace ftxui {

src/ftxui/component/dropdown.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Copyright 2021 Arthur Sonzogni. All rights reserved.
22
// Use of this source code is governed by the MIT license that can be found in
33
// the LICENSE file.
4-
#include <cstddef> // for size_t
54
#include <ftxui/component/event.hpp>
65
#include <functional> // for function
76
#include <string> // for string
87

8+
#include <utility>
99
#include "ftxui/component/component.hpp" // for Maybe, Checkbox, Make, Radiobox, Vertical, Dropdown
1010
#include "ftxui/component/component_base.hpp" // for Component, ComponentBase
1111
#include "ftxui/component/component_options.hpp" // for CheckboxOption, EntryState
@@ -21,14 +21,15 @@ namespace ftxui {
2121
/// @param selected The index of the selected entry.
2222
Component Dropdown(ConstStringListRef entries, int* selected) {
2323
DropdownOption option;
24-
option.radiobox.entries = entries;
24+
option.radiobox.entries = std::move(entries);
2525
option.radiobox.selected = selected;
2626
return Dropdown(option);
2727
}
2828

2929
/// @brief A dropdown menu.
3030
/// @ingroup component
3131
/// @param option The options for the dropdown.
32+
// NOLINTNEXTLINE
3233
Component Dropdown(DropdownOption option) {
3334
class Impl : public ComponentBase, public DropdownOption {
3435
public:

src/ftxui/component/event.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Copyright 2020 Arthur Sonzogni. All rights reserved.
22
// Use of this source code is governed by the MIT license that can be found in
33
// the LICENSE file.
4-
#include <map> // for map
4+
#include <map> // for map
5+
#include <string>
56
#include <utility> // for move
67

78
#include "ftxui/component/event.hpp"

src/ftxui/component/hoverable.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// Copyright 2022 Arthur Sonzogni. All rights reserved.
22
// Use of this source code is governed by the MIT license that can be found in
33
// the LICENSE file.
4-
#include <ftxui/component/captured_mouse.hpp> // for CapturedMouse
5-
#include <functional> // for function
6-
#include <utility> // for move
4+
#include <functional> // for function
5+
#include <utility> // for move
76

87
#include "ftxui/component/component.hpp" // for ComponentDecorator, Hoverable, Make
98
#include "ftxui/component/component_base.hpp" // for ComponentBase

src/ftxui/component/hoverable_test.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ TEST(HoverableTest, BasicCallback) {
6969
int on_enter_2 = 0;
7070
int on_leave_1 = 0;
7171
int on_leave_2 = 0;
72-
auto c1 = Hoverable(
73-
BasicComponent(), [&] { on_enter_1++; }, [&] { on_leave_1++; });
74-
auto c2 = Hoverable(
75-
BasicComponent(), [&] { on_enter_2++; }, [&] { on_leave_2++; });
72+
auto c1 =
73+
Hoverable(BasicComponent(), [&] { on_enter_1++; }, [&] { on_leave_1++; });
74+
auto c2 =
75+
Hoverable(BasicComponent(), [&] { on_enter_2++; }, [&] { on_leave_2++; });
7676
auto layout = Container::Horizontal({c1, c2});
7777
auto screen = Screen(8, 2);
7878
Render(screen, layout->Render());

src/ftxui/component/input.cpp

+38-31
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
#include <cstddef> // for size_t
66
#include <cstdint> // for uint32_t
77
#include <functional> // for function
8-
#include <memory> // for allocator, shared_ptr, allocator_traits<>::value_type
9-
#include <sstream> // for basic_istream, stringstream
10-
#include <string> // for string, basic_string, operator==, getline
11-
#include <utility> // for move
12-
#include <vector> // for vector
8+
#include <sstream> // for basic_istream, stringstream
9+
#include <string> // for string, basic_string, operator==, getline
10+
#include <utility> // for move
11+
#include <vector> // for vector
1312

14-
#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse
1513
#include "ftxui/component/component.hpp" // for Make, Input
1614
#include "ftxui/component/component_base.hpp" // for ComponentBase
1715
#include "ftxui/component/component_options.hpp" // for InputOption
@@ -134,7 +132,7 @@ class InputBase : public ComponentBase, public InputOption {
134132
break;
135133
}
136134

137-
cursor_char_index -= line.size() + 1;
135+
cursor_char_index -= static_cast<int>(line.size() + 1);
138136
cursor_line++;
139137
}
140138

@@ -164,7 +162,7 @@ class InputBase : public ComponentBase, public InputOption {
164162

165163
// The cursor is on this line.
166164
const int glyph_start = cursor_char_index;
167-
const int glyph_end = GlyphNext(line, glyph_start);
165+
const int glyph_end = static_cast<int>(GlyphNext(line, glyph_start));
168166
const std::string part_before_cursor = line.substr(0, glyph_start);
169167
const std::string part_at_cursor =
170168
line.substr(glyph_start, glyph_end - glyph_start);
@@ -206,7 +204,7 @@ class InputBase : public ComponentBase, public InputOption {
206204
const size_t start = GlyphPrevious(content(), cursor_position());
207205
const size_t end = cursor_position();
208206
content->erase(start, end - start);
209-
cursor_position() = start;
207+
cursor_position() = static_cast<int>(start);
210208
on_change();
211209
return true;
212210
}
@@ -234,7 +232,8 @@ class InputBase : public ComponentBase, public InputOption {
234232
return false;
235233
}
236234

237-
cursor_position() = GlyphPrevious(content(), cursor_position());
235+
cursor_position() =
236+
static_cast<int>(GlyphPrevious(content(), cursor_position()));
238237
return true;
239238
}
240239

@@ -243,7 +242,8 @@ class InputBase : public ComponentBase, public InputOption {
243242
return false;
244243
}
245244

246-
cursor_position() = GlyphNext(content(), cursor_position());
245+
cursor_position() =
246+
static_cast<int>(GlyphNext(content(), cursor_position()));
247247
return true;
248248
}
249249

@@ -258,7 +258,7 @@ class InputBase : public ComponentBase, public InputOption {
258258
if (content()[iter] == '\n') {
259259
break;
260260
}
261-
width += GlyphWidth(content(), iter);
261+
width += static_cast<int>(GlyphWidth(content(), iter));
262262
}
263263
return width;
264264
}
@@ -271,8 +271,9 @@ class InputBase : public ComponentBase, public InputOption {
271271
return;
272272
}
273273

274-
columns -= GlyphWidth(content(), cursor_position());
275-
cursor_position() = GlyphNext(content(), cursor_position());
274+
columns -= static_cast<int>(GlyphWidth(content(), cursor_position()));
275+
cursor_position() =
276+
static_cast<int>(GlyphNext(content(), cursor_position()));
276277
}
277278
}
278279

@@ -292,9 +293,10 @@ class InputBase : public ComponentBase, public InputOption {
292293
if (content()[previous] == '\n') {
293294
break;
294295
}
295-
cursor_position() = previous;
296+
cursor_position() = static_cast<int>(previous);
296297
}
297-
cursor_position() = GlyphPrevious(content(), cursor_position());
298+
cursor_position() =
299+
static_cast<int>(GlyphPrevious(content(), cursor_position()));
298300
while (true) {
299301
if (cursor_position() == 0) {
300302
break;
@@ -303,10 +305,10 @@ class InputBase : public ComponentBase, public InputOption {
303305
if (content()[previous] == '\n') {
304306
break;
305307
}
306-
cursor_position() = previous;
308+
cursor_position() = static_cast<int>(previous);
307309
}
308310

309-
MoveCursorColumn(columns);
311+
MoveCursorColumn(static_cast<int>(columns));
310312
return true;
311313
}
312314

@@ -322,14 +324,16 @@ class InputBase : public ComponentBase, public InputOption {
322324
if (content()[cursor_position()] == '\n') {
323325
break;
324326
}
325-
cursor_position() = GlyphNext(content(), cursor_position());
327+
cursor_position() =
328+
static_cast<int>(GlyphNext(content(), cursor_position()));
326329
if (cursor_position() == (int)content().size()) {
327330
return true;
328331
}
329332
}
330-
cursor_position() = GlyphNext(content(), cursor_position());
333+
cursor_position() =
334+
static_cast<int>(GlyphNext(content(), cursor_position()));
331335

332-
MoveCursorColumn(columns);
336+
MoveCursorColumn(static_cast<int>(columns));
333337
return true;
334338
}
335339

@@ -339,7 +343,7 @@ class InputBase : public ComponentBase, public InputOption {
339343
}
340344

341345
bool HandleEnd() {
342-
cursor_position() = content->size();
346+
cursor_position() = static_cast<int>(content->size());
343347
return true;
344348
}
345349

@@ -357,7 +361,7 @@ class InputBase : public ComponentBase, public InputOption {
357361
DeleteImpl();
358362
}
359363
content->insert(cursor_position(), character);
360-
cursor_position() += character.size();
364+
cursor_position() += static_cast<int>(character.size());
361365
on_change();
362366
return true;
363367
}
@@ -421,15 +425,15 @@ class InputBase : public ComponentBase, public InputOption {
421425
if (IsWordCharacter(content(), previous)) {
422426
break;
423427
}
424-
cursor_position() = previous;
428+
cursor_position() = static_cast<int>(previous);
425429
}
426430
// Move left, as long as left is a word character:
427431
while (cursor_position()) {
428432
const size_t previous = GlyphPrevious(content(), cursor_position());
429433
if (!IsWordCharacter(content(), previous)) {
430434
break;
431435
}
432-
cursor_position() = previous;
436+
cursor_position() = static_cast<int>(previous);
433437
}
434438
return true;
435439
}
@@ -441,7 +445,8 @@ class InputBase : public ComponentBase, public InputOption {
441445

442446
// Move right, until entering a word.
443447
while (cursor_position() < (int)content().size()) {
444-
cursor_position() = GlyphNext(content(), cursor_position());
448+
cursor_position() =
449+
static_cast<int>(GlyphNext(content(), cursor_position()));
445450
if (IsWordCharacter(content(), cursor_position())) {
446451
break;
447452
}
@@ -452,7 +457,7 @@ class InputBase : public ComponentBase, public InputOption {
452457
if (!IsWordCharacter(content(), cursor_position())) {
453458
break;
454459
}
455-
cursor_position() = next;
460+
cursor_position() = static_cast<int>(next);
456461
}
457462

458463
return true;
@@ -489,7 +494,7 @@ class InputBase : public ComponentBase, public InputOption {
489494
break;
490495
}
491496

492-
cursor_char_index -= line.size() + 1;
497+
cursor_char_index -= static_cast<int>(line.size() + 1);
493498
cursor_line++;
494499
}
495500
const int cursor_column =
@@ -515,11 +520,13 @@ class InputBase : public ComponentBase, public InputOption {
515520
// Convert back the new_cursor_{line,column} toward cursor_position:
516521
cursor_position() = 0;
517522
for (int i = 0; i < new_cursor_line; ++i) {
518-
cursor_position() += lines[i].size() + 1;
523+
cursor_position() += static_cast<int>(lines[i].size() + 1);
519524
}
520525
while (new_cursor_column > 0) {
521-
new_cursor_column -= GlyphWidth(content(), cursor_position());
522-
cursor_position() = GlyphNext(content(), cursor_position());
526+
new_cursor_column -=
527+
static_cast<int>(GlyphWidth(content(), cursor_position()));
528+
cursor_position() =
529+
static_cast<int>(GlyphNext(content(), cursor_position()));
523530
}
524531

525532
on_change();

src/ftxui/component/menu.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ class MenuBase : public ComponentBase, public MenuOption {
511511
/// entry 2
512512
/// entry 3
513513
/// ```
514+
// NOLINTNEXTLINE
514515
Component Menu(MenuOption option) {
515516
return Make<MenuBase>(std::move(option));
516517
}
@@ -543,7 +544,7 @@ Component Menu(MenuOption option) {
543544
/// entry 3
544545
/// ```
545546
Component Menu(ConstStringListRef entries, int* selected, MenuOption option) {
546-
option.entries = entries;
547+
option.entries = std::move(entries);
547548
option.selected = selected;
548549
return Menu(option);
549550
}
@@ -554,7 +555,7 @@ Component Menu(ConstStringListRef entries, int* selected, MenuOption option) {
554555
/// See also |Menu|.
555556
/// @ingroup component
556557
Component Toggle(ConstStringListRef entries, int* selected) {
557-
return Menu(entries, selected, MenuOption::Toggle());
558+
return Menu(std::move(entries), selected, MenuOption::Toggle());
558559
}
559560

560561
/// @brief A specific menu entry. They can be put into a Container::Vertical to

src/ftxui/component/radiobox.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ class RadioboxBase : public ComponentBase, public RadioboxOption {
204204
/// ○ entry 2
205205
/// ○ entry 3
206206
/// ```
207+
/// NOLINTNEXTLINE
207208
Component Radiobox(RadioboxOption option) {
208209
return Make<RadioboxBase>(std::move(option));
209210
}
@@ -239,7 +240,7 @@ Component Radiobox(RadioboxOption option) {
239240
Component Radiobox(ConstStringListRef entries,
240241
int* selected,
241242
RadioboxOption option) {
242-
option.entries = entries;
243+
option.entries = std::move(entries);
243244
option.selected = selected;
244245
return Make<RadioboxBase>(std::move(option));
245246
}

0 commit comments

Comments
 (0)