Fix minor style issues identified by pylint

Pylint is a static analyzer of Python code.  It seems appropriate
to use a static analyzer to analyze a static analyzer :-).
None of the changes here fix a flaw in flawfinder.
The goal here is to follow PEP 008 more closely in the hope that
the changes make it easier for other developers to improve it further.

Signed-off-by: David A. Wheeler <dwheeler@dwheeler.com>
This commit is contained in:
David A. Wheeler 2017-07-30 16:49:11 -04:00
parent 595f45ad13
commit d06466bd2a
2 changed files with 47 additions and 44 deletions

View File

@ -184,7 +184,7 @@ diff_line_del = re.compile( r'^-[^-].*' )
diff_findjunk = re.compile(r'^(?P<filename>.*)((\s\d\d\d\d+-\d\d-\d\d\s+\d\d:\d[0-9:.]+Z?(\s+[\-\+0-9A-Z]+)?)|(\s[A-Za-z][a-z]+\s[A-za-z][a-z]+\s\d+\s\d+:\d[0-9:.]+Z?(\s[\-\+0-9]*)?\s\d\d\d\d+)|(\s\(.*\)))\s*$')
def is_svn_diff(sLine):
if (sLine.find('Index:') != -1):
if sLine.find('Index:') != -1:
return True
return False
@ -203,7 +203,7 @@ def svn_diff_get_filename(sLine):
def gnu_diff_get_filename(sLine):
newfile_match = diff_newfile.match(sLine)
if (newfile_match):
if newfile_match:
patched_filename = string.strip(newfile_match.group('filename'))
# Clean up filename - remove trailing timestamp and/or (comment).
return diff_findjunk.match(patched_filename)
@ -233,11 +233,11 @@ def load_patch_info(patch_file):
sLine = hPatch.readline()
#Heuristic to determine if it's a svn diff, git diff, or a GNU diff.
if (is_svn_diff(sLine)):
if is_svn_diff(sLine):
fn_get_filename = svn_diff_get_filename
elif (is_git_diff(sLine)):
elif is_git_diff(sLine):
fn_get_filename = git_diff_get_filename
elif (is_gnu_diff(sLine)):
elif is_gnu_diff(sLine):
fn_get_filename = gnu_diff_get_filename
else:
print "Error: Unrecognized patch format"
@ -248,9 +248,9 @@ def load_patch_info(patch_file):
# This is really a sequence of if ... elsif ... elsif..., but
# because Python forbids '=' in conditions, we do it this way.
filename_match = fn_get_filename(sLine)
if (filename_match):
if filename_match:
patched_filename = string.strip(filename_match.group('filename'))
if (patched_file in patch):
if patched_file in patch:
error("filename occurs more than once in the patch: %s" %
patched_filename)
sys.exit(1)
@ -258,15 +258,15 @@ def load_patch_info(patch_file):
patch[patched_filename] = {}
else:
hunk_match = diff_hunk.match(sLine)
if (hunk_match):
if (patched_filename == ""):
if hunk_match:
if patched_filename == "":
error("wrong type of patch file : we have a line number without having seen a filename")
sys.exit(1)
initial_number = hunk_match.group('linenumber')
line_counter = 0
else:
line_added_match = diff_line_added.match(sLine)
if (line_added_match):
if line_added_match:
line_added = line_counter + int(initial_number)
patch[patched_filename][line_added] = True
# Let's also warn about the lines above and below this one,
@ -278,15 +278,14 @@ def load_patch_info(patch_file):
line_counter += 1
else:
line_del_match = diff_line_del.match(sLine)
if (line_del_match == None):
if line_del_match == None:
line_counter += 1
sLine = hPatch.readline()
if (sLine == ''): break # Done reading.
if sLine == '': break # Done reading.
return patch
def htmlize(s):
# Take s, and return legal (UTF-8) HTML.
s1 = string.replace(s, "&", "&amp;")
@ -394,7 +393,8 @@ class Hit:
def show_csv(self):
csv_writer.writerow([self.filename, self.line, self.column, self.level,
self.category, self.name, self.warning,
self.suggestion, self.note, self.cwes(), self.context_text ])
self.suggestion, self.note, self.cwes(),
self.context_text ])
def show(self):
if csv_output:

View File

@ -191,6 +191,7 @@ indent-after-paren=4
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
# tab).
# Flawfinder specific: We use 2-space indents, not 4-space
indent-string=' '
# Maximum number of characters on a single line.
@ -224,7 +225,9 @@ logging-modules=logging
[MISCELLANEOUS]
# List of note tags to take in consideration, separated by a comma.
notes=FIXME,XXX,TODO
# notes=FIXME,XXX,TODO
# Flawfinder specifics: We already note them, no need to report
notes=
[SIMILARITIES]