Skip to content

add new clang-tidy option #19699

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
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
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Checks: >
readability-container-size-empty,
readability-delete-null-pointer,
readability-redundant-control-flow,
readability-redundant-string-cstr,

WarningsAsErrors: '*'
HeaderFilterRegex: '/(?!external)/.*'
Expand Down
2 changes: 1 addition & 1 deletion cocos/audio/linux/SimpleAudioEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void SimpleAudioEngine::stopBackgroundMusic(bool releaseData)
{
AudioEngine::stop(g_SimpleAudioEngineLinux->musicid);
if (releaseData) {
AudioEngine::uncache(g_SimpleAudioEngineLinux->musicpath.c_str());
AudioEngine::uncache(g_SimpleAudioEngineLinux->musicpath);
}
}

Expand Down
2 changes: 1 addition & 1 deletion cocos/base/CCDataVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void PrettyPrinter::visit(const __Set *p)
if (i > 0) {
_result += "\n";
}
_result += _indentStr.c_str();
_result += _indentStr;
PrettyPrinter v(_indentLevel);
//FIXME:james (*it)->acceptVisitor(v);
_result += v.getResult();
Expand Down
2 changes: 1 addition & 1 deletion cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ Offset<NodeAction> FlatBuffersSerialize::createNodeAction(const tinyxml2::XMLEle
}
else if (name == "ActivedAnimationName")
{
currentAnimationName = value.c_str();
currentAnimationName = value;
}

attribute = attribute->Next();
Expand Down
4 changes: 2 additions & 2 deletions cocos/network/SocketIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ void SIOClientImpl::send(SocketIOPacket *packet)
if (_connected)
{
CCLOGINFO("-->SEND:%s", req.data());
_ws->send(req.data());
_ws->send(req);
}
else
CCLOGINFO("Cant send the message (%s) because disconnected", req.c_str());
Expand Down Expand Up @@ -757,7 +757,7 @@ void SIOClientImpl::onOpen(WebSocket* /*ws*/)
if (_version == SocketIOPacket::SocketIOVersion::V10x)
{
std::string s = "5";//That's a ping https://github.com/Automattic/engine.io-parser/blob/1b8e077b2218f4947a69f5ad18be2a512ed54e93/lib/index.js#L21
_ws->send(s.data());
_ws->send(s);
}

