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 15, 2024
1 parent 7ca8a1d commit 502b1ca
Show file tree
Hide file tree
Showing 18 changed files with 207 additions and 179 deletions.
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
15 changes: 9 additions & 6 deletions generators/react/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ 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) {
Expand All @@ -59,6 +56,7 @@ export default class ReactGenerator extends BaseApplicationGenerator {
get composing() {
return this.asComposingTaskGroup({
async composeClientCommon() {
await this.composeWithJHipster('jhipster:javascript:eslint', { generatorOptions: { typescriptEslint: true } });
await this.composeWithJHipster('jhipster:client:common');
},
});
Expand Down Expand Up @@ -142,10 +140,15 @@ export default class ReactGenerator extends BaseApplicationGenerator {
}

get writing() {
return {
return this.asWritingTaskGroup({
cleanup({ control }) {
control.cleanupFiles({
'8.5.1': ['.eslintrc.json', '.eslintignore'],
});
},
cleanupOldFilesTask,
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.15.0",
"webpack": "5.93.0",
"webpack-cli": "5.1.4",
"webpack-dev-server": "5.0.4",
Expand Down
Loading

0 comments on commit 502b1ca

Please sign in to comment.