From ac6cdc8dd5f42820014b5d0b09b5e52593fb0a20 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 10 Mar 2017 16:18:56 +0300 Subject: Add check for new CLASS(). Here brackets should be removed. --- src/Makefile.am | 1 + src/rules/constructorbrackets.cpp | 43 +++++++++++++++++++++++++++++++++++++ tests/testreport.txt | 6 ++++-- tests/testsrc/bad/brackets.cpp | 2 ++ tests/testsrc/bad/brackets.h | 7 ++++++ tests/testsrc/good/brackets2.cpp | 2 ++ tests/testsrc/good/constructor1.cpp | 2 ++ 7 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/rules/constructorbrackets.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 0375ff2..3557e43 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,6 +19,7 @@ mplint_SOURCES = \ template.hpp \ rules/brackets.cpp \ rules/constructor.cpp \ + rules/constructorbrackets.cpp \ rules/copyconstructor.cpp \ rules/debug.cpp \ rules/dump.cpp \ diff --git a/src/rules/constructorbrackets.cpp b/src/rules/constructorbrackets.cpp new file mode 100644 index 0000000..73dd9f3 --- /dev/null +++ b/src/rules/constructorbrackets.cpp @@ -0,0 +1,43 @@ +/* + * The ManaPlus Client + * Copyright (C) 2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "template.hpp" + +registerRuleExt(constructorBrackets, "017", "(.+)[.](cpp|h)") + +startRule(constructorBrackets) +{ +} + +endRule(constructorBrackets) +{ +} + +parseLineRule(constructorBrackets) +{ + if (data.find("new ") != std::string::npos) + { + std::smatch m; + if (isMatch(data, "(.+)[ ]new[ ]([a-zA-Z_0123456789]+)[(][)](.+)", m)) + { + print("Remove () after new CLASS()."); + } + } +} diff --git a/tests/testreport.txt b/tests/testreport.txt index e56ac61..da80304 100644 --- a/tests/testreport.txt +++ b/tests/testreport.txt @@ -4,9 +4,10 @@ [testsrc/bad/brackets.cpp:45]: V015: Brackets formatting error. Wrong last bracket position [testsrc/bad/brackets.cpp:56]: V015: Brackets formatting error. Wrong first bracket position [testsrc/bad/brackets.cpp:69]: V015: Brackets formatting error. Wrong last bracket position -[testsrc/bad/brackets.cpp:76]: V015: Brackets formatting error. Wrong last bracket position -[testsrc/bad/brackets.cpp:77]: V015: Brackets formatting error. Wrong last bracket position +[testsrc/bad/brackets.cpp:72]: V017: Remove () after new CLASS(). [testsrc/bad/brackets.cpp:78]: V015: Brackets formatting error. Wrong last bracket position +[testsrc/bad/brackets.cpp:79]: V015: Brackets formatting error. Wrong last bracket position +[testsrc/bad/brackets.cpp:80]: V015: Brackets formatting error. Wrong last bracket position [testsrc/bad/brackets.h:21]: V015: Brackets formatting error. Wrong last bracket position [testsrc/bad/brackets.h:32]: V015: Brackets formatting error. Wrong last bracket position [testsrc/bad/brackets.h:43]: V015: Brackets formatting error. Wrong last bracket position @@ -15,6 +16,7 @@ [testsrc/bad/brackets.h:74]: V015: Brackets formatting error. Wrong last bracket position [testsrc/bad/brackets.h:75]: V015: Brackets formatting error. Wrong last bracket position [testsrc/bad/brackets.h:76]: V015: Brackets formatting error. Wrong last bracket position +[testsrc/bad/brackets.h:83]: V017: Remove () after new CLASS(). [testsrc/bad/constructor1.cpp:25]: V007: Need add final or notfinal into class declaration [testsrc/bad/constructor1.cpp:32]: V007: Need add final or notfinal into class declaration [testsrc/bad/constructor1.cpp:34]: V006: Add space between constructor and ":". diff --git a/tests/testsrc/bad/brackets.cpp b/tests/testsrc/bad/brackets.cpp index 898a258..7fc6552 100644 --- a/tests/testsrc/bad/brackets.cpp +++ b/tests/testsrc/bad/brackets.cpp @@ -69,6 +69,8 @@ void func5() else { } } + type *var = new type(); + type2 *var2 = new type2(123); } void func6() diff --git a/tests/testsrc/bad/brackets.h b/tests/testsrc/bad/brackets.h index bb1ba39..d56d23f 100644 --- a/tests/testsrc/bad/brackets.h +++ b/tests/testsrc/bad/brackets.h @@ -77,3 +77,10 @@ void func6() } } } + +void func7() +{ + type *var = new type(); + type *var2; + type2 *var3 = new type2(123); +} diff --git a/tests/testsrc/good/brackets2.cpp b/tests/testsrc/good/brackets2.cpp index 2199d6f..fe9ed3c 100644 --- a/tests/testsrc/good/brackets2.cpp +++ b/tests/testsrc/good/brackets2.cpp @@ -78,4 +78,6 @@ void func6() // } else { // } // } + type *var = mnew type(); + type2 *var = new type2(123); } diff --git a/tests/testsrc/good/constructor1.cpp b/tests/testsrc/good/constructor1.cpp index d300f06..99f12f7 100644 --- a/tests/testsrc/good/constructor1.cpp +++ b/tests/testsrc/good/constructor1.cpp @@ -38,5 +38,7 @@ struct Test2 final data1(), data2() { + type *var = mnew type(); + type2 *var = new type2(123); } } -- cgit v1.2.3-60-g2f50