Skip to content

Commit 7a206c1

Browse files
committed
fix clang-tidy warnings
1 parent af03d18 commit 7a206c1

13 files changed

+64
-65
lines changed

GraphQLParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,5 @@ std::unique_ptr<ast::Node> parseFileWithExperimentalSchemaSupport(
7171
}
7272

7373

74-
}
75-
}
74+
} // namespace graphql
75+
} // namespace facebook

JsonVisitor.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "position.hh"
1111
#include "JsonVisitor.h"
1212

13-
#include <assert.h>
13+
#include <cassert>
1414
#include <iterator>
1515

1616
namespace facebook {
@@ -28,7 +28,10 @@ JsonVisitor::NodeFieldPrinter::NodeFieldPrinter(
2828
if (!visitor_.printed_.empty()) {
2929
nextChild_ = visitor_.printed_.back().begin();
3030
}
31-
out_ << "{\"kind\":\"" << nodeKind << "\",\"loc\":";
31+
// NOTE: If you're an Emacs user and this file's use of C++11 raw
32+
// strings doesn't highlight correctly in c++-mode, try upgrading to
33+
// Emacs 26 if you can.
34+
out_ << R"({"kind":")" << nodeKind << R"(","loc":)";
3235
printLocation(out_, node.getLocation());
3336
}
3437

@@ -52,21 +55,21 @@ void JsonVisitor::NodeFieldPrinter::printSingularPrimitiveField(
5255
const char *fieldName,
5356
const char *value) {
5457
printFieldSeparator();
55-
out_ << '"' << fieldName << "\":";
58+
out_ << '"' << fieldName << R"(":)";
5659
out_ << '"' << value << '"';
5760
}
5861

5962
void JsonVisitor::NodeFieldPrinter::printSingularBooleanField(
6063
const char *fieldName,
6164
bool value) {
6265
printFieldSeparator();
63-
out_ << '"' << fieldName << "\":";
66+
out_ << '"' << fieldName << R"(":)";
6467
out_ << (value ? "true" : "false");
6568
}
6669

6770
void JsonVisitor::NodeFieldPrinter::printSingularObjectField(const char *fieldName) {
6871
printFieldSeparator();
69-
out_ << '"' << fieldName << "\":";
72+
out_ << '"' << fieldName << R"(":)";
7073
assert(!visitor_.printed_.empty());
7174
out_ << *nextChild_++;
7275
}
@@ -75,7 +78,7 @@ void JsonVisitor::NodeFieldPrinter::printNullableSingularObjectField(
7578
const char *fieldName,
7679
const void *value) {
7780
printFieldSeparator();
78-
out_ << '"' << fieldName << "\":";
81+
out_ << '"' << fieldName << R"(":)";
7982
if (value != nullptr) {
8083
assert(!visitor_.printed_.empty());
8184
out_ << *nextChild_++;
@@ -89,10 +92,10 @@ void JsonVisitor::NodeFieldPrinter::printLocation(
8992
std::ostringstream &out,
9093
const yy::location &location)
9194
{
92-
out << "{\"start\": {\"line\": " << location.begin.line
93-
<< ",\"column\":" << location.begin.column
94-
<< "}, \"end\": {\"line\":" << location.end.line
95-
<< ",\"column\":" << location.end.column
95+
out << R"({"start": {"line": )" << location.begin.line
96+
<< R"(,"column":)" << location.begin.column
97+
<< R"(}, "end": {"line":)" << location.end.line
98+
<< R"(,"column":)" << location.end.column
9699
<< "}}";
97100
}
98101

@@ -131,7 +134,7 @@ std::string JsonVisitor::getResult() const {
131134

132135
#include "JsonVisitor.cpp.inc"
133136

134-
}
135-
}
136-
}
137-
}
137+
} // namespace visitor
138+
} // namespace ast
139+
} // namespace graphql
140+
} // namespace facebook

README.clang-tidy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
* readability-implicit-bool is disabled because I disagree with it.
22

3-
* cppcoreguidelines-pro-type-cstyle-cast is disabled because we use it
4-
as reinterpret cast to implement our C API.
3+
* cppcoreguidelines-pro-type-reinterpret-cast is disabled because we use it
4+
to implement our C API.
55

66
* cppcoreguidelines-pro-bounds-array-to-pointer-decay is disabled
77
because it fires a false positive on every use of assert().

ast/c_impl.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def start_file(self):
2222
#include "GraphQLAst.h"
2323
#include "../Ast.h"
2424
25-
using namespace facebook::graphql::ast;
25+
using namespace facebook::graphql::ast; // NOLINT
2626
'''
2727

2828
def end_file(self):
@@ -33,7 +33,7 @@ def start_type(self, name):
3333

3434
def field(self, type, name, nullable, plural):
3535
print field_prototype(self._current_type, type, name, nullable, plural) + ' {'
36-
print ' const auto *realNode = (const %s *)node;' % self._current_type
36+
print ' const auto *realNode = reinterpret_cast<const %s *>(node);' % self._current_type
3737
title_name = title(name)
3838
call_get = 'realNode->get%s()' % title_name
3939
if plural:
@@ -45,7 +45,7 @@ def field(self, type, name, nullable, plural):
4545
if type in ['string', 'OperationKind', 'boolean']:
4646
print ' return %s;' % call_get
4747
else:
48-
fmt = ' return (const struct %s *)%s%s;'
48+
fmt = ' return reinterpret_cast<const struct %s *>(%s%s);'
4949
print fmt % (struct_name(type), '' if nullable else '&', call_get)
5050

5151
print '}'

ast/cxx_impl.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ def start_file(self):
2323
'''
2424

