Skip to content

style(clang-tidy): fix misc-use-anonymous-namespace #1699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 29 additions & 27 deletions src/core/jsonschema/frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

enum class AnchorType : std::uint8_t { Static, Dynamic, All };

static auto find_anchors(const sourcemeta::core::JSON &schema,
const sourcemeta::core::Vocabularies &vocabularies)
namespace {

auto find_anchors(const sourcemeta::core::JSON &schema,
const sourcemeta::core::Vocabularies &vocabularies)
-> std::map<sourcemeta::core::JSON::String, AnchorType> {
std::map<sourcemeta::core::JSON::String, AnchorType> result;

Expand Down Expand Up @@ -98,7 +100,7 @@ static auto find_anchors(const sourcemeta::core::JSON &schema,
return result;
}

static auto find_nearest_bases(
auto find_nearest_bases(
const std::map<sourcemeta::core::Pointer,
std::vector<sourcemeta::core::JSON::String>> &bases,
const sourcemeta::core::Pointer &pointer,
Expand All @@ -118,7 +120,7 @@ static auto find_nearest_bases(
return {{}, sourcemeta::core::empty_pointer};
}

static auto find_every_base(
auto find_every_base(
const std::map<sourcemeta::core::Pointer,
std::vector<sourcemeta::core::JSON::String>> &bases,
const sourcemeta::core::Pointer &pointer)
Expand All @@ -145,7 +147,7 @@ static auto find_every_base(
return result;
}

static auto ref_overrides_adjacent_keywords(
auto ref_overrides_adjacent_keywords(
const sourcemeta::core::JSON::String &base_dialect) -> bool {
// In older drafts, the presence of `$ref` would override any sibling
// keywords
Expand All @@ -161,8 +163,7 @@ static auto ref_overrides_adjacent_keywords(
base_dialect == "http://json-schema.org/draft-03/hyper-schema#";
}

static auto
supports_id_anchors(const sourcemeta::core::JSON::String &base_dialect)
auto supports_id_anchors(const sourcemeta::core::JSON::String &base_dialect)
-> bool {
return base_dialect == "http://json-schema.org/draft-07/schema#" ||
base_dialect == "http://json-schema.org/draft-07/hyper-schema#" ||
Expand All @@ -172,7 +173,7 @@ supports_id_anchors(const sourcemeta::core::JSON::String &base_dialect)
base_dialect == "http://json-schema.org/draft-04/hyper-schema#";
}

static auto fragment_string(const sourcemeta::core::URI &uri)
auto fragment_string(const sourcemeta::core::URI &uri)
-> std::optional<sourcemeta::core::JSON::String> {
const auto fragment{uri.fragment()};
if (fragment.has_value()) {
Expand All @@ -183,28 +184,27 @@ static auto fragment_string(const sourcemeta::core::URI &uri)
}

[[noreturn]]
static auto throw_already_exists(const sourcemeta::core::JSON::String &uri)
-> void {
auto throw_already_exists(const sourcemeta::core::JSON::String &uri) -> void {
std::ostringstream error;
error << "Schema identifier already exists: " << uri;
throw sourcemeta::core::SchemaError(error.str());
}

static auto
store(sourcemeta::core::SchemaFrame::Locations &frame,
sourcemeta::core::SchemaFrame::Instances &instances,
const sourcemeta::core::SchemaReferenceType type,
const sourcemeta::core::SchemaFrame::LocationType entry_type,
const sourcemeta::core::JSON::String &uri,
const std::optional<sourcemeta::core::JSON::String> &root_id,
const sourcemeta::core::JSON::String &base_id,
const sourcemeta::core::Pointer &pointer_from_root,
const sourcemeta::core::Pointer &pointer_from_base,
const sourcemeta::core::JSON::String &dialect,
const sourcemeta::core::JSON::String &base_dialect,
const std::vector<sourcemeta::core::PointerTemplate> &instance_locations,
const std::optional<sourcemeta::core::Pointer> &parent,
const bool ignore_if_present = false) -> void {
auto store(
sourcemeta::core::SchemaFrame::Locations &frame,
sourcemeta::core::SchemaFrame::Instances &instances,
const sourcemeta::core::SchemaReferenceType type,
const sourcemeta::core::SchemaFrame::LocationType entry_type,
const sourcemeta::core::JSON::String &uri,
const std::optional<sourcemeta::core::JSON::String> &root_id,
const sourcemeta::core::JSON::String &base_id,
const sourcemeta::core::Pointer &pointer_from_root,
const sourcemeta::core::Pointer &pointer_from_base,
const sourcemeta::core::JSON::String &dialect,
const sourcemeta::core::JSON::String &base_dialect,
const std::vector<sourcemeta::core::PointerTemplate> &instance_locations,
const std::optional<sourcemeta::core::Pointer> &parent,
const bool ignore_if_present = false) -> void {
assert(std::set<sourcemeta::core::PointerTemplate>(
instance_locations.cbegin(), instance_locations.cend())
.size() == instance_locations.size());
Expand All @@ -227,7 +227,7 @@ struct InternalEntry {
const std::optional<sourcemeta::core::JSON::String> id;
};

static auto traverse_origin_instance_locations(
auto traverse_origin_instance_locations(
const sourcemeta::core::SchemaFrame &frame,
const sourcemeta::core::SchemaFrame::Instances &instances,
const sourcemeta::core::Pointer &current,
Expand Down Expand Up @@ -264,7 +264,7 @@ struct CacheSubschema {
const std::optional<sourcemeta::core::Pointer> parent;
};

static auto repopulate_instance_locations(
auto repopulate_instance_locations(
const sourcemeta::core::SchemaFrame &frame,
const sourcemeta::core::SchemaFrame::Instances &instances,
const std::map<sourcemeta::core::Pointer, CacheSubschema> &cache,
Expand Down Expand Up @@ -314,6 +314,8 @@ static auto repopulate_instance_locations(
}
}

} // namespace

namespace sourcemeta::core {

auto SchemaFrame::to_json() const -> JSON {
Expand Down
6 changes: 5 additions & 1 deletion src/core/jsonschema/jsonschema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ auto sourcemeta::core::is_schema(const sourcemeta::core::JSON &schema) -> bool {
return schema.is_object() || schema.is_boolean();
}

static auto id_keyword_guess(const sourcemeta::core::JSON &schema)
namespace {

auto id_keyword_guess(const sourcemeta::core::JSON &schema)
-> std::optional<std::string> {
if (schema.defines("$id") && schema.at("$id").is_string()) {
if (!schema.defines("id") ||
Expand Down Expand Up @@ -55,6 +57,8 @@ static auto id_keyword(const std::string &base_dialect) -> std::string {
throw sourcemeta::core::SchemaError(error.str());
}

} // namespace

auto sourcemeta::core::identify(
const sourcemeta::core::JSON &schema, const SchemaResolver &resolver,
const SchemaIdentificationStrategy strategy,
Expand Down
19 changes: 11 additions & 8 deletions src/core/uri/uri.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
#include <utility> // std::move
#include <vector> // std::vector

static auto uri_normalize(UriUriA *uri) -> void {
namespace {

auto uri_normalize(UriUriA *uri) -> void {
if (uriNormalizeSyntaxA(uri) != URI_SUCCESS) {
throw sourcemeta::core::URIError{"Could not normalize URI"};
}
}

static auto uri_to_string(const UriUriA *const uri) -> std::string {
int size = 0;
auto uri_to_string(const UriUriA *const uri) -> std::string {
int size;
if (uriToStringCharsRequiredA(uri, &size) != URI_SUCCESS) {
throw sourcemeta::core::URIError{"Could not determine URI size"};
}
Expand All @@ -37,7 +39,7 @@ static auto uri_to_string(const UriUriA *const uri) -> std::string {
return result;
}

static auto uri_text_range(const UriTextRangeA *const range)
auto uri_text_range(const UriTextRangeA *const range)
-> std::optional<std::string_view> {
if (range->afterLast == nullptr) {
return std::nullopt;
Expand All @@ -48,8 +50,8 @@ static auto uri_text_range(const UriTextRangeA *const range)
range->afterLast - range->first)};
}

static auto uri_parse(const std::string &data, UriUriA *uri) -> void {
const char *error_position = nullptr;
auto uri_parse(const std::string &data, UriUriA *uri) -> void {
const char *error_position;
switch (uriParseSingleUriA(uri, data.c_str(), &error_position)) {
case URI_ERROR_SYNTAX:
// TODO: Test the positions of this error
Expand All @@ -68,8 +70,7 @@ static auto uri_parse(const std::string &data, UriUriA *uri) -> void {
uri_normalize(uri);
}

static auto canonicalize_path(const std::string &path)
-> std::optional<std::string> {
auto canonicalize_path(const std::string &path) -> std::optional<std::string> {
// TODO: This is a hack, as this whole function works badly for
// relative paths with ".."
if (path.starts_with("..")) {
Expand Down Expand Up @@ -113,6 +114,8 @@ static auto canonicalize_path(const std::string &path)
return canonical_path;
}

} // namespace

namespace sourcemeta::core {

struct URI::Internal {
Expand Down
10 changes: 6 additions & 4 deletions src/core/yaml/yaml.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
#include <sstream> // std::ostringstream, std::istringstream
#include <string_view> // std::string_view

namespace {

// TODO: Perform parsing token by token using `yaml_parser_parse`,
// as that function also let us get line/column information on `yaml_event_t`
static auto yaml_node_to_json(yaml_node_t *const node,
yaml_document_t *const document)
auto yaml_node_to_json(yaml_node_t *const node, yaml_document_t *const document)
-> sourcemeta::core::JSON {
if (!node) {
return sourcemeta::core::JSON{nullptr};
Expand Down Expand Up @@ -81,8 +82,7 @@ static auto yaml_node_to_json(yaml_node_t *const node,
}
}

static auto internal_parse_json(yaml_parser_t *parser)
-> sourcemeta::core::JSON {
auto internal_parse_json(yaml_parser_t *parser) -> sourcemeta::core::JSON {
yaml_document_t document;
if (!yaml_parser_load(parser, &document)) {
// TODO: Ideally we would get line/column information like for `ParseError`
Expand All @@ -105,6 +105,8 @@ static auto internal_parse_json(yaml_parser_t *parser)
}
}

} // namespace

namespace sourcemeta::core {

auto parse_yaml(std::basic_istream<JSON::Char, JSON::CharTraits> &stream)
Expand Down