Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove redundant character escape in RegExp #10636

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,21 @@ public class AngularOauth2ModuleFactory {
},
""";

private static final Pattern EMPTY_ALLOWED_COMMON_DEPENDENCIES_PATTERN = Pattern.compile(
"(\"allowedCommonJsDependencies\": *\\[\\s*)\\]"
);
private static final Pattern EMPTY_ALLOWED_COMMON_DEPENDENCIES_PATTERN = Pattern.compile("(\"allowedCommonJsDependencies\": *\\[\\s*)]");
private static final ElementReplacer EMPTY_ALLOWED_COMMON_DEPENDENCIES_NEEDLE = new RegexReplacer(
(contentBeforeReplacement, replacement) -> EMPTY_ALLOWED_COMMON_DEPENDENCIES_PATTERN.matcher(contentBeforeReplacement).find(),
EMPTY_ALLOWED_COMMON_DEPENDENCIES_PATTERN
);

private static final Pattern FILLED_ALLOWED_COMMON_DEPENDENCIES_PATTERN = Pattern.compile(
"(\"allowedCommonJsDependencies\": *\\[[^]]+)\\]"
"(\"allowedCommonJsDependencies\": *\\[[^]]+)]"
);
private static final ElementReplacer FILLED_ALLOWED_COMMON_DEPENDENCIES_NEEDLE = new RegexReplacer(
(contentBeforeReplacement, replacement) -> FILLED_ALLOWED_COMMON_DEPENDENCIES_PATTERN.matcher(contentBeforeReplacement).find(),
FILLED_ALLOWED_COMMON_DEPENDENCIES_PATTERN
);

private static final Pattern FILLED_STANDALONE_PATTERN = Pattern.compile("(imports: *\\[[^]]+)\\]");
private static final Pattern FILLED_STANDALONE_PATTERN = Pattern.compile("(imports: *\\[[^]]+)]");
private static final ElementReplacer FILLED_STANDALONE_NEEDLE = new RegexReplacer(
(contentBeforeReplacement, replacement) -> FILLED_STANDALONE_PATTERN.matcher(contentBeforeReplacement).find(),
FILLED_STANDALONE_PATTERN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ public class CypressModuleFactory {
private static final String EXCLUDE_KEY = "\"exclude\"";
private static final RegexReplacer NEW_EXCLUSION_REPLACER = new RegexReplacer(
(currentContent, replacement) -> !currentContent.contains(EXCLUDE_KEY),
Pattern.compile("\\n.*\\}\\s*$")
Pattern.compile("\\n.*}\\s*$")
);

private static final RegexReplacer EXISTING_EXCLUSION_REPLACER = new RegexReplacer(
(currentContent, replacement) -> currentContent.contains(EXCLUDE_KEY) && !currentContent.contains(CYPRESS_EXCLUSION),
Pattern.compile("(" + EXCLUDE_KEY + "\\s*:\\s*\\[[^\\]]+)\\]")
Pattern.compile("(" + EXCLUDE_KEY + "\\s*:\\s*\\[[^]]+)]")
);

private static final RegexReplacer EMPTY_EXCLUSION_REPLACER = new RegexReplacer(
(currentContent, replacement) -> currentContent.contains(EXCLUDE_KEY) && !currentContent.contains(CYPRESS_EXCLUSION),
Pattern.compile("(" + EXCLUDE_KEY + "\\s*:\\s*\\[\\s*)\\]")
Pattern.compile("(" + EXCLUDE_KEY + "\\s*:\\s*\\[\\s*)]")
);

public JHipsterModule buildModule(JHipsterModuleProperties properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private Tag buildTag(Object value) {
}

private static List<String> extractKeysParts(PropertyKey key) {
return Arrays.stream(key.get().split("\\.(?![^'\\[]*\\])")).map(subKey -> subKey.replace("'[", "[").replace("]'", "]")).toList();
return Arrays.stream(key.get().split("\\.(?![^'\\[]*])")).map(subKey -> subKey.replace("'[", "[").replace("]'", "]")).toList();
}

private MappingNode loadConfiguration(File yamlFile) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class MavenDependenciesReader implements JavaDependenciesReader {

private static final String CURRENT_VERSIONS_FILE = "/generator/dependencies/pom.xml";
private static final Pattern VERSIONS_PATTERN = Pattern.compile("<([^>]+)\\.version>([^>]+)<\\/");
private static final Pattern VERSIONS_PATTERN = Pattern.compile("<([^>]+)\\.version>([^>]+)</");

private final ProjectFiles files;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
@Order
class FileSystemNpmVersionReader implements NpmVersionsReader {

private static final Pattern DEV_DEPENDENCIES_PATTERN = Pattern.compile("\"devDependencies\"\\s*:\\s*\\{([^}]*)\\}", Pattern.DOTALL);
private static final Pattern DEPENDENCIES_PATTERN = Pattern.compile("\"dependencies\"\\s*:\\s*\\{([^}]*)\\}", Pattern.DOTALL);
private static final Pattern DEV_DEPENDENCIES_PATTERN = Pattern.compile("\"devDependencies\"\\s*:\\s*\\{([^}]*)}", Pattern.DOTALL);
private static final Pattern DEPENDENCIES_PATTERN = Pattern.compile("\"dependencies\"\\s*:\\s*\\{([^}]*)}", Pattern.DOTALL);
private static final Pattern PACKAGES_PATTERN = Pattern.compile("\"([^\"]+)\"\\s*:\\s*\"([^\"]+)\"", Pattern.DOTALL);

private final ProjectFiles projectFiles;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/tech/jhipster/lite/HexagonalArchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private static Collection<String> packagesWithAnnotation(Class<? extends Annotat
return Files.walk(rootPackagePath())
.filter(path -> path.toString().endsWith("package-info.java"))
.map(toPackageName())
.map(path -> path.replaceAll("[\\/]", "."))
.map(path -> path.replaceAll("[/]", "."))
.map(path -> path.replaceAll("[\\\\]", "."))
.map(path -> path.replace("src.main.java.", ""))
.map(toPackage())
Expand Down