Fix clang-tidy findings in documentation examples and replace redundant aliases

Apply clang-tidy fixes to the documentation examples:
- performance-avoid-endl: std::endl -> '\n'
- readability-qualified-auto: auto -> auto* / const auto*
- performance-for-range-copy: copy -> const reference
- google-readability-casting: C-style cast -> static_cast

Replace redundant aliases (readability-redundant-qualified-alias) such as
"using json = nlohmann::json;" with "using nlohmann::json;" in the
documentation, README, examples, tests, and benchmarks. Aliases at class
scope and aliases of other types (with_base_class_t etc.) are kept.

No changes to the library or its public API. All changed examples were
compiled and run; their output matches the stored .output files (except
max_size and meta, which depend on the platform and compiler).

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann committed 2026-10-25 08:17:41 +01:00
1 parent d99cacf4a8
commit d93ea68633
366 files changed
+592 -592

No files matched your search

+1 -1
View File
@@ -21,7 +21,7 @@
#include <vector>
#include <test_data.hpp>
using json = nlohmann::json;
using nlohmann::json;
//////////////////////////////////////////////////////////////////////////////
// parse JSON from file
+2 -2
View File
@@ -17,8 +17,8 @@
#include <string>
#include <test_data.hpp>
using json = nlohmann::json;
using json_document = nlohmann::json_document;
using nlohmann::json;
using nlohmann::json_document;
static std::string read_file(const char* filename)
{
+2 -2
View File
@@ -33,8 +33,8 @@ drivers.
#error "the fuzzer drivers must be built without NDEBUG"
#endif
using json = nlohmann::json;
using json_document = nlohmann::json_document;
using nlohmann::json;
using nlohmann::json_document;
using image_check = json_document::image_check;
// see http://llvm.org/docs/LibFuzzer.html
+2 -2
View File
@@ -42,8 +42,8 @@ drivers.
#error "the fuzzer drivers must be built without NDEBUG"
#endif
using json = nlohmann::json;
using json_document = nlohmann::json_document;
using nlohmann::json;
using nlohmann::json_document;
namespace
{
+1 -1
View File
@@ -19,7 +19,7 @@
#include <nlohmann/json.hpp>
using nlohmann::json;
using ordered_json = nlohmann::ordered_json;
using nlohmann::ordered_json;
#include <algorithm>
#include <climits>
+1 -1
View File
@@ -14,7 +14,7 @@
#define JSON_DIAGNOSTIC_POSITIONS 1
#include <nlohmann/json.hpp>
using json = nlohmann::json;
using nlohmann::json;
TEST_CASE("Better diagnostics with positions")
{
+1 -1
View File
@@ -13,7 +13,7 @@ DOCTEST_GCC_SUPPRESS_WARNING_PUSH
DOCTEST_GCC_SUPPRESS_WARNING("-Wnoexcept")
#include <nlohmann/json.hpp>
using json = nlohmann::json;
using nlohmann::json;
#ifdef JSON_TEST_NO_GLOBAL_UDLS
using namespace nlohmann::literals; // NOLINT(google-build-using-namespace)
#endif
+3 -3
View File
@@ -1948,7 +1948,7 @@ TEST_CASE_TEMPLATE("element access 2 (additional value() tests)", Json, nlohmann
#ifdef JSON_HAS_CPP_17
TEST_CASE("operator[] with user-defined std::string_view-convertible types")
{
using json = nlohmann::json;
using nlohmann::json;
class TestClass
{
@@ -2031,7 +2031,7 @@ TEST_CASE("keys convertible to std::string_view work with all lookup functions (
SECTION("nlohmann::json")
{
using json = nlohmann::json;
using nlohmann::json;
SECTION("ViewKey")
{
@@ -2072,7 +2072,7 @@ TEST_CASE("keys convertible to std::string_view work with all lookup functions (
SECTION("nlohmann::ordered_json")
{
using ordered_json = nlohmann::ordered_json;
using nlohmann::ordered_json;
SECTION("ViewKey")
{
+1 -1
View File
@@ -15,7 +15,7 @@
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using json = nlohmann::json;
using nlohmann::json;
/////////////////////////////////////////////////////////////////////
// for #4825 - explicitly instantiating basic_json must compile; this
+2 -2
View File
@@ -9,8 +9,8 @@
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using json = nlohmann::json;
using ordered_json = nlohmann::ordered_json;
using nlohmann::json;
using nlohmann::ordered_json;
namespace
{
+2 -2
View File
@@ -9,8 +9,8 @@
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using json = nlohmann::json;
using ordered_json = nlohmann::ordered_json;
using nlohmann::json;
using nlohmann::ordered_json;
#include <limits>
#include <set>
+1 -1
View File
@@ -19,7 +19,7 @@
#include <utility>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
using nlohmann::json;
// An argument type whose associated namespace is the library namespace, so
// argument-dependent lookup of a literal operator called by its function name
+1 -1
View File
@@ -38,7 +38,7 @@ static int json_throw_user_call_count = 0; // NOLINT(cppcoreguidelines-avoid-non
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using json = nlohmann::json;
using nlohmann::json;
TEST_CASE("JSON_NO_IO")
{
+2 -2
View File
@@ -33,8 +33,8 @@
#define JSON_TESTS_PRIVATE
#include <nlohmann/json.hpp>
using json = nlohmann::json;
using ordered_json = nlohmann::ordered_json;
using nlohmann::json;
using nlohmann::ordered_json;
#ifdef JSON_TEST_NO_GLOBAL_UDLS
using namespace nlohmann::literals; // NOLINT(google-build-using-namespace)
#endif
+2 -2
View File
@@ -36,8 +36,8 @@
#define JSON_TESTS_PRIVATE
#include <nlohmann/json.hpp>
using json = nlohmann::json;
using ordered_json = nlohmann::ordered_json;
using nlohmann::json;
using nlohmann::ordered_json;
#ifdef JSON_TEST_NO_GLOBAL_UDLS
using namespace nlohmann::literals; // NOLINT(google-build-using-namespace)
#endif
+2 -2
View File
@@ -16,8 +16,8 @@
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using json = nlohmann::json;
using ordered_json = nlohmann::ordered_json;
using nlohmann::json;
using nlohmann::ordered_json;
// JSON_HAS_CPP_20 (do not remove; see note at top of file)
#if JSON_HAS_STD_FORMAT