Skip to content

Commit

Permalink
Merge pull request #26794 from mshima/vue-eslint
Browse files Browse the repository at this point in the history
migrate vue eslint to flat config
  • Loading branch information
DanielFran authored Jul 25, 2024
2 parents c572427 + 701435d commit 09c885c
Show file tree
Hide file tree
Showing 21 changed files with 155 additions and 171 deletions.
4 changes: 0 additions & 4 deletions generators/client/files-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ export const files = {
{
templates: ['README.md.jhi.client', '.prettierignore.jhi.client'],
},
clientRootTemplatesBlock({
condition: ctx => !ctx.clientFrameworkReact && !ctx.clientFrameworkAngular,
templates: ['.eslintignore'],
}),
clientRootTemplatesBlock({
condition: generator => generator.microfrontend && (generator.clientFrameworkVue || generator.clientFrameworkReact),
templates: ['webpack/webpack.microfrontend.js.jhi'],
Expand Down
32 changes: 0 additions & 32 deletions generators/client/templates/.eslintignore.ejs

This file was deleted.

4 changes: 2 additions & 2 deletions generators/cypress/templates/eslint.config.js.jhi.cypress.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import cypress from 'eslint-plugin-cypress/flat';
<&_ } -&>
<&_ if (fragment.configSection) { -&>
{
files: ['<%- this.relativeDir(clientRootDir, cypressDir) %>**/*.cy.ts'],
files: ['<%- this.relativeDir(clientRootDir, cypressDir) %>**/*.ts'],
extends: [...tseslint.configs.recommendedTypeChecked, cypress.configs.recommended],
languageOptions: {
parserOptions: {
Expand All @@ -34,8 +34,8 @@ import cypress from 'eslint-plugin-cypress/flat';
'@typescript-eslint/no-unsafe-assignment': 'warn',
'@typescript-eslint/no-unsafe-call': 'warn',
'@typescript-eslint/no-unsafe-member-access': 'warn',
'@typescript-eslint/unbound-method': 'warn',
'@typescript-eslint/no-unused-vars': 'warn',
'@typescript-eslint/unbound-method': 'warn',
},
},
<&_ } -&>
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { existsSync, mkdirSync, writeFileSync } from 'fs';
import { lighthouse, pa11y, prepareAudit } from 'cypress-audit';
<%_ } _%>

export default async (on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions) => {
export default <% if (cypressCoverage) { %>async <% } %>(on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions) => {
on('before:browser:launch', (browser, launchOptions) => {
<%_ if (cypressAudit) { _%>
prepareAudit(launchOptions);
Expand All @@ -60,7 +60,9 @@ export default async (on: Cypress.PluginEvents, config: Cypress.PluginConfigOpti
on('task', {
lighthouse: lighthouse(async (lighthouseReport) => {
const { default: ReportGenerator } = await import('lighthouse/report/generator/report-generator');
!existsSync('<%= cypressTemporaryDir %>') && mkdirSync('<%= cypressTemporaryDir %>', { recursive: true });
if (!existsSync('<%= cypressTemporaryDir %>')) {
mkdirSync('<%= cypressTemporaryDir %>', { recursive: true });
}
writeFileSync('<%= cypressTemporaryDir %>lhreport.html', ReportGenerator.generateReport(lighthouseReport.lhr, 'html'));
}),
pa11y: pa11y(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-namespace */
export type Account = Record<string, string | boolean | number>;

Cypress.Commands.add('getAccount', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
-%>
/* eslint-disable @typescript-eslint/no-namespace */
/* eslint-disable @typescript-eslint/no-use-before-define */
/* eslint-disable @typescript-eslint/no-unsafe-return */

Cypress.Commands.add('getManagementInfo', () => {
return cy.request({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
/* eslint-disable @typescript-eslint/no-namespace */
// eslint-disable-next-line spaced-comment
/// <reference types="cypress" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ exports[`generator - javascript:eslint with defaults options should match files
"eslint.config.mjs": {
"contents": "import globals from 'globals';
import prettier from 'eslint-plugin-prettier/recommended';
// jhipster-needle-eslint-add-import - JHipster will add additional import here
export default [
Expand All @@ -21,7 +20,6 @@ export default [
},
},
},
// jhipster-needle-eslint-add-config - JHipster will add additional config here
prettier,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
fragments.registerSections({
importsSection: 0,
configSection: 0,
endConfigSection: 0,
});
_&>
<%_ if (typescriptEslint) { _%>
Expand All @@ -32,7 +33,7 @@ import prettier from 'eslint-plugin-prettier/recommended';
<%_ if (typescriptEslint) { _%>
import tseslint from 'typescript-eslint';
<%_ } _%>
<&- fragments.importsSection() &>
<&- fragments.importsSection() -&>
// jhipster-needle-eslint-add-import - JHipster will add additional import here

<%_ if (typescriptEslint) { _%>
Expand All @@ -47,9 +48,10 @@ export default [
},
},
},
<&- fragments.configSection() &>
<&- fragments.configSection() -&>
// jhipster-needle-eslint-add-config - JHipster will add additional config here
prettier,
<&- fragments.endConfigSection() -&>
<%_ if (typescriptEslint) { _%>
);
<%_ } else { _%>
Expand Down
57 changes: 18 additions & 39 deletions generators/vue/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ exports[`generator - vue gateway-jwt-skipUserManagement(true)-withAdminUi(false)
".yo-rc.json": {
"stateCleared": "modified",
},
"clientRoot/.eslintignore": {
"clientRoot/.postcssrc.js": {
"stateCleared": "modified",
},
"clientRoot/.eslintrc.cjs": {
"stateCleared": "modified",
},
"clientRoot/.postcssrc.js": {
"clientRoot/eslint.config.mjs": {
"stateCleared": "modified",
},
"clientRoot/package.json": {
Expand Down Expand Up @@ -472,13 +469,10 @@ exports[`generator - vue gateway-oauth2-withAdminUi(true)-skipJhipsterDependenci
".yo-rc.json": {
"stateCleared": "modified",
},
"clientRoot/.eslintignore": {
"stateCleared": "modified",
},
"clientRoot/.eslintrc.cjs": {
"clientRoot/.postcssrc.js": {
"stateCleared": "modified",
},
"clientRoot/.postcssrc.js": {
"clientRoot/eslint.config.mjs": {
"stateCleared": "modified",
},
"clientRoot/package.json": {
Expand Down Expand Up @@ -999,13 +993,10 @@ exports[`generator - vue microservice-jwt-skipUserManagement(false)-withAdminUi(
".yo-rc.json": {
"stateCleared": "modified",
},
"clientRoot/.eslintignore": {
"stateCleared": "modified",
},
"clientRoot/.eslintrc.cjs": {
"clientRoot/.postcssrc.js": {
"stateCleared": "modified",
},
"clientRoot/.postcssrc.js": {
"clientRoot/eslint.config.mjs": {
"stateCleared": "modified",
},
"clientRoot/package.json": {
Expand Down Expand Up @@ -1463,12 +1454,6 @@ exports[`generator - vue microservice-jwt-skipUserManagement(false)-withAdminUi(

exports[`generator - vue microservice-oauth2-withAdminUi(true)-skipJhipsterDependencies(true)-enableTranslation(true)--websocket(false) should match generated files snapshot 1`] = `
{
".eslintignore": {
"stateCleared": "modified",
},
".eslintrc.cjs": {
"stateCleared": "modified",
},
".jhipster/EntityWithCustomId.json": {
"stateCleared": "modified",
},
Expand All @@ -1487,6 +1472,9 @@ exports[`generator - vue microservice-oauth2-withAdminUi(true)-skipJhipsterDepen
".yo-rc.json": {
"stateCleared": "modified",
},
"eslint.config.mjs": {
"stateCleared": "modified",
},
"package.json": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -1942,12 +1930,6 @@ exports[`generator - vue microservice-oauth2-withAdminUi(true)-skipJhipsterDepen

exports[`generator - vue monolith-jwt-skipUserManagement(false)-withAdminUi(true)-skipJhipsterDependencies(true)-enableTranslation(true)--websocket(true) should match generated files snapshot 1`] = `
{
".eslintignore": {
"stateCleared": "modified",
},
".eslintrc.cjs": {
"stateCleared": "modified",
},
".jhipster/EntityWithCustomId.json": {
"stateCleared": "modified",
},
Expand All @@ -1966,6 +1948,9 @@ exports[`generator - vue monolith-jwt-skipUserManagement(false)-withAdminUi(true
".yo-rc.json": {
"stateCleared": "modified",
},
"eslint.config.mjs": {
"stateCleared": "modified",
},
"package.json": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -2556,12 +2541,6 @@ exports[`generator - vue monolith-jwt-skipUserManagement(false)-withAdminUi(true

exports[`generator - vue monolith-oauth2-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-websocket(false) should match generated files snapshot 1`] = `
{
".eslintignore": {
"stateCleared": "modified",
},
".eslintrc.cjs": {
"stateCleared": "modified",
},
".jhipster/EntityWithCustomId.json": {
"stateCleared": "modified",
},
Expand All @@ -2580,6 +2559,9 @@ exports[`generator - vue monolith-oauth2-withAdminUi(false)-skipJhipsterDependen
".yo-rc.json": {
"stateCleared": "modified",
},
"eslint.config.mjs": {
"stateCleared": "modified",
},
"package.json": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -2990,12 +2972,6 @@ exports[`generator - vue monolith-oauth2-withAdminUi(false)-skipJhipsterDependen

exports[`generator - vue monolith-session-skipUserManagement(true)-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-websocket(true) should match generated files snapshot 1`] = `
{
".eslintignore": {
"stateCleared": "modified",
},
".eslintrc.cjs": {
"stateCleared": "modified",
},
".jhipster/EntityWithCustomId.json": {
"stateCleared": "modified",
},
Expand All @@ -3014,6 +2990,9 @@ exports[`generator - vue monolith-session-skipUserManagement(true)-withAdminUi(f
".yo-rc.json": {
"stateCleared": "modified",
},
"eslint.config.mjs": {
"stateCleared": "modified",
},
"package.json": {
"stateCleared": "modified",
},
Expand Down
4 changes: 2 additions & 2 deletions generators/vue/files-vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ export const vueFiles = {
common: [
clientRootTemplatesBlock({
templates: [
'.postcssrc.js',
{ sourceFile: 'eslint.config.js.jhi.vue', destinationFile: ctx => `${ctx.eslintConfigFile}.jhi.vue` },
'package.json',
'tsconfig.json',
'tsconfig.app.json',
'tsconfig.node.json',
'tsconfig.vitest.json',
'.postcssrc.js',
'.eslintrc.cjs',
'vite.config.mts',
'vitest.config.mts',
],
Expand Down
29 changes: 21 additions & 8 deletions generators/vue/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
getTypescriptKeyType as getTSKeyType,
} from '../client/support/index.js';
import { createNeedleCallback } from '../base/support/index.js';
import { writeEslintClientRootConfigFile } from '../javascript/generators/eslint/support/tasks.js';
import { writeEntityFiles, postWriteEntityFiles, cleanupEntitiesFiles } from './entity-files-vue.js';
import cleanupOldFilesTask from './cleanup.js';
import { writeFiles, writeEntitiesFiles } from './files-vue.js';
Expand Down Expand Up @@ -61,6 +62,12 @@ export default class VueGenerator extends BaseApplicationGenerator {
this.fetchFromInstalledJHipster(GENERATOR_VUE, 'resources', 'package.json'),
);
},
applicationDefauts({ applicationDefaults }) {
applicationDefaults({
__override__: true,
typescriptEslint: true,
});
},
});
}

Expand All @@ -70,17 +77,17 @@ export default class VueGenerator extends BaseApplicationGenerator {

get preparing() {
return this.asPreparingTaskGroup({
applicationDefauts({ applicationDefaults }) {
applicationDefaults({
__override__: true,
eslintConfigFile: app => `eslint.config.${app.packageJsonType === 'module' ? 'js' : 'mjs'}`,
clientWebappDir: app => `${app.clientSrcDir}app/`,
webappEnumerationsDir: app => `${app.clientWebappDir}shared/model/enumerations/`,
});
},
prepareForTemplates({ application, source }) {
application.addPrettierExtensions?.(['html', 'vue', 'css', 'scss']);

application.clientWebappDir = `${application.clientSrcDir}app/`;
application.webappEnumerationsDir = `${application.clientWebappDir}shared/model/enumerations/`;
application.clientSpecDir = `${application.clientTestDir}spec/`;

// Can be dropped if tests are moved near implementation
application.applicationRootRelativeToClientTestDir = `${relative(application.clientSpecDir, '.')}/`;
application.clientSrcDirRelativeToClientTestDir = `${relative(application.clientSpecDir, application.clientWebappDir)}/`;

source.addWebpackConfig = args => {
const webpackPath = `${application.clientRootDir}webpack/webpack.common.js`;
const ignoreNonExisting = this.sharedData.getControl().ignoreNeedlesError && 'Webpack configuration file not found';
Expand Down Expand Up @@ -148,7 +155,13 @@ export default class VueGenerator extends BaseApplicationGenerator {

get writing() {
return this.asWritingTaskGroup({
cleanup({ control }) {
control.cleanupFiles({
'8.6.1': ['.eslintrc.json', '.eslintignore'],
});
},
cleanupOldFilesTask,
writeEslintClientRootConfigFile,
writeFiles,
});
}
Expand Down
5 changes: 3 additions & 2 deletions generators/vue/resources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
"vue-router": "4.4.0"
},
"devDependencies": {
"@eslint/eslintrc": "3.1.0",
"@eslint/js": "8.57.0",
"@module-federation/utilities": "3.0.3-0",
"@pinia/testing": "0.1.3",
"@rushstack/eslint-patch": "1.10.3",
"@tsconfig/node18": "18.2.4",
"@types/node": "20.11.25",
"@types/sinon": "17.0.3",
"@vitejs/plugin-vue": "5.1.0",
"@vue/eslint-config-prettier": "9.0.0",
"@vue/eslint-config-typescript": "13.0.0",
"@vue/test-utils": "2.4.6",
"@vue/tsconfig": "0.5.1",
Expand Down Expand Up @@ -58,6 +58,7 @@
"terser-webpack-plugin": "5.3.10",
"ts-loader": "9.5.1",
"typescript": "5.5.4",
"typescript-eslint": "7.17.0",
"vite": "5.3.4",
"vite-plugin-static-copy": "1.0.6",
"vitest": "2.0.4",
Expand Down
Loading

0 comments on commit 09c885c

Please sign in to comment.