Skip to content

Commit

Permalink
migrate react eslint to flat config
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Jul 16, 2024
1 parent 7424f42 commit 131f69b
Show file tree
Hide file tree
Showing 19 changed files with 235 additions and 183 deletions.
5 changes: 3 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ updates:
- dependency-name: '@module-federation/utilities'
versions: ['*']
groups:
typescript-eslint:
eslint:
patterns:
- '@typescript-eslint/*'
- '@eslint/*'
- 'eslint'
fortawesome:
patterns:
- '@fortawesome/fontawesome-svg-core'
Expand Down
1 change: 1 addition & 0 deletions generators/client/files-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const files = {
templates: ['README.md.jhi.client', '.prettierignore.jhi.client'],
},
clientRootTemplatesBlock({
condition: ctx => !ctx.clientFrameworkReact,
templates: ['.eslintignore'],
}),
clientRootTemplatesBlock({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const shareDependencies = ({ skipList = [] } = {}) =>
.map(([dependency, version]) => [dependency, { ...sharedDefaults, version, requiredVersion: version }]),
);

module.exports = ({ serve }) => {
module.exports = () => {
return {
optimization: {
moduleIds: 'named',
Expand Down
4 changes: 4 additions & 0 deletions generators/cypress/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export const cypressFiles: WriteFileSection<CypressGenerator, CommonClientServer
clientRootTemplatesBlock({
templates: ['cypress.config.ts'],
}),
clientRootTemplatesBlock({
condition: ctx => Boolean(ctx.eslintConfigFile),
templates: [{ sourceFile: 'eslint.config.js.jhi.cypress', destinationFile: ctx => `${ctx.eslintConfigFile}.jhi.cypress` }],
}),
],
clientTestFw: [
{
Expand Down
41 changes: 41 additions & 0 deletions generators/cypress/templates/eslint.config.js.jhi.cypress.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<%#
Copyright 2013-2024 the original author or authors from the JHipster project.
This file is part of the JHipster project, see https://www.jhipster.tech/
for more information.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-%>
<&_ if (fragment.importsSection) { -&>
import cypress from 'eslint-plugin-cypress/flat';
<&_ } -&>
<&_ if (fragment.configSection) { -&>
{
files: ['<%- this.relativeDir(clientRootDir, cypressDir) %>**/*.cy.ts'],
extends: [...tseslint.configs.recommendedTypeChecked, cypress.configs.recommended],
languageOptions: {
parserOptions: {
"project": ["./<%= this.relativeDir(clientRootDir, cypressDir) %>tsconfig.json"],
},
},
rules: {
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-unsafe-argument': 'warn',
'@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',
},
},
<&_ } -&>
60 changes: 24 additions & 36 deletions generators/react/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ exports[`generator - react gateway-jwt-skipUserManagement(true)-withAdminUi(fals
".yo-rc.json": {
"stateCleared": "modified",
},
"clientRoot/.eslintignore": {
"stateCleared": "modified",
},
"clientRoot/.eslintrc.json": {
"clientRoot/eslint.config.mjs": {
"stateCleared": "modified",
},
"clientRoot/jest.conf.js": {
Expand Down Expand Up @@ -419,6 +416,9 @@ exports[`generator - react gateway-jwt-skipUserManagement(true)-withAdminUi(fals
"clientRoot/webpack/webpack.prod.js": {
"stateCleared": "modified",
},
"package.json": {
"stateCleared": "modified",
},
}
`;

Expand All @@ -439,10 +439,7 @@ exports[`generator - react gateway-oauth2-withAdminUi(true)-skipJhipsterDependen
".yo-rc.json": {
"stateCleared": "modified",
},
"clientRoot/.eslintignore": {
"stateCleared": "modified",
},
"clientRoot/.eslintrc.json": {
"clientRoot/eslint.config.mjs": {
"stateCleared": "modified",
},
"clientRoot/jest.conf.js": {
Expand Down Expand Up @@ -874,6 +871,9 @@ exports[`generator - react gateway-oauth2-withAdminUi(true)-skipJhipsterDependen
"clientRoot/webpack/webpack.prod.js": {
"stateCleared": "modified",
},
"package.json": {
"stateCleared": "modified",
},
}
`;

Expand All @@ -894,10 +894,7 @@ exports[`generator - react microservice-jwt-skipUserManagement(false)-withAdminU
".yo-rc.json": {
"stateCleared": "modified",
},
"clientRoot/.eslintignore": {
"stateCleared": "modified",
},
"clientRoot/.eslintrc.json": {
"clientRoot/eslint.config.mjs": {
"stateCleared": "modified",
},
"clientRoot/jest.conf.js": {
Expand Down Expand Up @@ -1302,17 +1299,14 @@ exports[`generator - react microservice-jwt-skipUserManagement(false)-withAdminU
"clientRoot/webpack/webpack.prod.js": {
"stateCleared": "modified",
},
"package.json": {
"stateCleared": "modified",
},
}
`;

exports[`generator - react microservice-oauth2-withAdminUi(true)-skipJhipsterDependencies(true)-enableTranslation(true)--websocket(false) should match generated files snapshot 1`] = `
{
".eslintignore": {
"stateCleared": "modified",
},
".eslintrc.json": {
"stateCleared": "modified",
},
".jhipster/EntityWithCustomId.json": {
"stateCleared": "modified",
},
Expand All @@ -1328,6 +1322,9 @@ exports[`generator - react microservice-oauth2-withAdminUi(true)-skipJhipsterDep
".yo-rc.json": {
"stateCleared": "modified",
},
"eslint.config.mjs": {
"stateCleared": "modified",
},
"jest.conf.js": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -1753,12 +1750,6 @@ exports[`generator - react microservice-oauth2-withAdminUi(true)-skipJhipsterDep

exports[`generator - react monolith-jwt-skipUserManagement(false)-withAdminUi(true)-skipJhipsterDependencies(true)-enableTranslation(true)--websocket(true) should match generated files snapshot 1`] = `
{
".eslintignore": {
"stateCleared": "modified",
},
".eslintrc.json": {
"stateCleared": "modified",
},
".jhipster/EntityWithCustomId.json": {
"stateCleared": "modified",
},
Expand All @@ -1774,6 +1765,9 @@ exports[`generator - react monolith-jwt-skipUserManagement(false)-withAdminUi(tr
".yo-rc.json": {
"stateCleared": "modified",
},
"eslint.config.mjs": {
"stateCleared": "modified",
},
"jest.conf.js": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -2268,12 +2262,6 @@ exports[`generator - react monolith-jwt-skipUserManagement(false)-withAdminUi(tr

exports[`generator - react monolith-oauth2-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-websocket(false) should match generated files snapshot 1`] = `
{
".eslintignore": {
"stateCleared": "modified",
},
".eslintrc.json": {
"stateCleared": "modified",
},
".jhipster/EntityWithCustomId.json": {
"stateCleared": "modified",
},
Expand All @@ -2289,6 +2277,9 @@ exports[`generator - react monolith-oauth2-withAdminUi(false)-skipJhipsterDepend
".yo-rc.json": {
"stateCleared": "modified",
},
"eslint.config.mjs": {
"stateCleared": "modified",
},
"jest.conf.js": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -2693,12 +2684,6 @@ exports[`generator - react monolith-oauth2-withAdminUi(false)-skipJhipsterDepend

exports[`generator - react monolith-session-skipUserManagement(true)-withAdminUi(false)-skipJhipsterDependencies(false)-enableTranslation(false)-websocket(true) should match generated files snapshot 1`] = `
{
".eslintignore": {
"stateCleared": "modified",
},
".eslintrc.json": {
"stateCleared": "modified",
},
".jhipster/EntityWithCustomId.json": {
"stateCleared": "modified",
},
Expand All @@ -2714,6 +2699,9 @@ exports[`generator - react monolith-session-skipUserManagement(true)-withAdminUi
".yo-rc.json": {
"stateCleared": "modified",
},
"eslint.config.mjs": {
"stateCleared": "modified",
},
"jest.conf.js": {
"stateCleared": "modified",
},
Expand Down
7 changes: 4 additions & 3 deletions generators/react/files-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { asWriteFilesSection } from '../base-application/support/index.js';
import { clientApplicationTemplatesBlock, clientRootTemplatesBlock, clientSrcTemplatesBlock } from '../client/support/files.js';

export const files = {
export const files = asWriteFilesSection({
common: [
clientRootTemplatesBlock({
templates: [
{ sourceFile: 'eslint.config.js.jhi.react', destinationFile: ctx => `${ctx.eslintConfigFile}.jhi.react` },
'package.json',
'.eslintrc.json',
'tsconfig.json',
'tsconfig.test.json',
'jest.conf.js',
Expand Down Expand Up @@ -304,7 +305,7 @@ export const files = {
templates: ['shared/reducers/user-management.spec.ts'],
},
],
};
});

export async function writeFiles({ application }) {
if (!application.clientFrameworkReact) return;
Expand Down
42 changes: 34 additions & 8 deletions generators/react/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
generateEntityClientImports as formatEntityClientImports,
generateTestEntityId as getTestEntityId,
generateTestEntityPrimaryKey as getTestEntityPrimaryKey,
clientRootTemplatesBlock,
} from '../client/support/index.js';
import { createNeedleCallback, upperFirstCamelCase } from '../base/support/index.js';
import { writeEntitiesFiles, postWriteEntitiesFiles, cleanupEntitiesFiles } from './entity-files-react.js';
Expand All @@ -40,17 +41,15 @@ import { isTranslatedReactFile, translateReactFilesTransform } from './support/i
const { CommonDBTypes } = fieldTypes;
const TYPE_BOOLEAN = CommonDBTypes.BOOLEAN;
const { REACT } = clientFrameworkTypes;
/**
* @class
* @extends {BaseApplicationGenerator<import('../client/types.js').ClientApplication>}
*/

export default class ReactGenerator extends BaseApplicationGenerator {
async beforeQueue() {
if (!this.fromBlueprint) {
await this.composeWithBlueprints();
}

if (!this.delegateToBlueprint) {
await this.dependsOnJHipster('jhipster:javascript:bootstrap');
await this.dependsOnJHipster(GENERATOR_CLIENT);
await this.dependsOnJHipster(GENERATOR_LANGUAGES);
}
Expand All @@ -76,6 +75,12 @@ export default class ReactGenerator extends BaseApplicationGenerator {
this.fetchFromInstalledJHipster(GENERATOR_REACT, 'resources', 'package.json'),
);
},
applicationDefauts({ applicationDefaults }) {
applicationDefaults({
__override__: true,
typescriptEslint: true,
});
},
});
}

Expand All @@ -85,9 +90,14 @@ export default class ReactGenerator extends BaseApplicationGenerator {

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

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 @@ -142,10 +152,26 @@ export default class ReactGenerator extends BaseApplicationGenerator {
}

get writing() {
return {
return this.asWritingTaskGroup({
cleanup({ control }) {
control.cleanupFiles({
'8.6.1': ['.eslintrc.json', '.eslintignore'],
});
},
cleanupOldFilesTask,
async writingEslintFile({ application }) {
await this.writeFiles({
blocks: [
clientRootTemplatesBlock({
templates: [{ sourceFile: 'eslint.config.js.jhi', destinationFile: ctx => `${ctx.eslintConfigFile}.jhi` }],
}),
],
context: application,
rootTemplatesPath: this.fetchFromInstalledJHipster('javascript/generators/eslint/templates'),
});
},
writeFiles,
};
});
}

get [BaseApplicationGenerator.WRITING]() {
Expand Down
3 changes: 3 additions & 0 deletions generators/react/resources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"webstomp-client": "1.2.6"
},
"devDependencies": {
"@eslint/js": "8.57.0",
"@module-federation/utilities": "3.0.3-0",
"@testing-library/react": "16.0.0",
"@types/jest": "29.5.12",
Expand All @@ -51,6 +52,7 @@
"css-minimizer-webpack-plugin": "7.0.0",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.1.3",
"eslint-plugin-react": "7.34.4",
"eslint-webpack-plugin": "4.2.0",
"folder-hash": "4.0.4",
Expand Down Expand Up @@ -81,6 +83,7 @@
"ts-jest": "29.2.2",
"ts-loader": "9.5.1",
"typescript": "5.5.3",
"typescript-eslint": "7.16.0",
"webpack": "5.93.0",
"webpack-cli": "5.1.4",
"webpack-dev-server": "5.0.4",
Expand Down
Loading

0 comments on commit 131f69b

Please sign in to comment.