|
| 1 | +import re |
| 2 | + |
| 3 | + |
| 4 | +def non_compliant(input): |
| 5 | + re.match(r"<.+?>", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[^>]++".}} |
| 6 | + re.match(r"<\S+?>", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[^>\s]++".}} |
| 7 | + re.match(r"<\D+?>", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[^>\d]++".}} |
| 8 | + re.match(r"<\W+?>", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[^>\w]++".}} |
| 9 | + |
| 10 | + re.match(r"<.{2,5}?>", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[^>]{2,5}+".}} |
| 11 | + re.match(r"<\S{2,5}?>", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[^>\s]{2,5}+".}} |
| 12 | + re.match(r"<\D{2,5}?>", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[^>\d]{2,5}+".}} |
| 13 | + re.match(r"<\W{2,5}?>", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[^>\w]{2,5}+".}} |
| 14 | + |
| 15 | + re.match(r"<.{2,}?>", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[^>]{2,}+".}} |
| 16 | + re.match(r"\".*?\"", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[^\"]*+".}} |
| 17 | + re.match(r".*?\w", input) # Noncompliant {{Replace this use of a reluctant quantifier with "\W*+".}} |
| 18 | + re.match(r".*?\W", input) # Noncompliant {{Replace this use of a reluctant quantifier with "\w*+".}} |
| 19 | + re.match(r".*?\p{L}", input) # Noncompliant {{Replace this use of a reluctant quantifier with "\P{L}*+".}} |
| 20 | + re.match(r".*?\P{L}", input) # Noncompliant {{Replace this use of a reluctant quantifier with "\p{L}*+".}} |
| 21 | + re.match(r"\[.*?\]", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[^\]]*+".}} |
| 22 | + re.match(r".+?[abc]", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[^abc]++".}} |
| 23 | + re.match(r"(?-U:\s)*?\S", input) |
| 24 | + re.match(r"(?U:\s)*?\S", input, re.ASCII) # Noncompliant {{Replace this use of a reluctant quantifier with "[\s\S]*+".}} |
| 25 | + re.match(r"(?U:a|\s)*?\S", input) |
| 26 | + re.match(r"\S*?\s", input) |
| 27 | + re.match(r"\S*?(?-U:\s)", input) |
| 28 | + re.match(r"\S*?(?U:\s)", input, re.ASCII) # Noncompliant {{Replace this use of a reluctant quantifier with "[\S\s]*+".}} |
| 29 | + re.match(r"\S*?(?U)\s", input, re.ASCII) # Noncompliant {{Replace this use of a reluctant quantifier with "[\S\s]*+".}} |
| 30 | + |
| 31 | + # coverage |
| 32 | + re.match(r"(?:(?m))*?a", input) |
| 33 | + re.match(r"(?:(?m:.))*?(?:(?m))", input) |
| 34 | + |
| 35 | + # This replacement might not be equivalent in case of full match, but is equivalent in case of split |
| 36 | + re.match(r".+?[^abc]", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[abc]++".}} |
| 37 | + |
| 38 | + re.match(r".+?\x{1F4A9}", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[^\x{1F4A9}]++".}} |
| 39 | + re.match(r"<abc.*?>", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[^>]*+".}} |
| 40 | + re.match(r"<.+?>|otherstuff", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[^>]++".}} |
| 41 | + re.match(r"(<.+?>)*", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[^>]++".}} |
| 42 | + |
| 43 | + re.match(r"\S+?[abc]", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[^abc\s]++".}} |
| 44 | + re.match(r"\D+?[abc]", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[^abc\d]++".}} |
| 45 | + re.match(r"\w+?[abc]", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[^abc\W]++".}} |
| 46 | + |
| 47 | + re.match(r"\S*?[abc]", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[^abc\s]*+".}} |
| 48 | + re.match(r"\D*?[abc]", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[^abc\d]*+".}} |
| 49 | + re.match(r"\w*?[abc]", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[^abc\W]*+".}} |
| 50 | + |
| 51 | + re.match(r"\S+?[^abc]", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[abc\S]++".}} |
| 52 | + re.match(r"\s+?[^abc]", input) # Noncompliant {{Replace this use of a reluctant quantifier with "[abc\s]++".}} |
| 53 | + |
| 54 | + |
| 55 | +def compliant(input): |
| 56 | + re.match(r"<[^>]++>", input) |
| 57 | + re.match(r"<[^>]+>", input) |
| 58 | + re.match(r"<[^>]+?>", input) |
| 59 | + re.match(r"<.{42}?>", input) # Adding a ? to a fixed quantifier is pointless, but also doesn't cause any backtracking issues |
| 60 | + re.match(r"<.+>", input) |
| 61 | + re.match(r"<.++>", input) |
| 62 | + re.match(r"<--.?-->", input) |
| 63 | + re.match(r"<--.+?-->", input) |
| 64 | + re.match(r"<--.*?-->", input) |
| 65 | + re.match(r"/\*.?\*/", input) |
| 66 | + re.match(r"<[^>]+>?", input) |
| 67 | + re.match(r"", input) |
| 68 | + re.match(r".*?(?:a|b|c)", input) # Alternatives are currently not covered even if they contain only single characters |
| 69 | + |
| 70 | + # UNICODE flag is enabled by default |
| 71 | + re.match(r"(?U:\s)*?\S", input) |
| 72 | + re.match(r"\S*?(?U:\s)", input) |
| 73 | + re.match(r"\S*?(?U)\s", input) |
| 74 | + |
| 75 | +def no_intersection(input): |
| 76 | + re.match(r"<\d+?>", input) |
| 77 | + re.match(r"<\s+?>", input) |
| 78 | + re.match(r"<\w+?>", input) |
| 79 | + |
| 80 | + re.match(r"<\s{2,5}?>", input) |
| 81 | + re.match(r"<\d{2,5}?>", input) |
| 82 | + re.match(r"<\w{2,5}?>", input) |
| 83 | + |
| 84 | + re.match(r"\d+?[abc]", input) |
| 85 | + re.match(r"\s+?[abc]", input) |
| 86 | + re.match(r"\W+?[abc]", input) |
| 87 | + |
| 88 | + re.match(r"\W*?[abc]", input) |
| 89 | + re.match(r"\s*?[abc]", input) |
| 90 | + re.match(r"\d*?[abc]", input) |
0 commit comments