Skip to content

Commit 86acfba

Browse files
JohnCoconutminggo
authored andcommitted
add new clang-tidy option (#19670)
* add new clang-tidy option * readability-container-size-empty * minor fix for UnitTest * clang-tidy: filter external directory * add comment on python regular expression [ci skip]
1 parent b5293f2 commit 86acfba

File tree

73 files changed

+260
-257
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+260
-257
lines changed

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Checks: >
88
performance-inefficient-vector-operation,
99
performance-move-const-arg,
1010
performance-type-promotion-in-math-fn,
11+
readability-container-size-empty,
1112
1213
WarningsAsErrors: '*'
1314
HeaderFilterRegex: '/(?!external)/.*'

cocos/2d/CCAtlasNode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ AtlasNode * AtlasNode::create(const std::string& tile, int tileWidth, int tileHe
7171

7272
bool AtlasNode::initWithTileFile(const std::string& tile, int tileWidth, int tileHeight, int itemsToRender)
7373
{
74-
CCASSERT(tile.size() > 0, "file size should not be empty");
74+
CCASSERT(!tile.empty(), "file size should not be empty");
7575
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(tile);
7676
return initWithTexture(texture, tileWidth, tileHeight, itemsToRender);
7777
}

cocos/2d/CCClippingNode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ void ClippingNode::setStencil(Node *stencil)
332332

333333
bool ClippingNode::hasContent() const
334334
{
335-
return _children.size() > 0;
335+
return !_children.empty();
336336
}
337337

338338
GLfloat ClippingNode::getAlphaThreshold() const

cocos/2d/CCFastTMXTiledMap.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ TMXTiledMap* TMXTiledMap::createWithXML(const std::string& tmxString, const std:
6060

6161
bool TMXTiledMap::initWithTMXFile(const std::string& tmxFile)
6262
{
63-
CCASSERT(tmxFile.size()>0, "FastTMXTiledMap: tmx file should not be empty");
63+
CCASSERT(!tmxFile.empty(), "FastTMXTiledMap: tmx file should not be empty");
6464

6565
setContentSize(Size::ZERO);
6666

@@ -198,7 +198,7 @@ void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo)
198198
// public
199199
TMXLayer * TMXTiledMap::getLayer(const std::string& layerName) const
200200
{
201-
CCASSERT(layerName.size() > 0, "Invalid layer name!");
201+
CCASSERT(!layerName.empty(), "Invalid layer name!");
202202

203203
for (auto& child : _children)
204204
{
@@ -218,9 +218,9 @@ TMXLayer * TMXTiledMap::getLayer(const std::string& layerName) const
218218

219219
TMXObjectGroup * TMXTiledMap::getObjectGroup(const std::string& groupName) const
220220
{
221-
CCASSERT(groupName.size() > 0, "Invalid group name!");
221+
CCASSERT(!groupName.empty(), "Invalid group name!");
222222

223-
if (_objectGroups.size()>0)
223+
if (!_objectGroups.empty())
224224
{
225225
for (const auto& objectGroup : _objectGroups)
226226
{

cocos/2d/CCMenuItem.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ bool MenuItemAtlasFont::initWithString(const std::string& value, const std::stri
334334

335335
bool MenuItemAtlasFont::initWithString(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback)
336336
{
337-
CCASSERT( value.size() != 0, "value length must be greater than 0");
337+
CCASSERT( !value.empty(), "value length must be greater than 0");
338338
LabelAtlas *label = LabelAtlas::create();
339339
label->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap);
340340
if (MenuItemLabel::initWithLabel(label, callback))
@@ -736,17 +736,17 @@ bool MenuItemImage::initWithNormalImage(const std::string& normalImage, const st
736736
Node *selectedSprite = nullptr;
737737
Node *disabledSprite = nullptr;
738738

739-
if (normalImage.size() >0)
739+
if (!normalImage.empty())
740740
{
741741
normalSprite = Sprite::create(normalImage);
742742
}
743743

744-
if (selectedImage.size() >0)
744+
if (!selectedImage.empty())
745745
{
746746
selectedSprite = Sprite::create(selectedImage);
747747
}
748748

749-
if(disabledImage.size() >0)
749+
if(!disabledImage.empty())
750750
{
751751
disabledSprite = Sprite::create(disabledImage);
752752
}
@@ -952,7 +952,7 @@ void MenuItemToggle::cleanup()
952952

953953
void MenuItemToggle::setSelectedIndex(unsigned int index)
954954
{
955-
if( index != _selectedIndex && _subItems.size() > 0 )
955+
if( index != _selectedIndex && !_subItems.empty() )
956956
{
957957
_selectedIndex = index;
958958
if (_selectedItem)

cocos/2d/CCSpriteBatchNode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ ssize_t SpriteBatchNode::lowestAtlasIndexInChild(Sprite *sprite)
467467
{
468468
auto& children = sprite->getChildren();
469469

470-
if (children.size() == 0)
470+
if (children.empty())
471471
{
472472
return sprite->getAtlasIndex();
473473
}

cocos/2d/CCSpriteFrameCache.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ void SpriteFrameCache::addSpriteFramesWithFileContent(const std::string& plist_c
343343

344344
void SpriteFrameCache::addSpriteFramesWithFile(const std::string& plist, const std::string& textureFileName)
345345
{
346-
CCASSERT(textureFileName.size()>0, "texture name should not be null");
346+
CCASSERT(!textureFileName.empty(), "texture name should not be null");
347347
const std::string fullPath = FileUtils::getInstance()->fullPathForFilename(plist);
348348
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(fullPath);
349349
addSpriteFramesWithDictionary(dict, textureFileName, plist);
@@ -656,7 +656,7 @@ void SpriteFrameCache::reloadSpriteFramesWithDictionary(ValueMap& dictionary, Te
656656

657657
bool SpriteFrameCache::reloadTexture(const std::string& plist)
658658
{
659-
CCASSERT(plist.size()>0, "plist filename should not be nullptr");
659+
CCASSERT(!plist.empty(), "plist filename should not be nullptr");
660660

661661
if (_spriteFramesCache.isPlistUsed(plist)) {
662662
_spriteFramesCache.erasePlistIndex(plist);
@@ -784,7 +784,7 @@ bool SpriteFrameCache::PlistFramesCache::hasFrame(const std::string &frame) cons
784784
bool SpriteFrameCache::PlistFramesCache::isPlistUsed(const std::string &plist) const
785785
{
786786
auto frames = _indexPlist2Frames.find(plist);
787-
return frames != _indexPlist2Frames.end() && frames->second.size() > 0;
787+
return frames != _indexPlist2Frames.end() && !frames->second.empty();
788788
}
789789

790790
SpriteFrame * SpriteFrameCache::PlistFramesCache::at(const std::string &frame)

cocos/2d/CCTMXTiledMap.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ TMXTiledMap* TMXTiledMap::createWithXML(const std::string& tmxString, const std:
6161

6262
bool TMXTiledMap::initWithTMXFile(const std::string& tmxFile)
6363
{
64-
CCASSERT(tmxFile.size()>0, "TMXTiledMap: tmx file should not be empty");
64+
CCASSERT(!tmxFile.empty(), "TMXTiledMap: tmx file should not be empty");
6565

6666
_tmxFile = tmxFile;
6767

@@ -203,7 +203,7 @@ void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo)
203203
// public
204204
TMXLayer * TMXTiledMap::getLayer(const std::string& layerName) const
205205
{
206-
CCASSERT(layerName.size() > 0, "Invalid layer name!");
206+
CCASSERT(!layerName.empty(), "Invalid layer name!");
207207

208208
for (auto& child : _children)
209209
{
@@ -223,7 +223,7 @@ TMXLayer * TMXTiledMap::getLayer(const std::string& layerName) const
223223

224224
TMXObjectGroup * TMXTiledMap::getObjectGroup(const std::string& groupName) const
225225
{
226-
CCASSERT(groupName.size() > 0, "Invalid group name!");
226+
CCASSERT(!groupName.empty(), "Invalid group name!");
227227

228228
for (const auto objectGroup : _objectGroups)
229229
{

cocos/2d/CCTMXXMLParser.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ void TMXMapInfo::startElement(void* /*ctx*/, const char *name, const char **atts
293293
{
294294
// If this is an external tileset then start parsing that
295295
std::string externalTilesetFilename = attributeDict["source"].asString();
296-
if (externalTilesetFilename != "")
296+
if (!externalTilesetFilename.empty())
297297
{
298298
_externalTilesetFilename = externalTilesetFilename;
299299

@@ -444,15 +444,15 @@ void TMXMapInfo::startElement(void* /*ctx*/, const char *name, const char **atts
444444
}
445445
else
446446
{
447-
tileset->_sourceImage = _resources + (_resources.size() ? "/" : "") + imagename;
447+
tileset->_sourceImage = _resources + (!_resources.empty() ? "/" : "") + imagename;
448448
}
449449
}
450450
else if (elementName == "data")
451451
{
452452
std::string encoding = attributeDict["encoding"].asString();
453453
std::string compression = attributeDict["compression"].asString();
454454

455-
if (encoding == "")
455+
if (encoding.empty())
456456
{
457457
tmxMapInfo->setLayerAttribs(tmxMapInfo->getLayerAttribs() | TMXLayerAttribNone);
458458

@@ -482,7 +482,7 @@ void TMXMapInfo::startElement(void* /*ctx*/, const char *name, const char **atts
482482
layerAttribs = tmxMapInfo->getLayerAttribs();
483483
tmxMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribZlib);
484484
}
485-
CCASSERT( compression == "" || compression == "gzip" || compression == "zlib", "TMX: unsupported compression method" );
485+
CCASSERT( compression.empty() || compression == "gzip" || compression == "zlib", "TMX: unsupported compression method" );
486486
}
487487
else if (encoding == "csv")
488488
{

cocos/2d/CCTextFieldTTF.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ TextFieldTTF * TextFieldTTF::textFieldWithPlaceHolder(const std::string& placeho
114114
if(ret && ret->initWithPlaceHolder("", dimensions, alignment, fontName, fontSize))
115115
{
116116
ret->autorelease();
117-
if (placeholder.size()>0)
117+
if (!placeholder.empty())
118118
{
119119
ret->setPlaceHolder(placeholder);
120120
}
@@ -130,7 +130,7 @@ TextFieldTTF * TextFieldTTF::textFieldWithPlaceHolder(const std::string& placeho
130130
if(ret && ret->initWithPlaceHolder("", fontName, fontSize))
131131
{
132132
ret->autorelease();
133-
if (placeholder.size()>0)
133+
if (!placeholder.empty())
134134
{
135135
ret->setPlaceHolder(placeholder);
136136
}

0 commit comments

Comments
 (0)