diff --git a/src/main/java/tech/jhipster/lite/module/domain/JHipsterModule.java b/src/main/java/tech/jhipster/lite/module/domain/JHipsterModule.java index 868add69bfb..527558406ff 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/JHipsterModule.java +++ b/src/main/java/tech/jhipster/lite/module/domain/JHipsterModule.java @@ -256,6 +256,10 @@ public static RegexReplacer regex(String regex) { return regex(notContainingReplacement(), regex); } + public static RegexReplacer regex(Pattern pattern) { + return regex(notContainingReplacement(), pattern); + } + public static RegexReplacer regex(ReplacementCondition condition, String regex) { return new RegexReplacer(condition, regex); } diff --git a/src/main/java/tech/jhipster/lite/module/domain/JHipsterModuleShortcuts.java b/src/main/java/tech/jhipster/lite/module/domain/JHipsterModuleShortcuts.java index 6b99bb3d231..b2e85703600 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/JHipsterModuleShortcuts.java +++ b/src/main/java/tech/jhipster/lite/module/domain/JHipsterModuleShortcuts.java @@ -1,7 +1,6 @@ package tech.jhipster.lite.module.domain; import static tech.jhipster.lite.module.domain.JHipsterModule.*; -import static tech.jhipster.lite.module.domain.replacement.ReplacementCondition.notMatchingRegex; import java.util.regex.Pattern; import tech.jhipster.lite.module.domain.file.JHipsterSource; @@ -22,11 +21,7 @@ final class JHipsterModuleShortcuts { private static final JHipsterProjectFilePath SPRING_TEST_LOG_FILE = path("src/test/resources/logback.xml"); private static final TextNeedleBeforeReplacer JHIPSTER_LOGGER_NEEDLE = lineBeforeText(""); - private static final Pattern MODULE_EXPORT = Pattern.compile("module.exports = \\{"); - private static final Pattern DEFAULT_ES_LINT = Pattern.compile("\\s*'\\*': \\[], //default configuration, replace with your own"); - - private static final ElementReplacer EXISTING_ESLINT_CONFIGURATION = regex(notMatchingRegex(MODULE_EXPORT), MODULE_EXPORT); - private static final ElementReplacer DEFAULT_ES_LINT_CONFIGURATION = regex(notMatchingRegex(DEFAULT_ES_LINT), DEFAULT_ES_LINT); + private static final Pattern DEFAULT_LINTSTAGED_CONFIGURATION_ENTRY = Pattern.compile("\\s*'\\*': \\[\\s+].*"); private final JHipsterModuleBuilder builder; @@ -104,16 +99,13 @@ public void preCommitActions(StagedFilesFilter stagedFilesFilter, PreCommitComma Assert.notNull("stagedFilesFilter", stagedFilesFilter); Assert.notNull("preCommitCommands", preCommitCommands); - String esLintReplacement = - "module.exports = \\{" + - LINE_BREAK + - builder.properties().indentation().times(1) + - "'%s': %s,".formatted(stagedFilesFilter.get(), preCommitCommands.get()); + String newLintStagedConfigurationEntry = + "%s'%s': %s,".formatted(builder.properties().indentation().times(1), stagedFilesFilter, preCommitCommands); builder .optionalReplacements() .in(path(".lintstagedrc.cjs")) - .add(DEFAULT_ES_LINT_CONFIGURATION, "") - .add(EXISTING_ESLINT_CONFIGURATION, esLintReplacement); + .add(regex(DEFAULT_LINTSTAGED_CONFIGURATION_ENTRY), "") + .add(lineAfterRegex("module.exports = \\{"), newLintStagedConfigurationEntry); } } diff --git a/src/main/java/tech/jhipster/lite/module/domain/PreCommitCommands.java b/src/main/java/tech/jhipster/lite/module/domain/PreCommitCommands.java index d19e4bbeb21..aaea55a48ce 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/PreCommitCommands.java +++ b/src/main/java/tech/jhipster/lite/module/domain/PreCommitCommands.java @@ -37,4 +37,9 @@ private static String withQuotes(String command) { public String get() { return commands; } + + @Override + public String toString() { + return commands; + } } diff --git a/src/main/java/tech/jhipster/lite/module/domain/StagedFilesFilter.java b/src/main/java/tech/jhipster/lite/module/domain/StagedFilesFilter.java index ad1fb2399f2..2be608b2bb8 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/StagedFilesFilter.java +++ b/src/main/java/tech/jhipster/lite/module/domain/StagedFilesFilter.java @@ -10,4 +10,9 @@ public record StagedFilesFilter(String filter) { public String get() { return filter(); } + + @Override + public String toString() { + return filter; + } }