Skip to content

Commit

Permalink
Extend clang-tidy checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaraslaut committed Nov 14, 2024
1 parent cd7d26e commit e94d95c
Show file tree
Hide file tree
Showing 59 changed files with 993 additions and 771 deletions.
5 changes: 4 additions & 1 deletion src/.clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ Checks: >-
-readability-container-contains,
-readability-convert-member-functions-to-static,
-readability-else-after-return,
-readability-function-cognitive-complexity,
-readability-identifier-length,
-readability-implicit-bool-conversion,
-readability-magic-numbers,
Expand All @@ -77,6 +76,8 @@ WarningsAsErrors: >-
misc-const-correctness,
modernize-use-nullptr,
modernize-use-constraints,
modernize-use-designated-initializers,
readability-math-missing-parentheses,
bugprone-narrowing-conversions,
UseColor: true
HeaderFilterRegex: 'src/(contour|crispy|text_shaper|vtpty|vtparser|vtbackend|vtrasterizer)/'
Expand Down Expand Up @@ -154,3 +155,5 @@ CheckOptions:
value: camelBack
- key: readability-identifier-naming.ConstantCasePrefix
value: ''
- key: readability-function-cognitive-complexity.Threshold
value: '50'
2 changes: 1 addition & 1 deletion src/contour/BlurBehind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace
return nullopt;
auto const atomName = reply->atom;

return XcbPropertyInfo { xcbConnection, winId, atomName };
return XcbPropertyInfo { .connection = xcbConnection, .window = winId, .propertyAtom = atomName };
}

void setPropertyX11(QWindow* window, string const& name, uint32_t value)
Expand Down
2 changes: 1 addition & 1 deletion src/contour/CaptureScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ bool captureScreen(CaptureSettings const& settings)
settings.logicalLines ? "logical" : "physical",
settings.lineCount,
settings.words ? "words" : "lines",
settings.outputFile.data());
settings.outputFile);

// request screen capture
reference_wrapper<ostream> output(cout);
Expand Down
8 changes: 5 additions & 3 deletions src/contour/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <QtCore/QFile>
#include <QtGui/QOpenGLContext>

#include <algorithm>
#include <fstream>
#include <iostream>

Expand Down Expand Up @@ -272,7 +273,7 @@ void compareEntries(Config& config, auto const& output)

for (auto const& entry: existingEntries)
{
if (std::find(userEntries.begin(), userEntries.end(), entry) == userEntries.end())
if (std::ranges::find(userEntries, entry) == userEntries.end())
{
output()("[diff] Entry {} is missing in user config file\n", entry);
}
Expand Down Expand Up @@ -1098,7 +1099,7 @@ void YAMLConfigReader::loadFromEntry(YAML::Node const& node, std::string const&
loadFromEntry(child, "max_width", width);
uint height = 0;
loadFromEntry(child, "max_height", height);
where.maxImageSize = { vtpty::Width { width }, vtpty::Height { height } };
where.maxImageSize = { .width = vtpty::Width { width }, .height = vtpty::Height { height } };
}
}

Expand Down Expand Up @@ -1260,7 +1261,7 @@ void YAMLConfigReader::loadFromEntry(YAML::Node const& node,
{
if (literal == deprecated)
{
errorLog()("Setting font locator to \"{}\" is deprecated. Use \"native\".", literal);
errorLog()(R"(Setting font locator to "{}" is deprecated. Use "native".)", literal);
return NativeFontLocator;
}
}
Expand Down Expand Up @@ -1803,6 +1804,7 @@ std::optional<vtbackend::Modifiers> YAMLConfigReader::parseModifierKey(std::stri
return std::nullopt;
}

// NOLINTNEXTLINE(readability-function-cognitive-complexity)
std::optional<actions::Action> YAMLConfigReader::parseAction(YAML::Node const& node)
{
if (auto actionNode = node["action"])
Expand Down
9 changes: 6 additions & 3 deletions src/contour/ContourApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ int ContourApp::profileAction()

crispy::cli::command ContourApp::parameterDefinition() const
{
// NOLINTBEGIN
return CLI::command {
"contour",
"Contour Terminal Emulator " CONTOUR_VERSION_STRING
Expand Down Expand Up @@ -574,9 +575,10 @@ crispy::cli::command ContourApp::parameterDefinition() const
"capture",
"Captures the screen buffer of the currently running terminal.",
{
CLI::option { "logical",
CLI::value { false },
"Tells the terminal to use logical lines for counting and capturing." },
CLI::option { .name = "logical",
.v = CLI::value { false },
.helpText =
"Tells the terminal to use logical lines for counting and capturing." },
CLI::option { "words",
CLI::value { false },
"Splits each line into words and outputs only one word per line." },
Expand Down Expand Up @@ -606,6 +608,7 @@ crispy::cli::command ContourApp::parameterDefinition() const
"Profile name to activate in the currently connected terminal.",
"NAME" } } } } } }
};
// NOLINTEND
}

} // namespace contour
2 changes: 2 additions & 0 deletions src/contour/ContourGuiApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ crispy::cli::command ContourGuiApp::parameterDefinition() const
{
auto command = ContourApp::parameterDefinition();

// NOLINTBEGIN
command.children.insert(
command.children.begin(),
CLI::command {
Expand Down Expand Up @@ -147,6 +148,7 @@ crispy::cli::command ContourGuiApp::parameterDefinition() const
CLI::verbatim { "PROGRAM ARGS...",
"Executes given program instead of the one provided in the configuration." } });

// NOLINTEND
return command;
}

