Skip to content

Commit ae4dc9a

Browse files
nehebbaylesj
authored andcommitted
clang-tidy fixes (open-source-parsers#1033)
* [clang-tidy] Replace C typedef with C++ using Found with modernize-use-using Added to .clang-tidy file. Signed-off-by: Rosen Penev <[email protected]> * [clang-tidy] Remove redundant member init Found with readability-redundant-member-init Added to .clang-tidy * [clang-tidy] Replace C casts with C++ ones Found with google-readability-casting Signed-off-by: Rosen Penev <[email protected]> * [clang-tidy] Use default member init Found with modernize-use-default-member-init Signed-off-by: Rosen Penev <[email protected]>
1 parent e9ccbe0 commit ae4dc9a

File tree

4 files changed

+27
-17
lines changed

4 files changed

+27
-17
lines changed

.clang-tidy

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
Checks: 'google-readability-casting,modernize-use-default-member-init,modernize-use-using,readability-redundant-member-init'
3+
WarningsAsErrors: ''
4+
HeaderFilterRegex: ''
5+
AnalyzeTemporaryDtors: false
6+
FormatStyle: none
7+
CheckOptions:
8+
- key: modernize-use-using.IgnoreMacros
9+
value: '0'
10+
...
11+

src/lib_json/json_reader.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static size_t const stackLimit_g =
5151
namespace Json {
5252

5353
#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
54-
typedef std::unique_ptr<CharReader> CharReaderPtr;
54+
using CharReaderPtr = std::unique_ptr<CharReader>;
5555
#else
5656
typedef std::auto_ptr<CharReader> CharReaderPtr;
5757
#endif
@@ -86,11 +86,10 @@ bool Reader::containsNewLine(Reader::Location begin, Reader::Location end) {
8686
// //////////////////////////////////////////////////////////////////
8787

8888
Reader::Reader()
89-
: errors_(), document_(), commentsBefore_(), features_(Features::all()) {}
89+
: features_(Features::all()) {}
9090

9191
Reader::Reader(const Features& features)
92-
: errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(),
93-
lastValue_(), commentsBefore_(), features_(features), collectComments_() {
92+
: features_(features) {
9493
}
9594

9695
bool Reader::parse(const std::string& document,
@@ -111,7 +110,7 @@ bool Reader::parse(std::istream& is, Value& root, bool collectComments) {
111110
// Since String is reference-counted, this at least does not
112111
// create an extra copy.
113112
String doc;
114-
std::getline(is, doc, (char)EOF);
113+
std::getline(is, doc, static_cast<char>EOF);
115114
return parse(doc.data(), doc.data() + doc.size(), root, collectComments);
116115
}
117116

@@ -895,8 +894,8 @@ OurFeatures OurFeatures::all() { return {}; }
895894
// for implementing JSON reading.
896895
class OurReader {
897896
public:
898-
typedef char Char;
899-
typedef const Char* Location;
897+
using Char = char;
898+
using Location = const Char *;
900899
struct StructuredError {
901900
ptrdiff_t offset_start;
902901
ptrdiff_t offset_limit;
@@ -952,7 +951,7 @@ class OurReader {
952951
Location extra_;
953952
};
954953

955-
typedef std::deque<ErrorInfo> Errors;
954+
using Errors = std::deque<ErrorInfo>;
956955

957956
bool readToken(Token& token);
958957
void skipSpaces();
@@ -997,7 +996,7 @@ class OurReader {
997996
static String normalizeEOL(Location begin, Location end);
998997
static bool containsNewLine(Location begin, Location end);
999998

1000-
typedef std::stack<Value*> Nodes;
999+
using Nodes = std::stack<Value *>;
10011000
Nodes nodes_;
10021001
Errors errors_;
10031002
String document_;
@@ -1023,8 +1022,8 @@ bool OurReader::containsNewLine(OurReader::Location begin,
10231022
}
10241023

10251024
OurReader::OurReader(OurFeatures const& features)
1026-
: errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(),
1027-
lastValue_(), commentsBefore_(), features_(features), collectComments_() {
1025+
: begin_(), end_(), current_(), lastValueEnd_(),
1026+
lastValue_(), features_(features), collectComments_() {
10281027
}
10291028

10301029
bool OurReader::parse(const char* beginDoc,

src/lib_json/json_value.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,16 +1547,16 @@ Value::iterator Value::end() {
15471547
// class PathArgument
15481548
// //////////////////////////////////////////////////////////////////
15491549

1550-
PathArgument::PathArgument() : key_() {}
1550+
PathArgument::PathArgument() {}
15511551

15521552
PathArgument::PathArgument(ArrayIndex index)
1553-
: key_(), index_(index), kind_(kindIndex) {}
1553+
: index_(index), kind_(kindIndex) {}
15541554

15551555
PathArgument::PathArgument(const char* key)
1556-
: key_(key), index_(), kind_(kindKey) {}
1556+
: key_(key), kind_(kindKey) {}
15571557

15581558
PathArgument::PathArgument(const String& key)
1559-
: key_(key.c_str()), index_(), kind_(kindKey) {}
1559+
: key_(key.c_str()), kind_(kindKey) {}
15601560

15611561
// class Path
15621562
// //////////////////////////////////////////////////////////////////

src/lib_json/json_writer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
namespace Json {
8585

8686
#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
87-
typedef std::unique_ptr<StreamWriter> StreamWriterPtr;
87+
using StreamWriterPtr = std::unique_ptr<StreamWriter>;
8888
#else
8989
typedef std::auto_ptr<StreamWriter> StreamWriterPtr;
9090
#endif
@@ -887,7 +887,7 @@ struct BuiltStyledStreamWriter : public StreamWriter {
887887
void writeCommentAfterValueOnSameLine(Value const& root);
888888
static bool hasCommentForValue(const Value& value);
889889

890-
typedef std::vector<String> ChildValues;
890+
using ChildValues = std::vector<String>;
891891

892892
ChildValues childValues_;
893893
String indentString_;

0 commit comments

Comments
 (0)