Added HTTPS links wherever they are supported.
This commit is contained in:
@@ -16,10 +16,10 @@ Checks that all source files (*.cpp, *.h) use the basic style requirements of th
|
||||
- (TODO) Hex numbers with even digit length
|
||||
- (TODO) Hex numbers in lowercase
|
||||
- (TODO) Not using "* "-style doxy comment continuation lines
|
||||
|
||||
|
||||
Violations that cannot be checked easily:
|
||||
- Spaces around "+" (there are things like "a++", "++a", "a += 1", "X+", "stack +1" and ascii-drawn tables)
|
||||
|
||||
|
||||
Reports all violations on stdout in a form that is readable by Visual Studio's parser, so that dblclicking
|
||||
the line brings the editor directly to the violation.
|
||||
|
||||
@@ -114,38 +114,38 @@ local g_ViolationPatterns =
|
||||
|
||||
-- Check against indenting using spaces:
|
||||
{"^\t* +", "Indenting with a space"},
|
||||
|
||||
|
||||
-- Check against alignment using tabs:
|
||||
{"[^%s]\t+[^%s]", "Aligning with a tab"},
|
||||
|
||||
|
||||
-- Check against trailing whitespace:
|
||||
{"[^%s]%s+\n", "Trailing whitespace"},
|
||||
|
||||
|
||||
-- Check that all "//"-style comments have at least two spaces in front (unless alone on line):
|
||||
{"[^%s] //", "Needs at least two spaces in front of a \"//\"-style comment"},
|
||||
|
||||
|
||||
-- Check that all "//"-style comments have at least one spaces after:
|
||||
{"%s//[^%s/*<]", "Needs a space after a \"//\"-style comment"},
|
||||
|
||||
|
||||
-- Check that doxy-comments are used only in the double-asterisk form:
|
||||
{"/// ", "Use doxycomments in the form /** Comment */"},
|
||||
|
||||
|
||||
-- Check that /* */ comments have whitespace around the insides:
|
||||
{"%*%*/", "Wrong comment termination, use */"},
|
||||
{"/%*[^%s*/\"]", "Needs a space after /*"}, -- Need to take care of the special "//*/" comment ends
|
||||
{"/%*%*[^%s*<]", "Needs a space after /**"},
|
||||
{"[^%s/*]%*/", "Needs a space before */"},
|
||||
|
||||
|
||||
-- Check against MS XML doxycomments:
|
||||
{"/%*%* <", "Remove the MS XML markers from comment"},
|
||||
|
||||
-- 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
|
||||
|
||||
|
||||
-- Check that opening braces are not at the end of a code line:
|
||||
{"[^%s].-{\n?$", "Brace should be on a separate line"},
|
||||
|
||||
|
||||
-- Space after keywords:
|
||||
{"[^_]if%(", "Needs a space after \"if\""},
|
||||
{"%sfor%(", "Needs a space after \"for\""},
|
||||
@@ -153,16 +153,16 @@ local g_ViolationPatterns =
|
||||
{"%sswitch%(", "Needs a space after \"switch\""},
|
||||
{"%scatch%(", "Needs a space after \"catch\""},
|
||||
{"%stemplate<", "Needs a space after \"template\""},
|
||||
|
||||
|
||||
-- No space after keyword's parenthesis:
|
||||
{"[^%a#]if %( ", "Remove the space after \"(\""},
|
||||
{"for %( ", "Remove the space after \"(\""},
|
||||
{"while %( ", "Remove the space after \"(\""},
|
||||
{"catch %( ", "Remove the space after \"(\""},
|
||||
|
||||
|
||||
-- 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 +"},
|
||||
@@ -173,7 +173,7 @@ local g_ViolationPatterns =
|
||||
{"^[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 "*":
|
||||
@@ -191,7 +191,7 @@ local g_ViolationPatterns =
|
||||
{"^[^\"]*[!@#$%%%^&*() %[%]\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 &"},
|
||||
|
||||
|
||||
-- Check spaces around "==", "<=" and ">=":
|
||||
{"==[a-zA-Z0-9]+", "Add space after =="},
|
||||
{"[a-zA-Z0-9]+==", "Add space before =="},
|
||||
@@ -212,7 +212,7 @@ local g_ViolationPatterns =
|
||||
--- Processes one file
|
||||
local function ProcessFile(a_FileName)
|
||||
assert(type(a_FileName) == "string")
|
||||
|
||||
|
||||
-- Read the whole file:
|
||||
local f, err = io.open(a_FileName, "r")
|
||||
if (f == nil) then
|
||||
@@ -222,7 +222,7 @@ local function ProcessFile(a_FileName)
|
||||
end
|
||||
local all = f:read("*all")
|
||||
f:close()
|
||||
|
||||
|
||||
-- Check that the last line is empty - otherwise processing won't work properly:
|
||||
local lastChar = string.byte(all, string.len(all))
|
||||
if ((lastChar ~= 13) and (lastChar ~= 10)) then
|
||||
@@ -231,9 +231,9 @@ local function ProcessFile(a_FileName)
|
||||
ReportViolation(a_FileName, numLines, 1, 1, "Missing empty line at file end")
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
-- Process each line separately:
|
||||
-- Ref.: http://stackoverflow.com/questions/10416869/iterate-over-possibly-empty-lines-in-a-way-that-matches-the-expectations-of-exis
|
||||
-- Ref.: https://stackoverflow.com/questions/10416869/iterate-over-possibly-empty-lines-in-a-way-that-matches-the-expectations-of-exis
|
||||
local lineCounter = 1
|
||||
local lastIndentLevel = 0
|
||||
local isLastLineControl = false
|
||||
@@ -244,7 +244,7 @@ local function ProcessFile(a_FileName)
|
||||
for _, pat in ipairs(g_ViolationPatterns) do
|
||||
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
|
||||
@@ -260,7 +260,7 @@ 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
|
||||
@@ -273,7 +273,7 @@ local function ProcessFile(a_FileName)
|
||||
end
|
||||
lastIndentLevel = indentLevel
|
||||
end
|
||||
|
||||
|
||||
-- Check that control statements have braces on separate lines after them:
|
||||
-- Note that if statements can be broken into multiple lines, in which case this test is not taken
|
||||
if (isLastLineControl) then
|
||||
@@ -304,12 +304,12 @@ end
|
||||
--- Processes one item - a file or a folder
|
||||
local function ProcessItem(a_ItemName)
|
||||
assert(type(a_ItemName) == "string")
|
||||
|
||||
|
||||
-- Skip files / folders that should be ignored
|
||||
if (g_ShouldIgnoreFile[a_ItemName]) then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
local ext = a_ItemName:match("%.([^/%.]-)$")
|
||||
if (g_ShouldProcessExt[ext]) then
|
||||
ProcessFile(a_ItemName)
|
||||
@@ -340,7 +340,7 @@ local CmdLineHandlers =
|
||||
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")
|
||||
@@ -348,7 +348,7 @@ local CmdLineHandlers =
|
||||
table.insert(ToProcess, fnam)
|
||||
end
|
||||
end,
|
||||
|
||||
|
||||
-- "-h" prints help and exits
|
||||
["-h"] = function (a_Args, a_Idx)
|
||||
print([[
|
||||
@@ -368,7 +368,7 @@ 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]
|
||||
@@ -380,7 +380,7 @@ Only .cpp and .h files are ever checked.
|
||||
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
|
||||
@@ -425,7 +425,7 @@ for _, fnam in ipairs(ToProcess) do
|
||||
if (fnam:sub(1, 2) == "./") then
|
||||
fnam = fnam:sub(3)
|
||||
end
|
||||
|
||||
|
||||
ProcessItem(fnam)
|
||||
end
|
||||
|
||||
@@ -440,7 +440,3 @@ if (g_NumViolations > 0) then
|
||||
else
|
||||
os.exit(0)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user