Expand Down
4 changes: 2 additions & 2 deletions src/contour/TerminalSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ void TerminalSession::requestCaptureBuffer(LineCount lines, bool logical)
if (!_display)
return;

_pendingBufferCapture = CaptureBufferRequest { lines, logical };
_pendingBufferCapture = CaptureBufferRequest { .lines = lines, .logical = logical };

emit requestPermissionForBufferCapture();
// _display->post(
Expand Down Expand Up @@ -1499,7 +1499,7 @@ int TerminalSession::executeAllActions(std::vector<actions::Action> const& actio
}

auto const containsToggleKeybind = [](std::vector<actions::Action> const& actions) {
return std::any_of(actions.begin(), actions.end(), [](actions::Action const& action) {
return std::ranges::any_of(actions, [](actions::Action const& action) {
return holds_alternative<actions::ToggleAllKeyMaps>(action);
});
};
Expand Down
3 changes: 2 additions & 1 deletion src/contour/TerminalSessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <QtQml/QQmlEngine>

#include <algorithm>
#include <string>

using namespace std::string_literals;
Expand Down Expand Up @@ -179,7 +180,7 @@ void TerminalSessionManager::removeSession(TerminalSession& thatSession)

_app.onExit(thatSession); // TODO: the logic behind that impl could probably be moved here.

auto i = std::find_if(_sessions.begin(), _sessions.end(), [&](auto p) { return p == &thatSession; });
auto i = std::ranges::find_if(_sessions, [&](auto p) { return p == &thatSession; });
if (i != _sessions.end())
{
_sessions.erase(i);
Expand Down
6 changes: 4 additions & 2 deletions src/contour/display/ShaderConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@ ShaderConfig builtinShaderConfig(ShaderClass shaderClass)
auto const fileContents = file.readAll().toStdString();

auto const fileHeader = versionHeader + sharedDefines;
return ShaderSource { shaderFilePath, QString::fromStdString(fileHeader + fileContents) };
return ShaderSource { .location = shaderFilePath,
.contents = QString::fromStdString(fileHeader + fileContents) };
};
QString const basename = QString::fromStdString(to_string(shaderClass));
return ShaderConfig { makeSource(basename + ".vert"), makeSource(basename + ".frag") };
return ShaderConfig { .vertexShader = makeSource(basename + ".vert"),
.fragmentShader = makeSource(basename + ".frag") };
};
return makeConfig(shaderClass);
}
Expand Down
2 changes: 1 addition & 1 deletion src/contour/display/TerminalDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ vtbackend::RefreshRate TerminalDisplay::refreshRate() const

DPI TerminalDisplay::fontDPI() const noexcept
{
return DPI { 96, 96 } * contentScale();
return DPI { .x = 96, .y = 96 } * contentScale();
}

bool TerminalDisplay::isFullScreen() const
Expand Down
37 changes: 18 additions & 19 deletions src/contour/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace
auto const col = vtbackend::ColumnOffset(
clamp((sx - marginLeft) / cellSize.width.as<int>(), 0, *pageSize.columns - 1));

return { row, col };
return { .line = row, .column = col };
}

PixelCoordinate makeMousePixelPosition(QHoverEvent* event,
Expand All @@ -85,8 +85,8 @@ namespace
#endif
auto const marginLeft = static_cast<int>(unbox(margins.horizontal) * dpr);
auto const marginTop = static_cast<int>(unbox(margins.vertical) * dpr);
return PixelCoordinate { PixelCoordinate::X { int(double(position.x()) * dpr) - marginLeft },
PixelCoordinate::Y { int(double(position.y()) * dpr) - marginTop } };
return PixelCoordinate { .x = PixelCoordinate::X { int(double(position.x()) * dpr) - marginLeft },
.y = PixelCoordinate::Y { int(double(position.y()) * dpr) - marginTop } };
}

