1
0

CheckBasicStyle: Added a check for parentheses around comparisons.

The check is only rudimentary and tends to fall towards missed positived rather than false positives.
This commit is contained in:
Mattes D 2014-12-05 12:58:30 +01:00
parent 44644ae025
commit 21d5374b97

View File

@ -92,6 +92,25 @@ end
local g_ViolationPatterns =
{
-- Parenthesis around comparisons:
{"==[^)]+&&", "Add parenthesis around comparison"},
{"&&[^(]+==", "Add parenthesis around comparison"},
{"==[^)]+||", "Add parenthesis around comparison"},
{"||[^(]+==", "Add parenthesis around comparison"},
{"!=[^)]+&&", "Add parenthesis around comparison"},
{"&&[^(]+!=", "Add parenthesis around comparison"},
{"!=[^)]+||", "Add parenthesis around comparison"},
{"||[^(]+!=", "Add parenthesis around comparison"},
{"<[^)T][^)]*&&", "Add parenthesis around comparison"}, -- Must take special care of templates: "template <T> fn(Args && ...)"
{"&&[^(]+<", "Add parenthesis around comparison"},
{"<[^)T][^)]*||", "Add parenthesis around comparison"}, -- Must take special care of templates: "template <T> fn(Args && ...)"
{"||[^(]+<", "Add parenthesis around comparison"},
-- Cannot check ">" because of "obj->m_Flag &&". Check at least ">=":
{">=[^)]+&&", "Add parenthesis around comparison"},
{"&&[^(]+>=", "Add parenthesis around comparison"},
{">=[^)]+||", "Add parenthesis around comparison"},
{"||[^(]+>=", "Add parenthesis around comparison"},
-- Check against indenting using spaces:
{"^\t* +", "Indenting with a space"},
@ -227,6 +246,9 @@ end
-- Remove buffering from stdout, so that the output appears immediately in IDEs:
io.stdout:setvbuf("no")
-- Process all files in the AllFiles.lst file (generated by cmake):
for fnam in io.lines("AllFiles.lst") do
ProcessItem(fnam)