Issue #958: Travis CI should enforce clang-format standards (#1026)
* Issue #958: Travis CI should enfore clang-format standards
This patch adds clang format support to the travis bots.
* Update path
* Roll back to version 8 since 9 is in test
* Cleanup clang
* Revert "Delete JSONCPP_DEPRECATED, use [[deprecated]] instead. (#978)" (#1029)
This reverts commit b27c83f691a03f521a1b3b99eefa2973f8e2bfcd.
diff --git a/src/jsontestrunner/main.cpp b/src/jsontestrunner/main.cpp
index d2d41aa..cb9db66 100644
--- a/src/jsontestrunner/main.cpp
+++ b/src/jsontestrunner/main.cpp
@@ -68,8 +68,8 @@
return text;
}
-static void
-printValueTree(FILE* fout, Json::Value& value, const Json::String& path = ".") {
+static void printValueTree(FILE* fout, Json::Value& value,
+ const Json::String& path = ".") {
if (value.hasComment(Json::commentBefore)) {
fprintf(fout, "%s\n", value.getComment(Json::commentBefore).c_str());
}
@@ -125,8 +125,7 @@
static int parseAndSaveValueTree(const Json::String& input,
const Json::String& actual,
const Json::String& kind,
- const Json::Features& features,
- bool parseOnly,
+ const Json::Features& features, bool parseOnly,
Json::Value* root) {
Json::Reader reader(features);
bool parsingSuccessful =
diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp
index 5d6207c..ac673ff 100644
--- a/src/lib_json/json_reader.cpp
+++ b/src/lib_json/json_reader.cpp
@@ -89,8 +89,7 @@
Reader::Reader(const Features& features) : features_(features) {}
-bool Reader::parse(const std::string& document,
- Value& root,
+bool Reader::parse(const std::string& document, Value& root,
bool collectComments) {
document_.assign(document.begin(), document.end());
const char* begin = document_.c_str();
@@ -111,9 +110,7 @@
return parse(doc.data(), doc.data() + doc.size(), root, collectComments);
}
-bool Reader::parse(const char* beginDoc,
- const char* endDoc,
- Value& root,
+bool Reader::parse(const char* beginDoc, const char* endDoc, Value& root,
bool collectComments) {
if (!features_.allowComments_) {
collectComments = false;
@@ -373,8 +370,7 @@
return normalized;
}
-void Reader::addComment(Location begin,
- Location end,
+void Reader::addComment(Location begin, Location end,
CommentPlacement placement) {
assert(collectComments_);
const String& normalized = normalizeEOL(begin, end);
@@ -677,10 +673,8 @@
return true;
}
-bool Reader::decodeUnicodeCodePoint(Token& token,
- Location& current,
- Location end,
- unsigned int& unicode) {
+bool Reader::decodeUnicodeCodePoint(Token& token, Location& current,
+ Location end, unsigned int& unicode) {
if (!decodeUnicodeEscapeSequence(token, current, end, unicode))
return false;
@@ -704,8 +698,7 @@
return true;
}
-bool Reader::decodeUnicodeEscapeSequence(Token& token,
- Location& current,
+bool Reader::decodeUnicodeEscapeSequence(Token& token, Location& current,
Location end,
unsigned int& ret_unicode) {
if (end - current < 4)
@@ -753,8 +746,7 @@
return false;
}
-bool Reader::addErrorAndRecover(const String& message,
- Token& token,
+bool Reader::addErrorAndRecover(const String& message, Token& token,
TokenType skipUntilToken) {
addError(message, token);
return recoverFromError(skipUntilToken);
@@ -768,8 +760,7 @@
return *current_++;
}
-void Reader::getLocationLineAndColumn(Location location,
- int& line,
+void Reader::getLocationLineAndColumn(Location location, int& line,
int& column) const {
Location current = begin_;
Location lastLineStart = current;
@@ -845,8 +836,7 @@
return true;
}
-bool Reader::pushError(const Value& value,
- const String& message,
+bool Reader::pushError(const Value& value, const String& message,
const Value& extra) {
ptrdiff_t const length = end_ - begin_;
if (value.getOffsetStart() > length || value.getOffsetLimit() > length ||
@@ -900,9 +890,7 @@
};
OurReader(OurFeatures const& features);
- bool parse(const char* beginDoc,
- const char* endDoc,
- Value& root,
+ bool parse(const char* beginDoc, const char* endDoc, Value& root,
bool collectComments = true);
String getFormattedErrorMessages() const;
std::vector<StructuredError> getStructuredErrors() const;
@@ -968,24 +956,19 @@
bool decodeString(Token& token, String& decoded);
bool decodeDouble(Token& token);
bool decodeDouble(Token& token, Value& decoded);
- bool decodeUnicodeCodePoint(Token& token,
- Location& current,
- Location end,
+ bool decodeUnicodeCodePoint(Token& token, Location& current, Location end,
unsigned int& unicode);
- bool decodeUnicodeEscapeSequence(Token& token,
- Location& current,
- Location end,
- unsigned int& unicode);
+ bool decodeUnicodeEscapeSequence(Token& token, Location& current,
+ Location end, unsigned int& unicode);
bool addError(const String& message, Token& token, Location extra = nullptr);
bool recoverFromError(TokenType skipUntilToken);
- bool addErrorAndRecover(const String& message,
- Token& token,
+ bool addErrorAndRecover(const String& message, Token& token,
TokenType skipUntilToken);
void skipUntilSpace();
Value& currentValue();
Char getNextChar();
- void
- getLocationLineAndColumn(Location location, int& line, int& column) const;
+ void getLocationLineAndColumn(Location location, int& line,
+ int& column) const;
String getLocationLineAndColumn(Location location) const;
void addComment(Location begin, Location end, CommentPlacement placement);
void skipCommentTokens(Token& token);
@@ -1022,9 +1005,7 @@
: begin_(), end_(), current_(), lastValueEnd_(), lastValue_(),
features_(features), collectComments_() {}
-bool OurReader::parse(const char* beginDoc,
- const char* endDoc,
- Value& root,
+bool OurReader::parse(const char* beginDoc, const char* endDoc, Value& root,
bool collectComments) {
if (!features_.allowComments_) {
collectComments = false;
@@ -1341,8 +1322,7 @@
return normalized;
}
-void OurReader::addComment(Location begin,
- Location end,
+void OurReader::addComment(Location begin, Location end,
CommentPlacement placement) {
assert(collectComments_);
const String& normalized = normalizeEOL(begin, end);
@@ -1700,10 +1680,8 @@
return true;
}
-bool OurReader::decodeUnicodeCodePoint(Token& token,
- Location& current,
- Location end,
- unsigned int& unicode) {
+bool OurReader::decodeUnicodeCodePoint(Token& token, Location& current,
+ Location end, unsigned int& unicode) {
if (!decodeUnicodeEscapeSequence(token, current, end, unicode))
return false;
@@ -1727,8 +1705,7 @@
return true;
}
-bool OurReader::decodeUnicodeEscapeSequence(Token& token,
- Location& current,
+bool OurReader::decodeUnicodeEscapeSequence(Token& token, Location& current,
Location end,
unsigned int& ret_unicode) {
if (end - current < 4)
@@ -1776,8 +1753,7 @@
return false;
}
-bool OurReader::addErrorAndRecover(const String& message,
- Token& token,
+bool OurReader::addErrorAndRecover(const String& message, Token& token,
TokenType skipUntilToken) {
addError(message, token);
return recoverFromError(skipUntilToken);
@@ -1791,8 +1767,7 @@
return *current_++;
}
-void OurReader::getLocationLineAndColumn(Location location,
- int& line,
+void OurReader::getLocationLineAndColumn(Location location, int& line,
int& column) const {
Location current = begin_;
Location lastLineStart = current;
@@ -1863,8 +1838,7 @@
return true;
}
-bool OurReader::pushError(const Value& value,
- const String& message,
+bool OurReader::pushError(const Value& value, const String& message,
const Value& extra) {
ptrdiff_t length = end_ - begin_;
if (value.getOffsetStart() > length || value.getOffsetLimit() > length ||
@@ -1891,9 +1865,7 @@
public:
OurCharReader(bool collectComments, OurFeatures const& features)
: collectComments_(collectComments), reader_(features) {}
- bool parse(char const* beginDoc,
- char const* endDoc,
- Value* root,
+ bool parse(char const* beginDoc, char const* endDoc, Value* root,
String* errs) override {
bool ok = reader_.parse(beginDoc, endDoc, *root, collectComments_);
if (errs) {
@@ -1989,9 +1961,7 @@
//////////////////////////////////
// global functions
-bool parseFromStream(CharReader::Factory const& fact,
- IStream& sin,
- Value* root,
+bool parseFromStream(CharReader::Factory const& fact, IStream& sin, Value* root,
String* errs) {
OStringStream ssin;
ssin << sin.rdbuf();
diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp
index 6ee999c..cf93ec7 100644
--- a/src/lib_json/json_value.cpp
+++ b/src/lib_json/json_value.cpp
@@ -22,10 +22,8 @@
// Provide implementation equivalent of std::snprintf for older _MSC compilers
#if defined(_MSC_VER) && _MSC_VER < 1900
#include <stdarg.h>
-static int msvc_pre1900_c99_vsnprintf(char* outBuf,
- size_t size,
- const char* format,
- va_list ap) {
+static int msvc_pre1900_c99_vsnprintf(char* outBuf, size_t size,
+ const char* format, va_list ap) {
int count = -1;
if (size != 0)
count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap);
@@ -34,10 +32,8 @@
return count;
}
-int JSON_API msvc_pre1900_c99_snprintf(char* outBuf,
- size_t size,
- const char* format,
- ...) {
+int JSON_API msvc_pre1900_c99_snprintf(char* outBuf, size_t size,
+ const char* format, ...) {
va_list ap;
va_start(ap, format);
const int count = msvc_pre1900_c99_vsnprintf(outBuf, size, format, ap);
@@ -156,10 +152,8 @@
0; // to avoid buffer over-run accidents by users later
return newString;
}
-inline static void decodePrefixedString(bool isPrefixed,
- char const* prefixed,
- unsigned* length,
- char const** value) {
+inline static void decodePrefixedString(bool isPrefixed, char const* prefixed,
+ unsigned* length, char const** value) {
if (!isPrefixed) {
*length = static_cast<unsigned>(strlen(prefixed));
*value = prefixed;
@@ -235,8 +229,7 @@
Value::CZString::CZString(ArrayIndex index) : cstr_(nullptr), index_(index) {}
-Value::CZString::CZString(char const* str,
- unsigned length,
+Value::CZString::CZString(char const* str, unsigned length,
DuplicationPolicy allocate)
: cstr_(str) {
// allocate != duplicate
@@ -1165,8 +1158,7 @@
return this->value_.map_->emplace(size(), std::move(value)).first->second;
}
-Value Value::get(char const* begin,
- char const* end,
+Value Value::get(char const* begin, char const* end,
Value const& defaultValue) const {
Value const* found = find(begin, end);
return !found ? defaultValue : *found;
@@ -1564,11 +1556,8 @@
// class Path
// //////////////////////////////////////////////////////////////////
-Path::Path(const String& path,
- const PathArgument& a1,
- const PathArgument& a2,
- const PathArgument& a3,
- const PathArgument& a4,
+Path::Path(const String& path, const PathArgument& a1, const PathArgument& a2,
+ const PathArgument& a3, const PathArgument& a4,
const PathArgument& a5) {
InArgs in;
in.reserve(5);
@@ -1611,8 +1600,7 @@
}
}
-void Path::addPathInArg(const String& /*path*/,
- const InArgs& in,
+void Path::addPathInArg(const String& /*path*/, const InArgs& in,
InArgs::const_iterator& itInArg,
PathArgument::Kind kind) {
if (itInArg == in.end()) {
diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp
index 4b91035..e16d84f 100644
--- a/src/lib_json/json_writer.cpp
+++ b/src/lib_json/json_writer.cpp
@@ -122,10 +122,8 @@
#endif // # if defined(JSON_HAS_INT64)
namespace {
-String valueToString(double value,
- bool useSpecialFloats,
- unsigned int precision,
- PrecisionType precisionType) {
+String valueToString(double value, bool useSpecialFloats,
+ unsigned int precision, PrecisionType precisionType) {
// Print into the buffer. We need not request the alternative representation
// that always has a decimal point because JSON doesn't distinguish the
// concepts of reals and integers.
@@ -168,8 +166,7 @@
}
} // namespace
-String valueToString(double value,
- unsigned int precision,
+String valueToString(double value, unsigned int precision,
PrecisionType precisionType) {
return valueToString(value, false, precision, precisionType);
}
@@ -864,14 +861,10 @@
};
struct BuiltStyledStreamWriter : public StreamWriter {
- BuiltStyledStreamWriter(String indentation,
- CommentStyle::Enum cs,
- String colonSymbol,
- String nullSymbol,
- String endingLineFeedSymbol,
- bool useSpecialFloats,
- unsigned int precision,
- PrecisionType precisionType);
+ BuiltStyledStreamWriter(String indentation, CommentStyle::Enum cs,
+ String colonSymbol, String nullSymbol,
+ String endingLineFeedSymbol, bool useSpecialFloats,
+ unsigned int precision, PrecisionType precisionType);
int write(Value const& root, OStream* sout) override;
private:
@@ -903,14 +896,10 @@
unsigned int precision_;
PrecisionType precisionType_;
};
-BuiltStyledStreamWriter::BuiltStyledStreamWriter(String indentation,
- CommentStyle::Enum cs,
- String colonSymbol,
- String nullSymbol,
- String endingLineFeedSymbol,
- bool useSpecialFloats,
- unsigned int precision,
- PrecisionType precisionType)
+BuiltStyledStreamWriter::BuiltStyledStreamWriter(
+ String indentation, CommentStyle::Enum cs, String colonSymbol,
+ String nullSymbol, String endingLineFeedSymbol, bool useSpecialFloats,
+ unsigned int precision, PrecisionType precisionType)
: rightMargin_(74), indentation_(std::move(indentation)), cs_(cs),
colonSymbol_(std::move(colonSymbol)), nullSymbol_(std::move(nullSymbol)),
endingLineFeedSymbol_(std::move(endingLineFeedSymbol)),
diff --git a/src/test_lib_json/jsontest.cpp b/src/test_lib_json/jsontest.cpp
index c0b5296..0cc500a 100644
--- a/src/test_lib_json/jsontest.cpp
+++ b/src/test_lib_json/jsontest.cpp
@@ -82,8 +82,8 @@
void TestResult::setTestName(const Json::String& name) { name_ = name; }
-TestResult&
-TestResult::addFailure(const char* file, unsigned int line, const char* expr) {
+TestResult& TestResult::addFailure(const char* file, unsigned int line,
+ const char* expr) {
/// Walks the PredicateContext stack adding them to failures_ if not already
/// added.
unsigned int nestingLevel = 0;
@@ -107,10 +107,8 @@
return *this;
}
-void TestResult::addFailureInfo(const char* file,
- unsigned int line,
- const char* expr,
- unsigned int nestingLevel) {
+void TestResult::addFailureInfo(const char* file, unsigned int line,
+ const char* expr, unsigned int nestingLevel) {
Failure failure;
failure.file_ = file;
failure.line_ = line;
@@ -342,8 +340,8 @@
#if defined(_MSC_VER) && defined(_DEBUG)
// Hook MSVCRT assertions to prevent dialog from appearing
-static int
-msvcrtSilentReportHook(int reportType, char* message, int* /*returnValue*/) {
+static int msvcrtSilentReportHook(int reportType, char* message,
+ int* /*returnValue*/) {
// The default CRT handling of error and assertion is to display
// an error dialog to the user.
// Instead, when an error or an assertion occurs, we force the
@@ -418,12 +416,9 @@
}
#endif
-TestResult& checkStringEqual(TestResult& result,
- const Json::String& expected,
- const Json::String& actual,
- const char* file,
- unsigned int line,
- const char* expr) {
+TestResult& checkStringEqual(TestResult& result, const Json::String& expected,
+ const Json::String& actual, const char* file,
+ unsigned int line, const char* expr) {
if (expected != actual) {
result.addFailure(file, line, expr);
result << "Expected: '" << expected << "'\n";
diff --git a/src/test_lib_json/jsontest.h b/src/test_lib_json/jsontest.h
index e9c11a4..5d213dc 100644
--- a/src/test_lib_json/jsontest.h
+++ b/src/test_lib_json/jsontest.h
@@ -68,8 +68,8 @@
void setTestName(const Json::String& name);
/// Adds an assertion failure.
- TestResult&
- addFailure(const char* file, unsigned int line, const char* expr = nullptr);
+ TestResult& addFailure(const char* file, unsigned int line,
+ const char* expr = nullptr);
/// Removes the last PredicateContext added to the predicate stack
/// chained list.
@@ -98,9 +98,7 @@
private:
TestResult& addToLastFailure(const Json::String& message);
/// Adds a failure or a predicate context
- void addFailureInfo(const char* file,
- unsigned int line,
- const char* expr,
+ void addFailureInfo(const char* file, unsigned int line, const char* expr,
unsigned int nestingLevel);
static Json::String indentText(const Json::String& text,
const Json::String& indent);
@@ -176,12 +174,8 @@
};
template <typename T, typename U>
-TestResult& checkEqual(TestResult& result,
- T expected,
- U actual,
- const char* file,
- unsigned int line,
- const char* expr) {
+TestResult& checkEqual(TestResult& result, T expected, U actual,
+ const char* file, unsigned int line, const char* expr) {
if (static_cast<U>(expected) != actual) {
result.addFailure(file, line, expr);
result << "Expected: " << static_cast<U>(expected) << "\n";
@@ -196,12 +190,9 @@
Json::String ToJsonString(std::string in);
#endif
-TestResult& checkStringEqual(TestResult& result,
- const Json::String& expected,
- const Json::String& actual,
- const char* file,
- unsigned int line,
- const char* expr);
+TestResult& checkStringEqual(TestResult& result, const Json::String& expected,
+ const Json::String& actual, const char* file,
+ unsigned int line, const char* expr);
} // namespace JsonTest