Seconde révision, ajout de la gestion des blocs de commentaires et premières corrections
This commit is contained in:
parent
0d3fc15df6
commit
28f6dfa2aa
@ -27,7 +27,7 @@ def checkFile(path):
|
||||
checkDir(path)
|
||||
else:
|
||||
baseName = os.path.basename(path)
|
||||
if baseName.upper == "AUTHORS":
|
||||
if baseName.upper() == "AUTHORS":
|
||||
if baseName != "AUTHORS":
|
||||
printError(path, "Bad filename")
|
||||
checkAuthors(path)
|
||||
@ -44,6 +44,8 @@ def checkFile(path):
|
||||
checkCFile(path)
|
||||
elif ext == ".h":
|
||||
checkHFile(path)
|
||||
elif ext == ".sh":
|
||||
checkSHFile(path)
|
||||
else:
|
||||
checkOtherFile(path)
|
||||
|
||||
@ -65,47 +67,104 @@ def checkDir(path):
|
||||
checkFile(path + '/' + f)
|
||||
|
||||
def check80cols(path, line, num):
|
||||
if len(line) > 80:
|
||||
if len(line) > 79:
|
||||
printError(path, "80 columns exceeded", num)
|
||||
|
||||
def checkTrailingWhitespace(path, line, num):
|
||||
if len(line) > 1 and line[len(line)-1] == ' ':
|
||||
if len(line) > 1 and (line[len(line)-1] == ' ' or line[len(line)-1] == '\t'):
|
||||
printError(path, "Trailing whitespace", num)
|
||||
|
||||
def checkCComment(path, line, num):
|
||||
txt = line.strip()
|
||||
if re.match("\*/", txt) is not None:
|
||||
if re.match("\*/$", txt) is None:
|
||||
printError(path, "Last big comment lines aren't empty", num)
|
||||
return 0
|
||||
elif re.match("\*/", txt) is not None and \
|
||||
re.match("/\*", txt) is None:
|
||||
printError(path, "\*/ ", num)
|
||||
elif re.match("^\*\* ", txt) is None:
|
||||
printError(path, "Bad intermediary comment lines", num)
|
||||
return 1
|
||||
|
||||
def checkCLang(path, line, num):
|
||||
txt = line.strip()
|
||||
if re.match("^#define", txt) is not None and \
|
||||
re.match("^#define +[A-Z0-9_]+[ \(]", txt) is None:
|
||||
re.match("^#define +[A-Z0-9_]+[ (]?", txt) is None:
|
||||
printError(path, "Constant or macro without full uppercase", num)
|
||||
elif re.match("^struct", txt) is not None and \
|
||||
elif re.match("^ +#", line) is not None:
|
||||
printError(path, "The preprocessor directive mark not on the first column", num)
|
||||
elif re.match(".*sizeof[^ ].*", txt) is not None:
|
||||
printError(path, "Forgotten space after keyword", num)
|
||||
elif re.match("^# *(else|endif)", txt) is not None and \
|
||||
re.match("^# *(else|endif) +/", txt) is None:
|
||||
printError(path, "Preprocesor condition without comment describing the corresponding condition", num)
|
||||
elif re.match("^(typedef +)?struct", txt) is not None and \
|
||||
re.match("^(typedef +)?struct +s_", txt) is None:
|
||||
printError(path, "New struct without s_ name", num)
|
||||
elif re.match("^typedef", txt) is not None and \
|
||||
elif re.match("^(typedef +)?union", txt) is not None and \
|
||||
re.match("^(typedef +)?union +u_", txt) is None:
|
||||
printError(path, "New union without u_ name", num)
|
||||
elif re.match("^(typedef +)?enum", txt) is not None and \
|
||||
re.match("^(typedef +)?enum +e_", txt) is None:
|
||||
printError(path, "New struct without s_ name", num)
|
||||
elif re.match("^typedef *(^(union|struct|enum))", txt) is not None and \
|
||||
re.match("^typedef +(unsigned )?[a-z_\*] +t_", txt) is None:
|
||||
printError(path, "New type without t_ name", num)
|
||||
elif re.match("^(if|else|elseif|for|while|do|typedef|struct|return|sizeof)", txt) is not None and \
|
||||
re.match("^(if|else|elseif|for|while|do|typedef|struct|return|sizeof) ", txt) is None:
|
||||
re.match("^(if|else|elseif|for|while|do|typedef|struct|return|sizeof)(uble| |$)", txt) is None:
|
||||
printError(path, "Forgotten space after keyword", num)
|
||||
elif re.match("^(if|else|elseif|for|while|do|typedef|struct)", txt) is not None and \
|
||||
re.match("^(if|else|elseif|for|while|do|typedef|struct).*{", txt) is None:
|
||||
printError(path, "{ on the same lime of instruction", num)
|
||||
re.match("^(if|else|elseif|for|while|do|typedef|struct).*\{", txt) is not None:
|
||||
printError(path, "{ on the same line of instruction", num)
|
||||
elif re.match("(^/\*|\*/$)", txt) is not None and \
|
||||
re.match("^(/\*|\*/)$", txt) is None:
|
||||
printError(path, "First and last big comment lines aren't empty", num)
|
||||
elif re.match("/\*$", txt) is not None:
|
||||
return 1
|
||||
elif re.match("^for", txt) is not None and \
|
||||
re.match("^for \(.*; .*; .*\)", txt) is None:
|
||||
printError(path, "Bad syntax for a for", num)
|
||||
elif re.match("^return", txt) is not None and \
|
||||
re.match("^return \(.*\)", txt) is None:
|
||||
printError(path, "Bad syntax for return", num)
|
||||
elif re.match(".*=.*;", txt) is not None and \
|
||||
re.match(".* [&%\+\*/-]= .*", txt) is None:
|
||||
elif re.match(".*[^=]=.*;", txt) is not None and \
|
||||
re.match(".* [><]?[-&%+^*/!><|]?= .*", txt) is None:
|
||||
printError(path, "Bad syntax for an affectation", num)
|
||||
elif re.match("\r$", txt) is not None:
|
||||
printError(path, "DOS CR+LF line terminator detected", num)
|
||||
return 0
|
||||
|
||||
def checkHFile(path):
|
||||
checkCFile(path)
|
||||
|
||||
num = 0
|
||||
with open(path, "r") as fp:
|
||||
lines = fp.read().split('\n')
|
||||
#Search for Header protection
|
||||
for line in lines:
|
||||
num += 1
|
||||
line = line.replace(" ", " ")
|
||||
|
||||
|
||||
|
||||
def checkCFile(path):
|
||||
num = 0
|
||||
with open(path, "r") as fp:
|
||||
lines = fp.read().split('\n')
|
||||
typeBlock = 0
|
||||
for line in lines:
|
||||
num += 1
|
||||
line = line.replace(" ", " ")
|
||||
|
||||
check80cols(path, line, num)
|
||||
checkTrailingWhitespace(path, line, num)
|
||||
if typeBlock == 1:
|
||||
typeBlock = checkCComment(path, line, num)
|
||||
else:
|
||||
typeBlock = checkCLang(path, line, num)
|
||||
|
||||
def checkSHFile(path):
|
||||
num = 0
|
||||
with open(path, "r") as fp:
|
||||
lines = fp.read().split('\n')
|
||||
@ -115,7 +174,6 @@ def checkCFile(path):
|
||||
|
||||
check80cols(path, line, num)
|
||||
checkTrailingWhitespace(path, line, num)
|
||||
checkCLang(path, line, num)
|
||||
|
||||
def checkOtherFile(path):
|
||||
num = 0
|
||||
@ -139,7 +197,7 @@ def checkAuthors(path):
|
||||
for line in lines:
|
||||
num += 1
|
||||
checkTrailingWhitespace(path, line, num)
|
||||
if re.match("^\* [a-z0-9-]{1,6}_[a-z0-9-]$", line) is None:
|
||||
if re.match("^(\* [a-z][a-z-]{,5}_[a-z0-9])?$", line) is None:
|
||||
printError(path, "Bad author format", num)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user