misra: fix misra-3_1 false positive for URIs in block comments (#4939)
* misra: fix misra-3_1 false positive for URIs in block comments * added unit test, improved new misra 3.1 based on false positives --------- Co-authored-by: Paul B <unconfigured@null.spigotmc.org>
This commit is contained in:
parent
12118d8d67
commit
30ff1aad9a
|
@ -1543,10 +1543,19 @@ class MisraChecker:
|
|||
def misra_3_1(self, rawTokens):
|
||||
for token in rawTokens:
|
||||
starts_with_double_slash = token.str.startswith('//')
|
||||
if token.str.startswith('/*') or starts_with_double_slash:
|
||||
starts_with_block_comment = token.str.startswith("/*")
|
||||
s = token.str.lstrip('/')
|
||||
if ((not starts_with_double_slash) and '//' in s) or '/*' in s:
|
||||
if (starts_with_double_slash or starts_with_block_comment) and "/*" in s:
|
||||
# Block comment inside of regular comment, violation
|
||||
self.reportError(token, 3, 1)
|
||||
elif starts_with_block_comment and "//" in s:
|
||||
# "//" in block comment, check if it's a uri
|
||||
while "//" in s:
|
||||
possible_uri, s = s.split("//", 1)
|
||||
if not re.search(r"\w+:$", possible_uri):
|
||||
# Violation if no uri was found
|
||||
self.reportError(token, 3, 1)
|
||||
break
|
||||
|
||||
def misra_3_2(self, rawTokens):
|
||||
for token in rawTokens:
|
||||
|
|
|
@ -82,6 +82,7 @@ static void misra_2_2(int x) {
|
|||
/* // */ // 3.1
|
||||
/* /* */ // 3.1
|
||||
////
|
||||
/* https://cppcheck.net */
|
||||
|
||||
// http://example.com // no warning
|
||||
|
||||
|
|
Loading…
Reference in New Issue