From ff37192e945c9083d313ddc8924ef433e193f9c7 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 4 Aug 2014 12:03:37 +0200 Subject: BasicStyleCheck: Dividers are exactly 80 slashes. --- src/CheckBasicStyle.lua | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/CheckBasicStyle.lua') diff --git a/src/CheckBasicStyle.lua b/src/CheckBasicStyle.lua index 13a6d15d2..c743a84a5 100644 --- a/src/CheckBasicStyle.lua +++ b/src/CheckBasicStyle.lua @@ -10,11 +10,12 @@ Checks that all source files (*.cpp, *.h) use the basic style requirements of th - Spaces after comma, not before - Opening braces not at the end of a code line - Spaces after if, for, while + - Line dividers (////...) exactly 80 slashes - (TODO) Spaces before *, /, & - (TODO) Hex numbers with even digit length - (TODO) Hex numbers in lowercase - - (TODO) Line dividers (////...) exactly 80 slashes - (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) @@ -165,6 +166,21 @@ local function ProcessFile(a_FileName) for _, pat in ipairs(g_ViolationPatterns) do ReportViolationIfFound(a_Line, a_FileName, lineCounter, pat[1], pat[2]) end + + local dividerStart, dividerEnd = a_Line:find("/////*") + if (dividerStart) then + if (dividerEnd ~= dividerStart + 79) then + ReportViolation(a_FileName, lineCounter, 1, 80, "Divider comment should have exactly 80 slashes") + end + if (dividerStart > 1) then + if ( + (a_Line:sub(1, dividerStart - 1) ~= string.rep("\t", dividerStart - 1)) or -- The divider should have only indent in front of it + (a_Line:len() > dividerEnd + 1) -- The divider should have no other text following it + ) then + ReportViolation(a_FileName, lineCounter, 1, 80, "Divider comment shouldn't have any extra text around it") + end + end + end lineCounter = lineCounter + 1 end -- cgit v1.2.3 From 7bfb0b05d0514c47095ba3ec8ebb6a1073d9962a Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 4 Aug 2014 13:20:16 +0200 Subject: CheckBasicStyle: multi-level indent change. --- src/CheckBasicStyle.lua | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/CheckBasicStyle.lua') 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 -- cgit v1.2.3 From 9b68ff2656d5e662d33c670ee5fa20dd12b8264f Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 28 Aug 2014 16:53:26 +0300 Subject: CheckBasicStyle: Added checking for the "template" keyword. --- src/CheckBasicStyle.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/CheckBasicStyle.lua') diff --git a/src/CheckBasicStyle.lua b/src/CheckBasicStyle.lua index bf81a7cd5..b244b1fbc 100644 --- a/src/CheckBasicStyle.lua +++ b/src/CheckBasicStyle.lua @@ -108,7 +108,7 @@ local g_ViolationPatterns = -- Check that all commas have spaces after them and not in front of them: {" ,", "Extra space before a \",\""}, - {",[^%s\"%%]", "Needs a space after a \",\""}, -- Report all except >> "," << needed for splitting and >>,%s<< needed for formatting + {",[^%s\"%%\']", "Needs a space after a \",\""}, -- Report all except >> "," << needed for splitting and >>,%s<< needed for formatting -- Check that opening braces are not at the end of a code line: {"[^%s].-{\n?$", "Brace should be on a separate line"}, @@ -119,6 +119,7 @@ local g_ViolationPatterns = {"while%(", "Needs a space after \"while\""}, {"switch%(", "Needs a space after \"switch\""}, {"catch%(", "Needs a space after \"catch\""}, + {"template<", "Needs a space after \"template\""}, -- No space after keyword's parenthesis: {"[^%a#]if %( ", "Remove the space after \"(\""}, -- cgit v1.2.3