summaryrefslogtreecommitdiffstats
path: root/src/CheckBasicStyle.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/CheckBasicStyle.lua')
-rwxr-xr-x[-rw-r--r--]src/CheckBasicStyle.lua137
1 files changed, 135 insertions, 2 deletions
diff --git a/src/CheckBasicStyle.lua b/src/CheckBasicStyle.lua
index 19156b537..fa20f18f7 100644..100755
--- a/src/CheckBasicStyle.lua
+++ b/src/CheckBasicStyle.lua
@@ -43,6 +43,7 @@ local g_IgnoredFiles =
{
"Bindings/Bindings.h",
"Bindings/Bindings.cpp",
+ "Bindings/LuaState_Implementation.cpp",
"LeakFinder.cpp",
"LeakFinder.h",
"MersenneTwister.h",
@@ -149,6 +150,39 @@ local g_ViolationPatterns =
-- No space before a closing parenthesis:
{" %)", "Remove the space before \")\""},
+
+ -- Check spaces around "+":
+ {"^[a-zA-Z0-9]+%+[a-zA-Z0-9]+", "Add space around +"},
+ {"[!@#$%%%^&*() %[%]\t][a-zA-Z0-9]+%+[a-zA-Z0-9]+", "Add space around +"},
+ --[[
+ -- Cannot check these because of text such as "X+" and "+2" appearing in some comments.
+ {"^[a-zA-Z0-9]+ %+[a-zA-Z0-9]+", "Add space after +"},
+ {"[!@#$%%%^&*() %[%]\t][a-zA-Z0-9]+ %+[a-zA-Z0-9]+", "Add space after +"},
+ {"^[a-zA-Z0-9]+%+ [a-zA-Z0-9]+", "Add space before +"},
+ {"[!@#$%%%^&*() %[%]\t][a-zA-Z0-9]+%+ [a-zA-Z0-9]+", "Add space before +"},
+ --]]
+
+ -- Cannot check spaces around "-", because the minus is sometimes used as a hyphen between-words
+
+ -- Check spaces around "*":
+ {"^[a-zA-Z0-9]+%*[a-zA-Z0-9]+", "Add space around *"},
+ {"^[^\"]*[!@#$%%%^&*() %[%]\t][a-zA-Z0-9]+%*[a-zA-Z0-9]+", "Add space around *"},
+ {"^[a-zB-Z0-9]+%* [a-zA-Z0-9]+", "Add space before *"},
+ {"^[^\"]*[!@#$%%%^&*() %[%]\t][a-zB-Z0-9]+%* [a-zA-Z0-9]+", "Add space before *"},
+
+ -- Check spaces around "/":
+ {"^[a-zA-Z0-9]+%/[a-zA-Z0-9]+", "Add space around /"},
+ {"^[^\"]*[!@#$%%%^&*() %[%]\t][a-zA-Z0-9]+%/[a-zA-Z0-9]+", "Add space around /"},
+
+ -- Check spaces around "&":
+ {"^[a-zA-Z0-9]+%&[a-zA-Z0-9]+", "Add space around /"},
+ {"^[^\"]*[!@#$%%%^&*() %[%]\t][a-zA-Z0-9]+%&[a-zA-Z0-9]+", "Add space around /"},
+ {"^[a-zA-Z0-9]+%& [a-zA-Z0-9]+", "Add space before &"},
+ {"^[^\"]*[!@#$%%%^&*() %[%]\t][a-zA-Z0-9]+%& [a-zA-Z0-9]+", "Add space before &"},
+
+ -- We don't like "Type const *" and "Type const &". Use "const Type *" and "const Type &" instead:
+ {"const %&", "Use 'const Type &' instead of 'Type const &'"},
+ {"const %*", "Use 'const Type *' instead of 'Type const *'"},
}
@@ -266,14 +300,113 @@ end
+--- Array of files to process. Filled from cmdline arguments
+local ToProcess = {}
+
+
+
+
+
+--- Handlers for the command-line arguments
+-- Maps flag => function
+local CmdLineHandlers =
+{
+ -- "-f file" checks the specified file
+ ["-f"] = function (a_Args, a_Idx)
+ local fnam = a_Args[a_Idx + 1]
+ if not(fnam) then
+ error("Invalid flag: '-f' needs a filename following it.")
+ end
+ table.insert(ToProcess, fnam)
+ return a_Idx + 2 -- skip the filename in param parsing
+ end,
+
+ -- "-g" checks files reported by git as being committed.
+ ["-g"] = function (a_Args, a_Idx)
+ local f = io.popen("git diff --cached --name-only --diff-filter=ACMR")
+ for fnam in f:lines() do
+ table.insert(ToProcess, fnam)
+ end
+ end,
+
+ -- "-h" prints help and exits
+ ["-h"] = function (a_Args, a_Idx)
+ print([[
+Usage:")
+"CheckBasicStyle [<options>]
+
+Available options:
+-f <filename> - checks the specified filename
+-g - checks files reported by Git as being committed
+-h - prints this help and exits
+-l <listfile> - checks all files listed in the specified listfile
+-- - reads the list of files to check from stdin
+
+When no options are given, the script checks all files listed in the AllFiles.lst file.
+
+Only .cpp and .h files are ever checked.
+]])
+ os.exit(0)
+ end,
+
+ -- "-l listfile" loads the list of files to check from the specified listfile
+ ["-l"] = function (a_Args, a_Idx)
+ local listFile = a_Args[a_Idx + 1]
+ if not(listFile) then
+ error("Invalid flag: '-l' needs a filename following it.")
+ end
+ for fnam in io.lines(listFile) do
+ table.insert(ToProcess, fnam)
+ end
+ return a_Idx + 2 -- Skip the listfile in param parsing
+ end,
+
+ -- "--" reads the list of files from stdin
+ ["--"] = function (a_Args, a_Idx)
+ for fnam in io.lines() do
+ table.insert(ToProcess, fnam)
+ end
+ 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
+-- Parse the cmdline arguments to see what files to check:
+local idx = 1
+while (arg[idx]) do
+ local handler = CmdLineHandlers[arg[idx]]
+ if not(handler) then
+ error("Unknown command-line argument #" .. idx .. ": " .. arg[idx])
+ end
+ idx = handler(arg, idx) or (idx + 1) -- Call the handler, let it change the next index if it wants
+end
+
+
+-- By default process all files in the AllFiles.lst file (generated by cmake):
+if not(arg[1]) then
+ for fnam in io.lines("AllFiles.lst") do
+ table.insert(ToProcess, fnam)
+ end
+end
+
+
+
+
+
+-- Process the files in the list:
+for _, fnam in ipairs(ToProcess) do
ProcessItem(fnam)
end
+
+
+
+
-- Report final verdict:
print("Number of violations found: " .. g_NumViolations)
if (g_NumViolations > 0) then