Director::getInstance()->getScheduler()->schedule(CC_SCHEDULE_SELECTOR(SIOClientImpl::heartbeat), this, (_heartbeat * .9f), false);
Expand Down
2 changes: 1 addition & 1 deletion cocos/platform/linux/CCDevice-linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ class BitmapDC
std::string lowerCasePath = fontPath;
std::transform(lowerCasePath.begin(), lowerCasePath.end(), lowerCasePath.begin(), ::tolower);
if ( lowerCasePath.find(".ttf") != std::string::npos ) {
fontPath = cocos2d::FileUtils::getInstance()->fullPathForFilename(fontPath.c_str());
fontPath = cocos2d::FileUtils::getInstance()->fullPathForFilename(fontPath);

FILE *f = fopen(fontPath.c_str(), "r");
if ( f ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ bool jsval_to_TerrainData(JSContext* cx, JS::HandleValue v, Terrain::TerrainData
JS::ToNumber(cx, js_mapHeight, &mapHeight);
JSB_PRECONDITION2(ok, cx, false, "Error processing arguments");

ret->_heightMapSrc = heightMap.c_str();
ret->_heightMapSrc = heightMap;
char* tmp = (char*)malloc(sizeof(char) * (alphaMap.size() + 1));
strcpy(tmp, alphaMap.c_str());
tmp[alphaMap.size()] = '\0';
Expand Down
2 changes: 1 addition & 1 deletion cocos/scripting/lua-bindings/manual/CCLuaStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ int LuaStack::luaLoadChunksFromZIP(lua_State *L)
std::string filename = zip->getFirstFilename();
while (filename.length()) {
ssize_t bufferSize = 0;
unsigned char *zbuffer = zip->getFileData(filename.c_str(), &bufferSize);
unsigned char *zbuffer = zip->getFileData(filename, &bufferSize);
if (bufferSize) {
// remove .lua or .luac extension
size_t pos = filename.find_last_of('.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3779,7 +3779,7 @@ static int tolua_cocos2dx_FileUtils_getStringFromFile(lua_State* tolua_S)
if (ok)
{
std::string fullPathName = FileUtils::getInstance()->fullPathForFilename(arg0);
__String* contentsOfFile = __String::createWithContentsOfFile(fullPathName.c_str());
__String* contentsOfFile = __String::createWithContentsOfFile(fullPathName);
if (nullptr != contentsOfFile)
{
const char* tolua_ret = contentsOfFile->getCString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ int lua_cocos2dx_physics_PhysicsWorld_getScene(lua_State* tolua_S)
auto iter = g_luaType.find(hashName);
std::string className = "";
if(iter != g_luaType.end()){
className = iter->second.c_str();
className = iter->second;
} else {
className = "cc.Scene";
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/assets-manager/AssetsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void AssetsManager::downloadAndUncompress()
Director::getInstance()->getScheduler()->performFunctionInCocosThread([&, this] {

// Record new version code.
UserDefault::getInstance()->setStringForKey(this->keyOfVersion().c_str(), this->_version.c_str());
UserDefault::getInstance()->setStringForKey(this->keyOfVersion().c_str(), this->_version);

// Unrecord downloaded version code.
UserDefault::getInstance()->setStringForKey(this->keyOfDownloadedVersion().c_str(), "");
Expand Down
2 changes: 1 addition & 1 deletion tests/cpp-tests/Classes/Box2DTestBed/Box2dView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ bool Box2dTestBed::initWithEntryID(int entryId)
view->setScale(15);
view->setAnchorPoint( Vec2(0,0) );
view->setPosition(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/3);
auto label = Label::createWithTTF(view->title().c_str(), "fonts/arial.ttf", 28);
auto label = Label::createWithTTF(view->title(), "fonts/arial.ttf", 28);
addChild(label, 1);
label->setPosition(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height-50);

Expand Down
4 changes: 2 additions & 2 deletions tests/cpp-tests/Classes/DataVisitorTest/DataVisitorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ void PrettyPrinterDemo::onEnter()
TestCase::onEnter();
auto s = Director::getInstance()->getWinSize();

auto label = Label::createWithTTF(title().c_str(), "fonts/arial.ttf", 28);
auto label = Label::createWithTTF(title(), "fonts/arial.ttf", 28);
label->setPosition(s.width/2, s.height * 4/5);
this->addChild(label, 1);

std::string strSubtitle = subtitle();
if(strSubtitle.empty() == false)
{
auto subLabel = Label::createWithTTF(strSubtitle.c_str(), "fonts/Thonburi.ttf", 16);
auto subLabel = Label::createWithTTF(strSubtitle, "fonts/Thonburi.ttf", 16);
subLabel->setPosition(s.width/2, s.height * 3/5);
this->addChild(subLabel, 1);
}
Expand Down
20 changes: 10 additions & 10 deletions tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/SocketIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void SocketIOTest::testevent(SIOClient *client, const std::string& data) {
std::stringstream s;
s << client->getTag() << " received event testevent with data: " << data.c_str();

_sioClientStatus->setString(s.str().c_str());
_sioClientStatus->setString(s.str());

}

Expand All @@ -131,7 +131,7 @@ void SocketIOTest::echotest(SIOClient *client, const std::string& data) {
std::stringstream s;
s << client->getTag() << " received event echotest with data: " << data.c_str();

_sioClientStatus->setString(s.str().c_str());
_sioClientStatus->setString(s.str());

}

Expand All @@ -143,7 +143,7 @@ void SocketIOTest::message(network::SIOClient* client, const std::string& data)

std::stringstream s;
s << client->getTag() << " received message with content: " << data.c_str();
_sioClientStatus->setString(s.str().c_str());
_sioClientStatus->setString(s.str());

}

Expand All @@ -153,7 +153,7 @@ void SocketIOTest::json(network::SIOClient* client, const std::string& data)

std::stringstream s;
s << client->getTag() << " received json message with content: " << data.c_str();
_sioClientStatus->setString(s.str().c_str());
_sioClientStatus->setString(s.str());

}

Expand All @@ -163,7 +163,7 @@ void SocketIOTest::connect(network::SIOClient* client, const std::string& data)

std::stringstream s;
s << client->getTag() << " connected!";
_sioClientStatus->setString(s.str().c_str());
_sioClientStatus->setString(s.str());

}

Expand All @@ -173,7 +173,7 @@ void SocketIOTest::disconnect(network::SIOClient* client, const std::string& dat

std::stringstream s;
s << client->getTag() << " disconnected by server!";
_sioClientStatus->setString(s.str().c_str());
_sioClientStatus->setString(s.str());

this->closedSocketAction(client);

Expand Down Expand Up @@ -271,7 +271,7 @@ void SocketIOTest::onMenuTestClientDisconnectClicked(cocos2d::Ref *sender)
s << "Socket.io Test Client not initialized!";
}

_sioClientStatus->setString(s.str().c_str());
_sioClientStatus->setString(s.str());

}

Expand All @@ -288,7 +288,7 @@ void SocketIOTest::onMenuTestEndpointDisconnectClicked(cocos2d::Ref *sender)
s << "Socket.io Test Endpoint not initialized!";
}

_sioClientStatus->setString(s.str().c_str());
_sioClientStatus->setString(s.str());

}

Expand All @@ -300,7 +300,7 @@ void SocketIOTest::onClose(network::SIOClient* client)

std::stringstream s;
s << client->getTag() << " closed!";
_sioClientStatus->setString(s.str().c_str());
_sioClientStatus->setString(s.str());

this->closedSocketAction(client);

Expand All @@ -312,5 +312,5 @@ void SocketIOTest::onError(network::SIOClient* client, const std::string& data)

std::stringstream s;
s << client->getTag() << " received error with content: " << data.c_str();
_sioClientStatus->setString(s.str().c_str());
_sioClientStatus->setString(s.str());
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,6 @@ void WebSocketDelayTest::onMenuSendTextClicked(cocos2d::Ref *sender)
{
std::string warningStr = "send text websocket instance wasn't ready...";
log("%s", warningStr.c_str());
_sendTextStatus->setString(warningStr.c_str());
_sendTextStatus->setString(warningStr);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void WebSocketTest::onMessage(network::WebSocket* ws, const network::WebSocket::
std::string textStr = std::string("response text msg: ")+data.bytes+", "+times;
log("%s", textStr.c_str());

_sendTextStatus->setString(textStr.c_str());
_sendTextStatus->setString(textStr);
}
else
{
Expand All @@ -220,7 +220,7 @@ void WebSocketTest::onMessage(network::WebSocket* ws, const network::WebSocket::

binaryStr += std::string(", ")+times;
log("%s", binaryStr.c_str());
_sendBinaryStatus->setString(binaryStr.c_str());
_sendBinaryStatus->setString(binaryStr);
}
}

Expand Down Expand Up @@ -285,7 +285,7 @@ void WebSocketTest::onMenuSendTextClicked(cocos2d::Ref *sender)
{
std::string warningStr = "send text websocket instance wasn't ready...";
log("%s", warningStr.c_str());
_sendTextStatus->setString(warningStr.c_str());
_sendTextStatus->setString(warningStr);
}
}

Expand All @@ -307,7 +307,7 @@ void WebSocketTest::onMenuSendMultipleTextClicked(cocos2d::Ref *sender)
{
std::string warningStr = "send text websocket instance wasn't ready...";
log("%s", warningStr.c_str());
_sendTextStatus->setString(warningStr.c_str());
_sendTextStatus->setString(warningStr);
}
}

Expand All @@ -327,7 +327,7 @@ void WebSocketTest::onMenuSendBinaryClicked(cocos2d::Ref *sender)
{
std::string warningStr = "send binary websocket instance wasn't ready...";
log("%s", warningStr.c_str());
_sendBinaryStatus->setString(warningStr.c_str());
_sendBinaryStatus->setString(warningStr);
}
}

Expand Down
16 changes: 8 additions & 8 deletions tests/cpp-tests/Classes/FileUtilsTest/FileUtilsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ void TextWritePlist::onEnter()
else
log("write plist file failed");

auto label = Label::createWithTTF(fullPath.c_str(), "fonts/Thonburi.ttf", 6);
auto label = Label::createWithTTF(fullPath, "fonts/Thonburi.ttf", 6);
this->addChild(label);
auto winSize = Director::getInstance()->getWinSize();
label->setPosition(winSize.width/2, winSize.height/3);
Expand Down Expand Up @@ -593,7 +593,7 @@ std::string TextWritePlist::title() const

std::string TextWritePlist::subtitle() const
{
std::string writablePath = FileUtils::getInstance()->getWritablePath().c_str();
std::string writablePath = FileUtils::getInstance()->getWritablePath();
return ("See plist file at your writablePath");
}

Expand All @@ -617,7 +617,7 @@ void TestWriteString::onEnter()
// writeTest
std::string writeDataStr = "the string data will be write into a file";
std::string fullPath = writablePath + fileName;
if (FileUtils::getInstance()->writeStringToFile(writeDataStr, fullPath.c_str()))
if (FileUtils::getInstance()->writeStringToFile(writeDataStr, fullPath))
{
log("see the plist file at %s", fullPath.c_str());
writeResult->setString("write success:" + writeDataStr);
Expand Down Expand Up @@ -793,7 +793,7 @@ void TestWriteData::onEnter()
Data writeData;
writeData.copy((unsigned char *)writeDataStr.c_str(), writeDataStr.size());
std::string fullPath = writablePath + fileName;
if (FileUtils::getInstance()->writeDataToFile(writeData, fullPath.c_str()))
if (FileUtils::getInstance()->writeDataToFile(writeData, fullPath))
{
log("see the plist file at %s", fullPath.c_str());
writeResult->setString("write success:" + writeDataStr);
Expand Down Expand Up @@ -881,7 +881,7 @@ void TestWriteValueMap::onEnter()
// end with /
std::string writablePath = FileUtils::getInstance()->getWritablePath();
std::string fullPath = writablePath + "testWriteValueMap.plist";
if (FileUtils::getInstance()->writeValueMapToFile(valueMap, fullPath.c_str()))
if (FileUtils::getInstance()->writeValueMapToFile(valueMap, fullPath))
{
log("see the plist file at %s", fullPath.c_str());
writeResult->setString("write success");
Expand All @@ -892,7 +892,7 @@ void TestWriteValueMap::onEnter()
writeResult->setString("write failed");
}

ValueMap readValueMap = FileUtils::getInstance()->getValueMapFromFile(fullPath.c_str());
ValueMap readValueMap = FileUtils::getInstance()->getValueMapFromFile(fullPath);
std::string readDataStr = "read data:\n";
// read value map data
ValueMap readMapInMap = readValueMap["data0"].asValueMap();
Expand Down Expand Up @@ -984,7 +984,7 @@ void TestWriteValueVector::onEnter()
// end with /
std::string writablePath = FileUtils::getInstance()->getWritablePath();
std::string fullPath = writablePath + "testWriteValueVector.plist";
if (FileUtils::getInstance()->writeValueVectorToFile(array, fullPath.c_str()))
if (FileUtils::getInstance()->writeValueVectorToFile(array, fullPath))
{
log("see the plist file at %s", fullPath.c_str());
writeResult->setString("write success");
Expand All @@ -995,7 +995,7 @@ void TestWriteValueVector::onEnter()
writeResult->setString("write failed");
}

ValueVector readArray = FileUtils::getInstance()->getValueVectorFromFile(fullPath.c_str());
ValueVector readArray = FileUtils::getInstance()->getValueVectorFromFile(fullPath);
std::string readDataStr = "read data:\n";
// read value map data
ValueMap readMapInArray = readArray.at(0).asValueMap();
Expand Down
8 changes: 4 additions & 4 deletions tests/cpp-tests/Classes/InputTest/MouseTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,31 @@ void MouseEventTest::onMouseDown(Event *event)
EventMouse* e = (EventMouse*)event;
std::string str = "Mouse Down detected, Key: ";
str += tostr(static_cast<int>(e->getMouseButton()));
_labelAction->setString(str.c_str());
_labelAction->setString(str);
}

void MouseEventTest::onMouseUp(Event *event)
{
EventMouse* e = (EventMouse*)event;
std::string str = "Mouse Up detected, Key: ";
str += tostr(static_cast<int>(e->getMouseButton()));
_labelAction->setString(str.c_str());
_labelAction->setString(str);
}

void MouseEventTest::onMouseMove(Event *event)
{
EventMouse* e = (EventMouse*)event;
std::string str = "MousePosition X:";
str = str + tostr(e->getCursorX()) + " Y:" + tostr(e->getCursorY());
_labelPosition->setString(str.c_str());
_labelPosition->setString(str);
}

void MouseEventTest::onMouseScroll(Event *event)
{
EventMouse* e = (EventMouse*)event;
std::string str = "Mouse Scroll detected, X: ";
str = str + tostr(e->getScrollX()) + " Y: " + tostr(e->getScrollY());
_labelAction->setString(str.c_str());
_labelAction->setString(str);
}

std::string MouseEventTest::title() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ void CustomEventTest::onEnter()
char* buf = static_cast<char*>(event->getUserData());
str += buf;
str += " times";
statusLabel->setString(str.c_str());
statusLabel->setString(str);
});

_eventDispatcher->addEventListenerWithFixedPriority(_listener, 1);
Expand All @@ -418,7 +418,7 @@ void CustomEventTest::onEnter()
char* buf = static_cast<char*>(event->getUserData());
str += buf;
str += " times";
statusLabel2->setString(str.c_str());
statusLabel2->setString(str);
});

_eventDispatcher->addEventListenerWithFixedPriority(_listener2, 1);
Expand Down
Loading