diff options
author | peterbell10 <peterbell10@live.co.uk> | 2018-07-26 23:24:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-26 23:24:36 +0200 |
commit | 950aeffff8d641a0855fbd9a9b2993d9dfd7d2c3 (patch) | |
tree | 5e6fde4625714922e970bd5ad4ea339f58ab6b57 /src/CheckBasicStyle.lua | |
parent | At long last... Piston animations! (diff) | |
download | cuberite-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-x | src/CheckBasicStyle.lua | 28 |
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 ) |