1
1
package tech .jhipster .lite .module .domain ;
2
2
3
3
import static tech .jhipster .lite .module .domain .JHipsterModule .*;
4
- import static tech .jhipster .lite .module .domain .replacement .ReplacementCondition .notMatchingRegex ;
4
+ import static tech .jhipster .lite .module .domain .replacement .ReplacementCondition .always ;
5
5
6
6
import java .util .regex .Pattern ;
7
7
import tech .jhipster .lite .module .domain .file .JHipsterSource ;
@@ -22,11 +22,7 @@ final class JHipsterModuleShortcuts {
22
22
private static final JHipsterProjectFilePath SPRING_TEST_LOG_FILE = path ("src/test/resources/logback.xml" );
23
23
private static final TextNeedleBeforeReplacer JHIPSTER_LOGGER_NEEDLE = lineBeforeText ("<!-- jhipster-needle-logback-add-log -->" );
24
24
25
- private static final Pattern MODULE_EXPORT = Pattern .compile ("module.exports = \\ {" );
26
- private static final Pattern DEFAULT_ES_LINT = Pattern .compile ("\\ s*'\\ *': \\ [], //default configuration, replace with your own" );
27
-
28
- private static final ElementReplacer EXISTING_ESLINT_CONFIGURATION = regex (notMatchingRegex (MODULE_EXPORT ), MODULE_EXPORT );
29
- private static final ElementReplacer DEFAULT_ES_LINT_CONFIGURATION = regex (notMatchingRegex (DEFAULT_ES_LINT ), DEFAULT_ES_LINT );
25
+ private static final Pattern DEFAULT_LINTSTAGED_CONFIGURATION_ENTRY = Pattern .compile ("\\ s*'\\ *': \\ [\\ s*].*" );
30
26
31
27
private final JHipsterModuleBuilder builder ;
32
28
@@ -104,16 +100,13 @@ public void preCommitActions(StagedFilesFilter stagedFilesFilter, PreCommitComma
104
100
Assert .notNull ("stagedFilesFilter" , stagedFilesFilter );
105
101
Assert .notNull ("preCommitCommands" , preCommitCommands );
106
102
107
- String esLintReplacement =
108
- "module.exports = \\ {" +
109
- LINE_BREAK +
110
- builder .properties ().indentation ().times (1 ) +
111
- "'%s': %s," .formatted (stagedFilesFilter .get (), preCommitCommands .get ());
103
+ String newLintStagedConfigurationEntry =
104
+ "%s'%s': %s," .formatted (builder .properties ().indentation ().times (1 ), stagedFilesFilter , preCommitCommands );
112
105
113
106
builder
114
107
.optionalReplacements ()
115
108
.in (path (".lintstagedrc.cjs" ))
116
- .add (DEFAULT_ES_LINT_CONFIGURATION , "" )
117
- .add (EXISTING_ESLINT_CONFIGURATION , esLintReplacement );
109
+ .add (regex ( always (), DEFAULT_LINTSTAGED_CONFIGURATION_ENTRY ) , "" )
110
+ .add (lineAfterRegex ( "module.exports = \\ {" ), newLintStagedConfigurationEntry );
118
111
}
119
112
}
0 commit comments