Reduce false positives with verify-flag-underscore.sh by updating regex

Check to make sure there is not an alphanumeric character immeditely
before or after the 'flag'.  It there is an alphanumeric character then
this is obviously not actually the flag we care about.  For example if
the project declares a flag "valid-name" but the regex finds something
like "invalid_name" we should not match.  Clearly this "invalid_name" is
not actually a wrong usage of the "valid-name" flag.
This commit is contained in:
Eric Paris
2015-08-13 19:52:01 -04:00
parent ea59172874
commit 30d34d0e59
6 changed files with 13 additions and 191 deletions

View File

@@ -96,11 +96,10 @@ def normalize_files(rootdir, files):
return newfiles
def line_has_bad_flag(line, flagre):
m = flagre.search(line)
if not m:
return False
if "_" in m.group(0):
return True
results = flagre.findall(line)
for result in results:
if "_" in result:
return True
return False
# The list of files might not be the whole repo. If someone only changed a
@@ -155,7 +154,7 @@ def flags_to_re(flags):
for flag in flags:
# turn all flag names into regexs which will find both types
newre = dashRE.sub('[-_]', flag)
flagREs.append(newre)
flagREs.append("[^\w]" + newre + "[^\w]")
# turn that list of regex strings into a single large RE
flagRE = "|".join(flagREs)
flagRE = re.compile(flagRE)