From ebf4d0f42d8f7879b3b41a5ea13746b0a30eb988 Mon Sep 17 00:00:00 2001 From: pantor Date: Sat, 18 Oct 2025 06:49:33 -0700 Subject: [PATCH] fix some clang-tidy warnings --- .clang-tidy | 4 +++- include/inja/parser.hpp | 6 +++--- include/inja/renderer.hpp | 4 ++-- single_include/inja/inja.hpp | 8 ++++---- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 317748b..38c2b2f 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -2,6 +2,7 @@ Checks: > *, -abseil-*, -altera-*, + -boost-*, -cppcoreguidelines-avoid-goto, -cppcoreguidelines-non-private-member-variables-in-classes, -fuchsia-*, @@ -11,7 +12,8 @@ Checks: > -misc-non-private-member-variables-in-classes, -modernize-*, -readability-function-cognitive-complexity, - -readability-identifier-length + -readability-identifier-length, + -readability-named-parameter # Turn all the warnings from the checks above into errors. HeaderFilterRegex: '.*/include/inja/.*\.hpp$' diff --git a/include/inja/parser.hpp b/include/inja/parser.hpp index 53098df..816f589 100644 --- a/include/inja/parser.hpp +++ b/include/inja/parser.hpp @@ -517,7 +517,7 @@ class Parser { throw_parser_error("expected id, got '" + tok.describe() + "'"); } - const Token key_token = std::move(value_token); + const Token key_token = value_token; value_token = tok; get_next_token(); @@ -667,13 +667,13 @@ public: const FunctionStorage& function_storage) : config(parser_config), lexer(lexer_config), template_storage(template_storage), function_storage(function_storage) {} - Template parse(std::string_view input, std::filesystem::path path) { + Template parse(std::string_view input, const std::filesystem::path& path) { auto result = Template(std::string(input)); parse_into(result, path); return result; } - void parse_into_template(Template& tmpl, std::filesystem::path filename) { + void parse_into_template(Template& tmpl, const std::filesystem::path& filename) { auto sub_parser = Parser(config, lexer.get_config(), template_storage, function_storage); sub_parser.parse_into(tmpl, filename.parent_path()); } diff --git a/include/inja/renderer.hpp b/include/inja/renderer.hpp index dbefa4a..32070a6 100644 --- a/include/inja/renderer.hpp +++ b/include/inja/renderer.hpp @@ -115,7 +115,7 @@ class Renderer : public NodeVisitor { const auto result = data_eval_stack.top(); data_eval_stack.pop(); - if (!result) { + if (result == nullptr) { if (not_found_stack.empty()) { throw_renderer_error("expression could not be evaluated", expression_list); } @@ -661,7 +661,7 @@ public: output_stream = &os; current_template = &tmpl; data_input = &data; - if (loop_data) { + if (loop_data != nullptr) { additional_data = *loop_data; current_loop_data = &additional_data["loop"]; } diff --git a/single_include/inja/inja.hpp b/single_include/inja/inja.hpp index 2a95e1f..14d2d29 100644 --- a/single_include/inja/inja.hpp +++ b/single_include/inja/inja.hpp @@ -2117,13 +2117,13 @@ public: const FunctionStorage& function_storage) : config(parser_config), lexer(lexer_config), template_storage(template_storage), function_storage(function_storage) {} - Template parse(std::string_view input, std::filesystem::path path) { + Template parse(std::string_view input, const std::filesystem::path& path) { auto result = Template(std::string(input)); parse_into(result, path); return result; } - void parse_into_template(Template& tmpl, std::filesystem::path filename) { + void parse_into_template(Template& tmpl, const std::filesystem::path& filename) { auto sub_parser = Parser(config, lexer.get_config(), template_storage, function_storage); sub_parser.parse_into(tmpl, filename.parent_path()); } @@ -2268,7 +2268,7 @@ class Renderer : public NodeVisitor { const auto result = data_eval_stack.top(); data_eval_stack.pop(); - if (!result) { + if (result == nullptr) { if (not_found_stack.empty()) { throw_renderer_error("expression could not be evaluated", expression_list); } @@ -2814,7 +2814,7 @@ public: output_stream = &os; current_template = &tmpl; data_input = &data; - if (loop_data) { + if (loop_data != nullptr) { additional_data = *loop_data; current_loop_data = &additional_data["loop"]; }