PixelCoordinate makeMousePixelPosition(QMouseEvent* event,
Expand All @@ -100,8 +100,8 @@ namespace
#endif
auto const marginLeft = static_cast<int>(unbox(margins.horizontal) * dpr);
auto const marginTop = static_cast<int>(unbox(margins.vertical) * dpr);
return PixelCoordinate { PixelCoordinate::X { int(double(position.x()) * dpr) - marginLeft },
PixelCoordinate::Y { int(double(position.y()) * dpr) - marginTop } };
return PixelCoordinate { .x = PixelCoordinate::X { int(double(position.x()) * dpr) - marginLeft },
.y = PixelCoordinate::Y { int(double(position.y()) * dpr) - marginTop } };
}

PixelCoordinate makeMousePixelPosition(QWheelEvent* event,
Expand All @@ -115,8 +115,8 @@ namespace
#endif
auto const marginLeft = static_cast<int>(unbox(margins.horizontal) * dpr);
auto const marginTop = static_cast<int>(unbox(margins.vertical) * dpr);
return PixelCoordinate { PixelCoordinate::X { int(double(position.x()) * dpr) - marginLeft },
PixelCoordinate::Y { int(double(position.y()) * dpr) - marginTop } };
return PixelCoordinate { .x = PixelCoordinate::X { int(double(position.x()) * dpr) - marginLeft },
.y = PixelCoordinate::Y { int(double(position.y()) * dpr) - marginTop } };
}

QPoint transposed(QPoint p) noexcept
Expand All @@ -137,7 +137,7 @@ namespace

inputLog()("[{}] Accumulate scroll with current value {}",
modifiers,
crispy::point { session.getScrollX(), session.getScrollY() });
crispy::point { .x = session.getScrollX(), .y = session.getScrollY() });

if (std::abs(session.getScrollX()) > unbox<int>(session.terminal().cellPixelSize().width))
{
Expand Down Expand Up @@ -357,8 +357,8 @@ bool sendKeyEvent(QKeyEvent* event, vtbackend::KeyboardEventType eventType, Term
}

// NOLINTNEXTLINE(readability-qualified-auto)
if (auto const i = find_if(
begin(KeyMappings), end(KeyMappings), [event](auto const& x) { return x.first == event->key(); });
if (auto const i =
std::ranges::find_if(KeyMappings, [event](auto const& x) { return x.first == event->key(); });
i != end(KeyMappings))
{
session.sendKeyEvent(i->second, modifiers, eventType, now);
Expand All @@ -370,9 +370,8 @@ bool sendKeyEvent(QKeyEvent* event, vtbackend::KeyboardEventType eventType, Term
if (event->text().isEmpty())
{
// NOLINTNEXTLINE(readability-qualified-auto)
if (auto const i = find_if(begin(CharMappings),
end(CharMappings),
[event](auto const& x) { return x.first == event->key(); });
if (auto const i = std::ranges::find_if(CharMappings,
[event](auto const& x) { return x.first == event->key(); });
i != end(CharMappings))
{
session.sendCharEvent(static_cast<char32_t>(i->second), physicalKey, modifiers, eventType, now);
Expand Down Expand Up @@ -559,12 +558,12 @@ vtbackend::FontDef getFontDefinition(vtrasterizer::Renderer& renderer)
else
return styledFont.toPattern();
};
return { renderer.fontDescriptions().size.pt,
renderer.fontDescriptions().regular.familyName,
nameOfStyledFont(text::font_weight::bold, text::font_slant::normal),
nameOfStyledFont(text::font_weight::normal, text::font_slant::italic),
nameOfStyledFont(text::font_weight::bold, text::font_slant::italic),
renderer.fontDescriptions().emoji.toPattern() };
return { .size = renderer.fontDescriptions().size.pt,
.regular = renderer.fontDescriptions().regular.familyName,
.bold = nameOfStyledFont(text::font_weight::bold, text::font_slant::normal),
.italic = nameOfStyledFont(text::font_weight::normal, text::font_slant::italic),
.boldItalic = nameOfStyledFont(text::font_weight::bold, text::font_slant::italic),
.emoji = renderer.fontDescriptions().emoji.toPattern() };
}

vtrasterizer::PageMargin computeMargin(ImageSize cellSize,
Expand Down
5 changes: 2 additions & 3 deletions src/crispy/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ void app::link(std::string command, std::function<int()> handler)
void app::listDebugTags()
{
auto& categories = logstore::get();
sort(begin(categories), end(categories), [](auto const& a, auto const& b) {
return a.get().name() < b.get().name();
});
std::ranges::sort(categories,
[](auto const& a, auto const& b) { return a.get().name() < b.get().name(); });

auto const maxNameLength =
std::accumulate(begin(categories), end(categories), size_t { 0 }, [&](auto acc, auto const& cat) {
Expand Down
Loading

0 comments on commit e94d95c

Please sign in to comment.