Skip to content

Commit

Permalink
feat(vue): patch eslint config file from typescript module rather tha…
Browse files Browse the repository at this point in the history
…n overwriting it
  • Loading branch information
murdos committed Sep 15, 2024
1 parent df4f8f6 commit b52e17c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public JHipsterModule buildVueModule(JHipsterModuleProperties properties) {
.addScript(scriptKey("watch:tsc"), scriptCommand("npm run build:tsc -- --watch"))
.and()
.files()
.add(SOURCE.template("eslint.config.js.mustache"), to("eslint.config.js"))
.add(SOURCE.file("tsconfig.build.json"), to("tsconfig.build.json"))
.batch(SOURCE, to("."))
.addTemplate("vite.config.ts")
Expand Down Expand Up @@ -97,12 +96,44 @@ public JHipsterModule buildVueModule(JHipsterModuleProperties properties) {
.add(APP_SOURCE.template("test/webapp/unit/shared/http/infrastructure/secondary/AxiosStub.ts.mustache"), TEST_DESTINATION.append("unit/shared/http/infrastructure/secondary/AxiosStub.ts"))
.add(APP_SOURCE.template("test/webapp/unit/router/infrastructure/primary/HomeRouter.spec.ts.mustache"), TEST_DESTINATION.append("unit/router/infrastructure/primary/HomeRouter.spec.ts"))
.and()
.apply(patchEslintConfig(properties))
.apply(patchTsConfig(properties))
.apply(patchVitestConfig(properties))
.build();
//@formatter:on
}

private Consumer<JHipsterModuleBuilder> patchEslintConfig(JHipsterModuleProperties properties) {
String vuePluginConfig =
"""
\t...vue.configs['flat/recommended'],
\t{
\t\tfiles: ['**/*.vue'],
\t\tlanguageOptions: {
\t\t\tparserOptions: { parser: '@typescript-eslint/parser' },
\t\t\tglobals: { ...globals.browser },
\t\t},
\t},\
""".replace("\t", properties.indentation().spaces());
//@formatter:off
return moduleBuilder -> moduleBuilder
.mandatoryReplacements()
.in(path("eslint.config.js"))
.add(lineAfterRegex("from 'typescript-eslint'"), "import vue from 'eslint-plugin-vue';")
.add(lineAfterRegex("...typescript.configs.recommended"), vuePluginConfig)
.add(text("files: ['src/*/webapp/**/*.ts']"), "files: ['src/*/webapp/**/*.vue', 'src/*/webapp/**/*.ts']")
.add(eslintTypescriptVueRule("'vue/html-self-closing': 'off',", properties.indentation()))
.add(eslintTypescriptVueRule("'@typescript-eslint/no-explicit-any': 'off',", properties.indentation()))
.add(eslintTypescriptVueRule("'@typescript-eslint/no-empty-object-type': 'off',", properties.indentation()))
.and()
.and();
//@formatter:on
}

private static MandatoryReplacer eslintTypescriptVueRule(String rule, Indentation indentation) {
return new MandatoryReplacer(lineAfterRegex("quotes: \\['error', 'single'"), indentation.times(3) + rule);
}

private Consumer<JHipsterModuleBuilder> patchTsConfig(JHipsterModuleProperties properties) {
//@formatter:off
return moduleBuilder -> moduleBuilder
Expand Down
39 changes: 0 additions & 39 deletions src/main/resources/generator/client/vue/eslint.config.js.mustache

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void shouldCreateVueModule() {
JHipsterModule module = factory.buildVueModule(properties);

//@formatter:off
assertThatModuleWithFiles(module, packageJsonFile(), lintStagedConfigFile(), tsConfigFile(), vitestConfigFile())
assertThatModuleWithFiles(module, packageJsonFile(), lintStagedConfigFile(), tsConfigFile(), vitestConfigFile(), eslintConfigFile())
.hasFiles("documentation/vue.md")
.hasFile("package.json")
.notContaining(nodeDependency("@tsconfig/recommended"))
Expand Down Expand Up @@ -81,6 +81,28 @@ void shouldCreateVueModule() {
"""
)
.and()
.hasFile("eslint.config.js")
.containing("import vue from 'eslint-plugin-vue';")
.containing("""
...vue.configs['flat/recommended'],
{
files: ['**/*.vue'],
languageOptions: {
parserOptions: { parser: '@typescript-eslint/parser' },
globals: { ...globals.browser },
},
},
"""
)
.containing("""
rules: {
quotes: ['error', 'single', { avoidEscape: true }],
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'vue/html-self-closing': 'off',
"""
)
.and()
.hasFiles("src/main/webapp/app/shared/http/infrastructure/secondary/AxiosHttp.ts")
.hasFiles("src/main/webapp/index.html")
.hasPrefixedFiles("src/main/webapp/app", "env.d.ts", "AppVue.vue", "injections.ts", "router.ts", "main.ts")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public static ModuleFile vitestConfigFile() {
return file("src/main/resources/generator/typescript/vitest.config.ts.mustache", "vitest.config.ts");
}

public static ModuleFile eslintConfigFile() {
return file("src/main/resources/generator/typescript/eslint.config.js.mustache", "eslint.config.js");
}

public static ModuleFile emptyLintStagedConfigFile() {
return file("src/test/resources/projects/init/.lintstagedrc.empty.cjs", ".lintstagedrc.cjs");
}
Expand Down

0 comments on commit b52e17c

Please sign in to comment.