diff options
author | madmaxoft <github@xoft.cz> | 2014-08-04 13:20:16 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2014-08-04 13:20:29 +0200 |
commit | 7bfb0b05d0514c47095ba3ec8ebb6a1073d9962a (patch) | |
tree | 31ce509c35c190aab82c86b3252f59b8acc74355 /src/CheckBasicStyle.lua | |
parent | BasicStyleCheck: Dividers are exactly 80 slashes. (diff) | |
download | cuberite-7bfb0b05d0514c47095ba3ec8ebb6a1073d9962a.tar cuberite-7bfb0b05d0514c47095ba3ec8ebb6a1073d9962a.tar.gz cuberite-7bfb0b05d0514c47095ba3ec8ebb6a1073d9962a.tar.bz2 cuberite-7bfb0b05d0514c47095ba3ec8ebb6a1073d9962a.tar.lz cuberite-7bfb0b05d0514c47095ba3ec8ebb6a1073d9962a.tar.xz cuberite-7bfb0b05d0514c47095ba3ec8ebb6a1073d9962a.tar.zst cuberite-7bfb0b05d0514c47095ba3ec8ebb6a1073d9962a.zip |
Diffstat (limited to '')
-rw-r--r-- | src/CheckBasicStyle.lua | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/CheckBasicStyle.lua b/src/CheckBasicStyle.lua index c743a84a5..bf81a7cd5 100644 --- a/src/CheckBasicStyle.lua +++ b/src/CheckBasicStyle.lua @@ -11,11 +11,11 @@ Checks that all source files (*.cpp, *.h) use the basic style requirements of th - Opening braces not at the end of a code line - Spaces after if, for, while - Line dividers (////...) exactly 80 slashes + - Multi-level indent change - (TODO) Spaces before *, /, & - (TODO) Hex numbers with even digit length - (TODO) Hex numbers in lowercase - (TODO) Not using "* "-style doxy comment continuation lines - - (TODO) Multi-level indent change Violations that cannot be checked easily: - Spaces around "+" (there are things like "a++", "++a", "a += 1", "X+", "stack +1" and ascii-drawn tables) @@ -159,6 +159,7 @@ local function ProcessFile(a_FileName) -- Process each line separately: -- Ref.: http://stackoverflow.com/questions/10416869/iterate-over-possibly-empty-lines-in-a-way-that-matches-the-expectations-of-exis local lineCounter = 1 + local lastIndentLevel = 0 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) @@ -167,6 +168,7 @@ local function ProcessFile(a_FileName) ReportViolationIfFound(a_Line, a_FileName, lineCounter, pat[1], pat[2]) end + -- Check that divider comments are well formed - 80 slashes plus optional indent: local dividerStart, dividerEnd = a_Line:find("/////*") if (dividerStart) then if (dividerEnd ~= dividerStart + 79) then @@ -181,6 +183,19 @@ local function ProcessFile(a_FileName) end end end + + -- Check the indent level change from the last line, if it's too much, report: + local indentStart, indentEnd = a_Line:find("\t+") + local indentLevel = 0 + if (indentStart) then + indentLevel = indentEnd - indentStart + end + if (indentLevel > 0) then + if ((lastIndentLevel - indentLevel >= 2) or (lastIndentLevel - indentLevel <= -2)) then + ReportViolation(a_FileName, lineCounter, 1, indentStart or 1, "Indent changed more than a single level between the previous line and this one: from " .. lastIndentLevel .. " to " .. indentLevel) + end + lastIndentLevel = indentLevel + end lineCounter = lineCounter + 1 end |