From 458fefea8b7caeb40d886ac5b880d98998ddea4f Mon Sep 17 00:00:00 2001 From: Robin Linden Date: Wed, 1 Nov 2023 23:12:56 +0100 Subject: [PATCH] meta/clang-tidy: Enable a bunch more readability checks --- .clang-tidy | 10 ++++++++++ gfx/opengl_shader.cpp | 4 ++++ html2/character_reference.cpp | 2 +- html2/parser_states.cpp | 11 ++++------- html2/tokenizer_test.cpp | 2 +- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 8da58cff..3bafd76b 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -42,11 +42,21 @@ Checks: > modernize-*, performance-*, readability-container-size-empty, + readability-duplicate-include, readability-identifier-naming, readability-inconsistent-declaration-parameter-name, + readability-make-member-function-const, + readability-misleading-indentation, + readability-non-const-parameter, readability-qualified-auto, + readability-redundant-control-flow, + readability-redundant-preprocessor, readability-redundant-string-init, readability-simplify-boolean-expr, + readability-simplify-subscript-expr, + readability-static-definition-in-anonymous-namespace, + readability-string-compare, + readability-use-anyofallof, -bugprone-exception-escape, -bugprone-narrowing-conversions, -bugprone-unchecked-optional-access, diff --git a/gfx/opengl_shader.cpp b/gfx/opengl_shader.cpp index a7f466ad..091e965a 100644 --- a/gfx/opengl_shader.cpp +++ b/gfx/opengl_shader.cpp @@ -10,6 +10,9 @@ #include #include +// NOLINTBEGIN(readability-make-member-function-const): The drawing code +// shouldn't be thought of as const, even if it technically doesn't modify any +// class members. namespace gfx { std::optional OpenGLShader::create(std::string_view vertex_src, std::string_view fragment_src) { @@ -100,3 +103,4 @@ void OpenGLShader::set_uniform(char const *name, std::span data) } } // namespace gfx +// NOLINTEND(readability-make-member-function-const) diff --git a/html2/character_reference.cpp b/html2/character_reference.cpp index e07db63f..fa74e38f 100644 --- a/html2/character_reference.cpp +++ b/html2/character_reference.cpp @@ -29,7 +29,7 @@ namespace { // print(f'"{key}"sv', *codepoints, sep=', ', end='') // print('},') // ``` -static constexpr std::array kReferences = std::to_array({{"Æ"sv, 198}, +constexpr std::array kReferences = std::to_array({{"Æ"sv, 198}, {"Æ"sv, 198}, {"&"sv, 38}, {"&"sv, 38}, diff --git a/html2/parser_states.cpp b/html2/parser_states.cpp index bf49375a..86851521 100644 --- a/html2/parser_states.cpp +++ b/html2/parser_states.cpp @@ -9,6 +9,7 @@ #include "util/string.h" +#include #include #include #include @@ -145,14 +146,10 @@ constexpr bool is_quirky_public_identifier(std::string_view identifier) { return true; } - for (auto start : kQuirkyStartsOfPublicIdentifier) { - if (identifier.starts_with(start)) { - return true; - } - } - - return false; + return std::ranges::any_of( + kQuirkyStartsOfPublicIdentifier, [&](auto start) { return identifier.starts_with(start); }); } + constexpr bool is_quirky_when_system_identifier_is_empty(std::string_view public_identifier) { return public_identifier.starts_with("-//w3c//dtd html 4.01 frameset//") || public_identifier.starts_with("-//w3c//dtd html 4.01 transitional//"); diff --git a/html2/tokenizer_test.cpp b/html2/tokenizer_test.cpp index 45b9fac4..6855031d 100644 --- a/html2/tokenizer_test.cpp +++ b/html2/tokenizer_test.cpp @@ -26,7 +26,7 @@ using namespace html2; namespace { -static constexpr char const *kReplacementCharacter = "\xef\xbf\xbd"; +constexpr char const *kReplacementCharacter = "\xef\xbf\xbd"; struct ParseErrorWithLocation { ParseError error{};