From 6fe4fb2b95a813c1dd86cedc383fe9e9dfa5530c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Thu, 14 Nov 2024 00:12:50 +0100 Subject: [PATCH] nixos-option: enable cppcoreguidelines lints --- pkgs/tools/nix/nixos-option/.clang-tidy | 7 ++++--- .../nix/nixos-option/src/nixos-option.cc | 19 +++++++++++++------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/pkgs/tools/nix/nixos-option/.clang-tidy b/pkgs/tools/nix/nixos-option/.clang-tidy index 1041f79bdece..1d92756771f3 100644 --- a/pkgs/tools/nix/nixos-option/.clang-tidy +++ b/pkgs/tools/nix/nixos-option/.clang-tidy @@ -16,9 +16,10 @@ Checks: - misc-* # we maybe want to address this? - -misc-no-recursion -# TODO -# - cppcoreguidelines-* -# - -cppcoreguidelines-avoid-magic-numbers +- cppcoreguidelines-* +- -cppcoreguidelines-avoid-magic-numbers +# We could use std::reference_wrapper, but it's not super important +- -cppcoreguidelines-avoid-const-or-ref-data-members UseColor: true CheckOptions: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: True diff --git a/pkgs/tools/nix/nixos-option/src/nixos-option.cc b/pkgs/tools/nix/nixos-option/src/nixos-option.cc index bd7d3b5ae631..6846cc7e5fbb 100644 --- a/pkgs/tools/nix/nixos-option/src/nixos-option.cc +++ b/pkgs/tools/nix/nixos-option/src/nixos-option.cc @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -347,7 +348,7 @@ void mapConfigValuesInOption( const std::function v)> & f, const std::string & path, Context & ctx) { - Value * option; + Value * option = nullptr; try { option = findAlongAttrPath(ctx.state, path, ctx.autoArgs, ctx.configRoot).first; } catch (Error &) { @@ -396,8 +397,8 @@ void printValue(Context & ctx, Out & out, std::variant(v.listSize())); - for (unsigned int n = 0; n < v.listSize(); ++n) { - printValue(ctx, listOut, *v.listElems()[n], ""); + for (auto *elem : v.listItems()) { + printValue(ctx, listOut, *elem, ""); listOut << Out::sep; } } @@ -417,7 +418,7 @@ void printAttrs(Context & ctx, Out & out, Value & v, const std::string & path) void multiLineStringEscape(Out & out, const std::string_view & s) { - size_t i; + size_t i = 0; for (i = 1; i < s.size(); i++) { if (s[i - 1] == '$' && s[i] == '{') { out << "''${"; @@ -591,7 +592,8 @@ void printOne(Context & ctx, Out & out, const std::string & path) int main(int argc, char ** argv) { - return nix::handleExceptions(argv[0], [&]() { + auto args = std::span(argv, argc); + return nix::handleExceptions(args[0], [&]() { bool recursive = false; std::string path = "."; std::string optionsExpr = "(import {}).options"; @@ -600,10 +602,15 @@ int main(int argc, char ** argv) struct MyArgs : nix::LegacyArgs, nix::MixEvalArgs { + MyArgs(const MyArgs& other) = default; + MyArgs(MyArgs&& other) noexcept = default; + auto operator=(const MyArgs& other) noexcept -> MyArgs& = default; + auto operator=(MyArgs&& other) noexcept -> MyArgs& = default; + virtual ~MyArgs() = default; using nix::LegacyArgs::LegacyArgs; }; - MyArgs myArgs(std::string(nix::baseNameOf(argv[0])), [&](Strings::iterator & arg, const Strings::iterator & end) { + MyArgs myArgs(std::string(nix::baseNameOf(args[0])), [&](Strings::iterator & arg, const Strings::iterator & end) { if (*arg == "--help") { nix::showManPage("nixos-option"); } else if (*arg == "--version") {