From 44f9ef3c6fbc68580232eef10a2c3684b17e339e Mon Sep 17 00:00:00 2001 From: Quentin Date: Mon, 2 Dec 2024 22:18:26 +0100 Subject: [PATCH] React/ESLint: enable react/react-in-jsx-scope --- .../client/react/core/domain/ReactCoreModulesFactory.java | 7 ++++++- .../app/home/infrastructure/primary/HomePage.tsx.mustache | 1 + .../home/infrastructure/primary/HomePage.spec.tsx.mustache | 1 + .../webapp/app/common/primary/app/LoginApp.tsx.mustache | 1 + .../webapp/app/login/primary/loginForm/index.tsx.mustache | 2 +- .../login/primary/loginModal/EyeFilledIcon.tsx.mustache | 2 ++ .../primary/loginModal/EyeSlashFilledIcon.tsx.mustache | 2 ++ .../webapp/app/login/primary/loginModal/index.tsx.mustache | 2 +- .../unit/login/primary/loginForm/index.test.tsx.mustache | 1 + .../unit/login/primary/loginModal/index.test.tsx.mustache | 1 + ...houldBuildModuleWithStyle.eslint.config.js.approved.txt | 1 - ...t.shouldBuildModuleWithStyle.tsconfig.json.approved.txt | 1 + 12 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/tech/jhipster/lite/generator/client/react/core/domain/ReactCoreModulesFactory.java b/src/main/java/tech/jhipster/lite/generator/client/react/core/domain/ReactCoreModulesFactory.java index 9c05f41dcae..ea27c33aa40 100644 --- a/src/main/java/tech/jhipster/lite/generator/client/react/core/domain/ReactCoreModulesFactory.java +++ b/src/main/java/tech/jhipster/lite/generator/client/react/core/domain/ReactCoreModulesFactory.java @@ -142,7 +142,6 @@ private Consumer patchEslintConfig(JHipsterModuleProperti .add( regex("[ \\t]+quotes: \\['error', 'single', \\{ avoidEscape: true }],"), """ - \t\t\t'react/react-in-jsx-scope': 'off', \t\t\t'@typescript-eslint/no-explicit-any': 'off', \t\t\t'@typescript-eslint/await-thenable': 'off', \t\t\t'@typescript-eslint/consistent-type-imports': 'error', @@ -170,6 +169,7 @@ private Consumer patchTsConfig(JHipsterModuleProperties p .add(tsConfigCompilerOption("composite", false, properties.indentation())) .add(tsConfigCompilerOption("forceConsistentCasingInFileNames", true, properties.indentation())) .add(tsConfigCompilerOption("allowSyntheticDefaultImports", true, properties.indentation())) + .add(tsConfigCompilerOption("jsx", "react", properties.indentation())) .add(text(DEFAULT_TSCONFIG_PATH), pathsReplacement) .and() .and(); @@ -181,6 +181,11 @@ private static MandatoryReplacer tsConfigCompilerOption(String optionName, boole return new MandatoryReplacer(lineAfterRegex("\"compilerOptions\":"), compilerOption); } + private static MandatoryReplacer tsConfigCompilerOption(String optionName, String optionValue, Indentation indentation) { + String compilerOption = indentation.times(2) + "\"%s\": \"%s\",".formatted(optionName, optionValue); + return new MandatoryReplacer(lineAfterRegex("\"compilerOptions\":"), compilerOption); + } + private Consumer patchVitestConfig(JHipsterModuleProperties properties) { //@formatter:off return moduleBuilder -> moduleBuilder diff --git a/src/main/resources/generator/client/react/core/src/main/webapp/app/home/infrastructure/primary/HomePage.tsx.mustache b/src/main/resources/generator/client/react/core/src/main/webapp/app/home/infrastructure/primary/HomePage.tsx.mustache index 48d7c713d6c..3dd2980fb19 100644 --- a/src/main/resources/generator/client/react/core/src/main/webapp/app/home/infrastructure/primary/HomePage.tsx.mustache +++ b/src/main/resources/generator/client/react/core/src/main/webapp/app/home/infrastructure/primary/HomePage.tsx.mustache @@ -1,3 +1,4 @@ +import React from 'react'; import './HomePage.css'; import JHipsterLiteNeonBlue from '@assets/JHipster-Lite-neon-blue.png'; diff --git a/src/main/resources/generator/client/react/core/src/test/webapp/unit/home/infrastructure/primary/HomePage.spec.tsx.mustache b/src/main/resources/generator/client/react/core/src/test/webapp/unit/home/infrastructure/primary/HomePage.spec.tsx.mustache index 00f8eaf4836..ce0fc36d799 100644 --- a/src/main/resources/generator/client/react/core/src/test/webapp/unit/home/infrastructure/primary/HomePage.spec.tsx.mustache +++ b/src/main/resources/generator/client/react/core/src/test/webapp/unit/home/infrastructure/primary/HomePage.spec.tsx.mustache @@ -1,3 +1,4 @@ +import React from 'react'; import { render } from '@testing-library/react'; import { describe, it } from 'vitest'; diff --git a/src/main/resources/generator/client/react/security/jwt/src/main/webapp/app/common/primary/app/LoginApp.tsx.mustache b/src/main/resources/generator/client/react/security/jwt/src/main/webapp/app/common/primary/app/LoginApp.tsx.mustache index e3c68a1b423..abdfecce2db 100644 --- a/src/main/resources/generator/client/react/security/jwt/src/main/webapp/app/common/primary/app/LoginApp.tsx.mustache +++ b/src/main/resources/generator/client/react/security/jwt/src/main/webapp/app/common/primary/app/LoginApp.tsx.mustache @@ -1,3 +1,4 @@ +import React from 'react'; import LoginForm from '@/login/primary/loginForm'; import './HomePage.css'; diff --git a/src/main/resources/generator/client/react/security/jwt/src/main/webapp/app/login/primary/loginForm/index.tsx.mustache b/src/main/resources/generator/client/react/security/jwt/src/main/webapp/app/login/primary/loginForm/index.tsx.mustache index 2bf275fd4a2..c4499a8c7ef 100644 --- a/src/main/resources/generator/client/react/security/jwt/src/main/webapp/app/login/primary/loginForm/index.tsx.mustache +++ b/src/main/resources/generator/client/react/security/jwt/src/main/webapp/app/login/primary/loginForm/index.tsx.mustache @@ -1,5 +1,5 @@ import { Button } from '@nextui-org/react'; -import { createContext, useCallback, useMemo, useState } from 'react'; +import React, { createContext, useCallback, useMemo, useState } from 'react'; import LoginModal from '@/login/primary/loginModal'; diff --git a/src/main/resources/generator/client/react/security/jwt/src/main/webapp/app/login/primary/loginModal/EyeFilledIcon.tsx.mustache b/src/main/resources/generator/client/react/security/jwt/src/main/webapp/app/login/primary/loginModal/EyeFilledIcon.tsx.mustache index f0a2a41c6fc..f77c064c746 100644 --- a/src/main/resources/generator/client/react/security/jwt/src/main/webapp/app/login/primary/loginModal/EyeFilledIcon.tsx.mustache +++ b/src/main/resources/generator/client/react/security/jwt/src/main/webapp/app/login/primary/loginModal/EyeFilledIcon.tsx.mustache @@ -1,3 +1,5 @@ +import React from 'react'; + export const EyeFilledIcon = (props: { className: string }) => (