Skip to content

Commit

Permalink
reduce sensitivity of regex check
Browse files Browse the repository at this point in the history
  • Loading branch information
Luro02 committed Apr 6, 2024
1 parent 49e6adb commit 98e6726
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

@ExecutableCheck(reportedProblems = {ProblemType.COMPLEX_REGEX})
public class RegexCheck extends IntegratedCheck {
private static final double MAX_ALLOWED_SCORE = 12.0;
private static final double MAX_ALLOWED_SCORE = 24.0;
private static final List<String> REGEX_HINTS = List.of("?", "<", ">", "+", "*", "[", "]", "$", "^", "|", "\\");
private static final int MIN_REGEX_HINTS = 2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

public class Test {
private String noRegex = "Should we do this? I guess we shouldn't! f*ck you!";
private String regex1 = "(foo)* [bar]+ x? x?"; /*# not ok #*/
private String regex2 = "(?<g1>foo)"; /*# not ok #*/
private String regex1 = "(foo)* [bar]+ x? x?"; /*# ok #*/
private String regex2 = "(?<g1>foo)"; /*# ok #*/
private String regex3 = "^[a-z]+(?: \\S+)?$"; /*# not ok #*/
private String regex4 = "^(?<start>\\d+)-->(?<end>\\d+):(?<length>\\d+)m,(?<type>\\d+)x,(?<velocity>\\d+)max$"; /*# not ok #*/
private String regex5 = "^(?<identifier>\\d+),(?<street>\\d+),(?<velocity>\\d+),(?<acceleration>\\d+)$"; /*# not ok #*/
Expand Down Expand Up @@ -43,14 +43,14 @@ private void foo() {

// test that context of regex is considered
class RegexContext {
private static final String DEFINITELY_REGEX_1 = "(foo)* [bar]+ x? x?"; /*# not ok #*/
private static final String DEFINITELY_REGEX_2 = "(foo)* [bar]+ x? x?"; /*# not ok #*/
private static final String DEFINITELY_REGEX_3 = "(foo)* [bar]+ x? x?"; /*# not ok #*/
private static final String DEFINITELY_REGEX_4 = "(foo)* [bar]+ x? x?"; /*# not ok #*/
private static final String DEFINITELY_REGEX_5 = "(foo)* [bar]+ x? x?"; /*# not ok #*/
private static final String DEFINITELY_REGEX_6 = "(foo)* [bar]+ x? x?"; /*# not ok #*/
private static final String UNUSED_REGEX = "(foo)* [bar]+ x? x?"; /*# ok #*/
private static final String NOT_USED_AS_REGEX = "(foo)* [bar]+ x? x?"; /*# ok #*/
private static final String DEFINITELY_REGEX_1 = "^[a-z]+(?: \\S+)?$"; /*# not ok #*/
private static final String DEFINITELY_REGEX_2 = "^[a-z]+(?: \\S+)?$"; /*# not ok #*/
private static final String DEFINITELY_REGEX_3 = "^[a-z]+(?: \\S+)?$"; /*# not ok #*/
private static final String DEFINITELY_REGEX_4 = "^[a-z]+(?: \\S+)?$"; /*# not ok #*/
private static final String DEFINITELY_REGEX_5 = "^[a-z]+(?: \\S+)?$"; /*# not ok #*/
private static final String DEFINITELY_REGEX_6 = "^[a-z]+(?: \\S+)?$"; /*# not ok #*/
private static final String UNUSED_REGEX = "^[a-z]+(?: \\S+)?$"; /*# ok #*/
private static final String NOT_USED_AS_REGEX = "^[a-z]+(?: \\S+)?$"; /*# ok #*/

private static final Pattern SYMBOL_REGEX = Pattern.compile("[0-9a-zA-Z]*"); /*# ok #*/

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
complexity.RegexCheck
Complex regex
Test.java:7
Test.java:8
Test.java:9
Test.java:10
Test.java:11
Expand Down

0 comments on commit 98e6726

Please sign in to comment.