Skip to content

Commit a9de30f

Browse files
authored
style(clang-tidy): fix misc-use-anonymous-namespace (#1699)
Fixes #1678 Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
1 parent 37b3519 commit a9de30f

File tree

4 files changed

+51
-40
lines changed

4 files changed

+51
-40
lines changed

src/core/jsonschema/frame.cc

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

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

15-
static auto find_anchors(const sourcemeta::core::JSON &schema,
16-
const sourcemeta::core::Vocabularies &vocabularies)
15+
namespace {
16+
17+
auto find_anchors(const sourcemeta::core::JSON &schema,
18+
const sourcemeta::core::Vocabularies &vocabularies)
1719
-> std::map<sourcemeta::core::JSON::String, AnchorType> {
1820
std::map<sourcemeta::core::JSON::String, AnchorType> result;
1921

@@ -98,7 +100,7 @@ static auto find_anchors(const sourcemeta::core::JSON &schema,
98100
return result;
99101
}
100102

101-
static auto find_nearest_bases(
103+
auto find_nearest_bases(
102104
const std::map<sourcemeta::core::Pointer,
103105
std::vector<sourcemeta::core::JSON::String>> &bases,
104106
const sourcemeta::core::Pointer &pointer,
@@ -118,7 +120,7 @@ static auto find_nearest_bases(
118120
return {{}, sourcemeta::core::empty_pointer};
119121
}
120122

121-
static auto find_every_base(
123+
auto find_every_base(
122124
const std::map<sourcemeta::core::Pointer,
123125
std::vector<sourcemeta::core::JSON::String>> &bases,
124126
const sourcemeta::core::Pointer &pointer)
@@ -145,7 +147,7 @@ static auto find_every_base(
145147
return result;
146148
}
147149

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

164-
static auto
165-
supports_id_anchors(const sourcemeta::core::JSON::String &base_dialect)
166+
auto supports_id_anchors(const sourcemeta::core::JSON::String &base_dialect)
166167
-> bool {
167168
return base_dialect == "http://json-schema.org/draft-07/schema#" ||
168169
base_dialect == "http://json-schema.org/draft-07/hyper-schema#" ||
@@ -172,7 +173,7 @@ supports_id_anchors(const sourcemeta::core::JSON::String &base_dialect)
172173
base_dialect == "http://json-schema.org/draft-04/hyper-schema#";
173174
}
174175

175-
static auto fragment_string(const sourcemeta::core::URI &uri)
176+
auto fragment_string(const sourcemeta::core::URI &uri)
176177
-> std::optional<sourcemeta::core::JSON::String> {
177178
const auto fragment{uri.fragment()};
178179
if (fragment.has_value()) {
@@ -183,28 +184,27 @@ static auto fragment_string(const sourcemeta::core::URI &uri)
183184
}
184185

185186
[[noreturn]]
186-
static auto throw_already_exists(const sourcemeta::core::JSON::String &uri)
187-
-> void {
187+
auto throw_already_exists(const sourcemeta::core::JSON::String &uri) -> void {
188188
std::ostringstream error;
189189
error << "Schema identifier already exists: " << uri;
190190
throw sourcemeta::core::SchemaError(error.str());
191191
}
192192

193-
static auto
194-
store(sourcemeta::core::SchemaFrame::Locations &frame,
195-
sourcemeta::core::SchemaFrame::Instances &instances,
196-
const sourcemeta::core::SchemaReferenceType type,
197-
const sourcemeta::core::SchemaFrame::LocationType entry_type,
198-
const sourcemeta::core::JSON::String &uri,
199-
const std::optional<sourcemeta::core::JSON::String> &root_id,
200-
const sourcemeta::core::JSON::String &base_id,
201-
const sourcemeta::core::Pointer &pointer_from_root,
202-
const sourcemeta::core::Pointer &pointer_from_base,
203-
const sourcemeta::core::JSON::String &dialect,
204-
const sourcemeta::core::JSON::String &base_dialect,
205-
const std::vector<sourcemeta::core::PointerTemplate> &instance_locations,
206-
const std::optional<sourcemeta::core::Pointer> &parent,
207-
const bool ignore_if_present = false) -> void {
193+
auto store(
194+
sourcemeta::core::SchemaFrame::Locations &frame,
195+
sourcemeta::core::SchemaFrame::Instances &instances,
196+
const sourcemeta::core::SchemaReferenceType type,
197+
const sourcemeta::core::SchemaFrame::LocationType entry_type,
198+
const sourcemeta::core::JSON::String &uri,
199+
const std::optional<sourcemeta::core::JSON::String> &root_id,
200+
const sourcemeta::core::JSON::String &base_id,
201+
const sourcemeta::core::Pointer &pointer_from_root,
202+
const sourcemeta::core::Pointer &pointer_from_base,
203+
const sourcemeta::core::JSON::String &dialect,
204+
const sourcemeta::core::JSON::String &base_dialect,
205+
const std::vector<sourcemeta::core::PointerTemplate> &instance_locations,
206+
const std::optional<sourcemeta::core::Pointer> &parent,
207+
const bool ignore_if_present = false) -> void {
208208
assert(std::set<sourcemeta::core::PointerTemplate>(
209209
instance_locations.cbegin(), instance_locations.cend())
210210
.size() == instance_locations.size());
@@ -227,7 +227,7 @@ struct InternalEntry {
227227
const std::optional<sourcemeta::core::JSON::String> id;
228228
};
229229

230-
static auto traverse_origin_instance_locations(
230+
auto traverse_origin_instance_locations(
231231
const sourcemeta::core::SchemaFrame &frame,
232232
const sourcemeta::core::SchemaFrame::Instances &instances,
233233
const sourcemeta::core::Pointer &current,
@@ -264,7 +264,7 @@ struct CacheSubschema {
264264
const std::optional<sourcemeta::core::Pointer> parent;
265265
};
266266

267-
static auto repopulate_instance_locations(
267+
auto repopulate_instance_locations(
268268
const sourcemeta::core::SchemaFrame &frame,
269269
const sourcemeta::core::SchemaFrame::Instances &instances,
270270
const std::map<sourcemeta::core::Pointer, CacheSubschema> &cache,
@@ -314,6 +314,8 @@ static auto repopulate_instance_locations(
314314
}
315315
}
316316

317+
} // namespace
318+
317319
namespace sourcemeta::core {
318320

319321
auto SchemaFrame::to_json() const -> JSON {

src/core/jsonschema/jsonschema.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ auto sourcemeta::core::is_schema(const sourcemeta::core::JSON &schema) -> bool {
1313
return schema.is_object() || schema.is_boolean();
1414
}
1515

16-
static auto id_keyword_guess(const sourcemeta::core::JSON &schema)
16+
namespace {
17+
18+
auto id_keyword_guess(const sourcemeta::core::JSON &schema)
1719
-> std::optional<std::string> {
1820
if (schema.defines("$id") && schema.at("$id").is_string()) {
1921
if (!schema.defines("id") ||
@@ -55,6 +57,8 @@ static auto id_keyword(const std::string &base_dialect) -> std::string {
5557
throw sourcemeta::core::SchemaError(error.str());
5658
}
5759

60+
} // namespace
61+
5862
auto sourcemeta::core::identify(
5963
const sourcemeta::core::JSON &schema, const SchemaResolver &resolver,
6064
const SchemaIdentificationStrategy strategy,

src/core/uri/uri.cc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
#include <utility> // std::move
1515
#include <vector> // std::vector
1616

17-
static auto uri_normalize(UriUriA *uri) -> void {
17+
namespace {
18+
19+
auto uri_normalize(UriUriA *uri) -> void {
1820
if (uriNormalizeSyntaxA(uri) != URI_SUCCESS) {
1921
throw sourcemeta::core::URIError{"Could not normalize URI"};
2022
}
2123
}
2224

23-
static auto uri_to_string(const UriUriA *const uri) -> std::string {
24-
int size = 0;
25+
auto uri_to_string(const UriUriA *const uri) -> std::string {
26+
int size;
2527
if (uriToStringCharsRequiredA(uri, &size) != URI_SUCCESS) {
2628
throw sourcemeta::core::URIError{"Could not determine URI size"};
2729
}
@@ -37,7 +39,7 @@ static auto uri_to_string(const UriUriA *const uri) -> std::string {
3739
return result;
3840
}
3941

40-
static auto uri_text_range(const UriTextRangeA *const range)
42+
auto uri_text_range(const UriTextRangeA *const range)
4143
-> std::optional<std::string_view> {
4244
if (range->afterLast == nullptr) {
4345
return std::nullopt;
@@ -48,8 +50,8 @@ static auto uri_text_range(const UriTextRangeA *const range)
4850
range->afterLast - range->first)};
4951
}
5052

51-
static auto uri_parse(const std::string &data, UriUriA *uri) -> void {
52-
const char *error_position = nullptr;
53+
auto uri_parse(const std::string &data, UriUriA *uri) -> void {
54+
const char *error_position;
5355
switch (uriParseSingleUriA(uri, data.c_str(), &error_position)) {
5456
case URI_ERROR_SYNTAX:
5557
// TODO: Test the positions of this error
@@ -68,8 +70,7 @@ static auto uri_parse(const std::string &data, UriUriA *uri) -> void {
6870
uri_normalize(uri);
6971
}
7072

71-
static auto canonicalize_path(const std::string &path)
72-
-> std::optional<std::string> {
73+
auto canonicalize_path(const std::string &path) -> std::optional<std::string> {
7374
// TODO: This is a hack, as this whole function works badly for
7475
// relative paths with ".."
7576
if (path.starts_with("..")) {
@@ -113,6 +114,8 @@ static auto canonicalize_path(const std::string &path)
113114
return canonical_path;
114115
}
115116

117+
} // namespace
118+
116119
namespace sourcemeta::core {
117120

118121
struct URI::Internal {

src/core/yaml/yaml.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
#include <sstream> // std::ostringstream, std::istringstream
88
#include <string_view> // std::string_view
99

10+
namespace {
11+
1012
// TODO: Perform parsing token by token using `yaml_parser_parse`,
1113
// as that function also let us get line/column information on `yaml_event_t`
12-
static auto yaml_node_to_json(yaml_node_t *const node,
13-
yaml_document_t *const document)
14+
auto yaml_node_to_json(yaml_node_t *const node, yaml_document_t *const document)
1415
-> sourcemeta::core::JSON {
1516
if (!node) {
1617
return sourcemeta::core::JSON{nullptr};
@@ -81,8 +82,7 @@ static auto yaml_node_to_json(yaml_node_t *const node,
8182
}
8283
}
8384

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

108+
} // namespace
109+
108110
namespace sourcemeta::core {
109111

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

0 commit comments

Comments
 (0)