2525
def end_file(self):
26-
print '}'
27-
print '}'
28-
print '}'
26+
print '} // namespace ast'
27+
print '} // namespace graphql'
28+
print '} // namespace facebook'
2929

3030
def start_type(self, name):
3131
print '''void %s::accept(visitor::AstVisitor *visitor) const {

c/GraphQLAstNode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ using facebook::graphql::ast::Node;
1414

1515
void graphql_node_get_location(const struct GraphQLAstNode *node,
1616
struct GraphQLAstLocation *location) {
17-
const Node *realNode = (Node *)node;
17+
const auto *realNode = reinterpret_cast<const Node *>(node);
1818
const auto &loc = realNode->getLocation();
1919
location->beginLine = loc.begin.line;
2020
location->beginColumn = loc.begin.column;
@@ -23,5 +23,5 @@ void graphql_node_get_location(const struct GraphQLAstNode *node,
2323
}
2424

2525
void graphql_node_free(struct GraphQLAstNode *node) {
26-
delete (Node *)node;
26+
delete reinterpret_cast<Node *>(node);
2727
}

c/GraphQLAstToJSON.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include "GraphQLAstToJSON.h"
1111

12-
#include <string.h>
12+
#include <cstring>
1313

1414
#include "../JsonVisitor.h"
1515
#include "../AstNode.h"
@@ -18,6 +18,6 @@
1818
const char *graphql_ast_to_json(const struct GraphQLAstNode *node)
1919
{
2020
facebook::graphql::ast::visitor::JsonVisitor visitor;
21-
((facebook::graphql::ast::Node *)node)->accept(&visitor);
21+
reinterpret_cast<const facebook::graphql::ast::Node *>(node)->accept(&visitor);
2222
return strdup(visitor.getResult().c_str());
2323
}

c/GraphQLAstVisitor.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "c/GraphQLAstVisitor.h"
1111
#include "AstVisitor.h"
1212

13-
using namespace facebook::graphql::ast;
13+
using namespace facebook::graphql::ast; // NOLINT
1414

1515
#include "c/GraphQLAstForEachConcreteType.h"
1616

@@ -26,8 +26,6 @@ class CVisitorBridge : public visitor::AstVisitor {
2626
void *userData)
2727
: callbacks_(callbacks), userData_(userData) {}
2828

29-
~CVisitorBridge() {}
30-
3129
FOR_EACH_CONCRETE_TYPE(DECLARE_VISIT)
3230
};
3331

@@ -48,12 +46,12 @@ class CVisitorBridge : public visitor::AstVisitor {
4846

4947
FOR_EACH_CONCRETE_TYPE(IMPLEMENT_VISIT)
5048

51-
void graphql_node_visit(struct GraphQLAstNode *node,
49+
void graphql_node_visit(const struct GraphQLAstNode *node,
5250
const struct GraphQLAstVisitorCallbacks *callbacks,
5351
void *userData)
5452
{
5553
CVisitorBridge visitor(callbacks, userData);
5654
if (node) {
57-
((facebook::graphql::ast::Node *)node)->accept(&visitor);
55+
reinterpret_cast<const facebook::graphql::ast::Node *>(node)->accept(&visitor);
5856
}
5957
}

c/GraphQLAstVisitor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct GraphQLAstNode;
4545
* callbacks struct as appropriate. userData will be passed as the userData
4646
* argument to each callback.
4747
*/
48-
void graphql_node_visit(struct GraphQLAstNode *node,
48+
void graphql_node_visit(const struct GraphQLAstNode *node,
4949
const struct GraphQLAstVisitorCallbacks *callbacks,
5050
void *userData);
5151

c/GraphQLParser.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@
1414
#include <cstdlib>
1515

1616
struct GraphQLAstNode *graphql_parse_string(const char *text, const char **error) {
17-
return (struct GraphQLAstNode *)facebook::graphql::parseString(text, error).release();
17+
return reinterpret_cast<struct GraphQLAstNode *>(facebook::graphql::parseString(text, error).release());
1818
}
1919

2020
struct GraphQLAstNode *graphql_parse_string_with_experimental_schema_support(
2121
const char *text, const char **error) {
22-
return (struct GraphQLAstNode *)facebook::graphql::parseStringWithExperimentalSchemaSupport(
23-
text, error).release();
22+
return reinterpret_cast<struct GraphQLAstNode *>(facebook::graphql::parseStringWithExperimentalSchemaSupport(
23+
text, error).release());
2424
}
2525

2626
struct GraphQLAstNode *graphql_parse_file(FILE *file, const char **error) {
27-
return (struct GraphQLAstNode *)facebook::graphql::parseFile(file, error).release();
27+
return reinterpret_cast<struct GraphQLAstNode *>(facebook::graphql::parseFile(file, error).release());
2828
}
2929

3030
struct GraphQLAstNode *graphql_parse_file_with_experimental_schema_support(
3131
FILE *file, const char **error) {
32-
return (struct GraphQLAstNode *)facebook::graphql::parseFileWithExperimentalSchemaSupport(file, error).release();
32+
return reinterpret_cast<struct GraphQLAstNode *>(facebook::graphql::parseFileWithExperimentalSchemaSupport(file, error).release());
3333
}
3434

3535
void graphql_error_free(const char *error) {
36-
std::free((void *)error);
36+
std::free((void *)(error)); // NOLINT
3737
}

0 commit comments

Comments
 (0)