summaryrefslogtreecommitdiffstats
path: root/src/CheckBasicStyle.lua
diff options
context:
space:
mode:
authorpeterbell10 <peterbell10@live.co.uk>2018-07-26 23:24:36 +0200
committerGitHub <noreply@github.com>2018-07-26 23:24:36 +0200
commit950aeffff8d641a0855fbd9a9b2993d9dfd7d2c3 (patch)
tree5e6fde4625714922e970bd5ad4ea339f58ab6b57 /src/CheckBasicStyle.lua
parentAt long last... Piston animations! (diff)
downloadcuberite-950aeffff8d641a0855fbd9a9b2993d9dfd7d2c3.tar
cuberite-950aeffff8d641a0855fbd9a9b2993d9dfd7d2c3.tar.gz
cuberite-950aeffff8d641a0855fbd9a9b2993d9dfd7d2c3.tar.bz2
cuberite-950aeffff8d641a0855fbd9a9b2993d9dfd7d2c3.tar.lz
cuberite-950aeffff8d641a0855fbd9a9b2993d9dfd7d2c3.tar.xz
cuberite-950aeffff8d641a0855fbd9a9b2993d9dfd7d2c3.tar.zst
cuberite-950aeffff8d641a0855fbd9a9b2993d9dfd7d2c3.zip
Diffstat (limited to '')
-rwxr-xr-xsrc/CheckBasicStyle.lua28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/CheckBasicStyle.lua b/src/CheckBasicStyle.lua
index 6cd499fd1..4376d460a 100755
--- a/src/CheckBasicStyle.lua
+++ b/src/CheckBasicStyle.lua
@@ -44,11 +44,6 @@ local g_IgnoredFiles =
"Bindings/Bindings.h",
"Bindings/Bindings.cpp",
"Bindings/LuaState_Implementation.cpp",
- "LeakFinder.cpp",
- "LeakFinder.h",
- "MersenneTwister.h",
- "StackWalker.cpp",
- "StackWalker.h",
}
--- The list of files not to be processed, as a dictionary (filename => true), built from g_IgnoredFiles
@@ -241,6 +236,9 @@ local function ProcessFile(a_FileName)
local lineCounter = 1
local lastIndentLevel = 0
local isLastLineControl = false
+ local lastNonEmptyLine = 0
+ local isAfterFunction = false
+ local isSourceFile = a_FileName:match("%.cpp")
all = all:gsub("\r\n", "\n") -- normalize CRLF into LF-only
string.gsub(all .. "\n", "[^\n]*\n", -- Iterate over each line, while preserving empty lines
function(a_Line)
@@ -296,6 +294,26 @@ local function ProcessFile(a_FileName)
lineWithSpace:find("^%s+else //") or
lineWithSpace:find("^%s+do %b()")
+
+ -- Check that exactly 5 empty lines are left beteen functions and no more than 5 elsewhere
+ if not(a_Line:find("^\n")) then
+ local numEmptyLines = (lineCounter - lastNonEmptyLine) - 1
+
+ local isStartOfFunction = (
+ isAfterFunction and
+ a_Line:find("^[%s%w]")
+ )
+
+ if (isSourceFile and isStartOfFunction and (numEmptyLines ~= 5)) then
+ ReportViolation(a_FileName, lineCounter - 1, 1, 1, "Leave exactly 5 empty lines between functions (found " .. numEmptyLines ..")")
+ elseif (numEmptyLines > 5) then
+ ReportViolation(a_FileName, lineCounter - 1, 1, 1, "Leave at most 5 consecutive empty lines (found " .. numEmptyLines .. ")")
+ end
+
+ lastNonEmptyLine = lineCounter
+ isAfterFunction = (a_Line == "}\n")
+ end
+
lineCounter = lineCounter + 1
end
)