diff --git a/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestESLint.java b/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestESLint.java index b2c1ffbf78..7696696bc2 100644 --- a/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestESLint.java +++ b/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestESLint.java @@ -42,114 +42,114 @@ class TestESLint { - private static IProject project; - - @BeforeAll - public static void setUpProject() throws Exception { - AllCleanRule.closeIntro(); - AllCleanRule.enableLogging(); - - String projectName = TestESLint.class.getName() + System.nanoTime(); - IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName); - IPath projectLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(projectName); - desc.setLocation(projectLocation); - File projectDirectory = projectLocation.toFile(); - projectDirectory.mkdir(); - try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/.eslintrc")) { - Files.copy(eslintRc, new File(projectDirectory, ".eslintrc").toPath()); - } - try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/tsconfig.json")) { - Files.copy(eslintRc, new File(projectDirectory, "tsconfig.json").toPath()); - } - try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/package.json")) { - Files.copy(eslintRc, new File(projectDirectory, "package.json").toPath()); - } - try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/ESLintProj.js")) { - Files.copy(eslintRc, new File(projectDirectory, "ESLintProj.js").toPath()); - } - try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/ESLintProj.js")) { - Files.copy(eslintRc, new File(projectDirectory, "ESLintProj.jsx").toPath()); - } - try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/ESLintProj.js")) { - Files.copy(eslintRc, new File(projectDirectory, "ESLintProj.ts").toPath()); - } - try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/ESLintProj.js")) { - Files.copy(eslintRc, new File(projectDirectory, "ESLintProj.tsx").toPath()); - } - ProcessBuilder builder = NodeJSManager.prepareNPMProcessBuilder("install", "--no-bin-links", "--ignore-scripts") - .directory(projectDirectory); - Process dependencyInstaller = builder.start(); - System.out.println(builder.command().toString()); - String result = dependencyInstaller.errorReader().lines().collect(Collectors.joining("\n")); - System.out.println("Error Stream: >>>\n" + result + "\n<<<"); - - result = dependencyInstaller.inputReader().lines().collect(Collectors.joining("\n")); - System.out.println("Output Stream: >>>\n" + result + "\n<<<"); - - assertEquals(0, dependencyInstaller.waitFor(), "npm install didn't complete properly"); - project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); - project.create(desc, null); - project.open(null); - } - - @BeforeEach - public void setUpTestCase() { - AllCleanRule.enableLogging(); - } - - @AfterAll - public static void cleanUp() throws Exception { - new AllCleanRule().afterEach(null); - } - - @Test - void testESLintDiagnosticsInJS() throws Exception { - IFile file = project.getFile("ESLintProj.js"); - IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); - assertESLintIndentMarkerExists(file); - } - - @Test - void testESLintDiagnosticsInTS() throws Exception { - IFile file = project.getFile("ESLintProj.ts"); - IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); - assertESLintIndentMarkerExists(file); - } - - @Test - void testESLintDiagnosticsInJSX() throws Exception { - IFile file = project.getFile("ESLintProj.jsx"); - IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); - assertESLintIndentMarkerExists(file); - } - - @Test - void testESLintDiagnosticsInTSX() throws Exception { - IFile file = project.getFile("ESLintProj.tsx"); - IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); - assertESLintIndentMarkerExists(file); - } - - private void assertESLintIndentMarkerExists(IFile file) throws PartInitException { - IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); - assertTrue(DisplayHelper.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 10000, () -> { - try { - return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0; - } catch (CoreException e) { - e.printStackTrace(); - return false; - } - }), "Diagnostic not published"); - - assertTrue(DisplayHelper.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000, () -> { - try { - return Arrays.asList(file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO)) - .stream().filter(Objects::nonNull) - .anyMatch(m -> m.getAttribute(IMarker.MESSAGE, null).toLowerCase().contains("indentation")); - } catch (CoreException e) { - e.printStackTrace(); - return false; - } - }), "Diagnostic content is incorrect"); - } + private static IProject project; + + @BeforeAll + public static void setUpProject() throws Exception { + AllCleanRule.closeIntro(); + AllCleanRule.enableLogging(); + + String projectName = TestESLint.class.getName() + System.nanoTime(); + IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName); + IPath projectLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(projectName); + desc.setLocation(projectLocation); + File projectDirectory = projectLocation.toFile(); + projectDirectory.mkdir(); + try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/eslint.config.mjs")) { + Files.copy(eslintRc, new File(projectDirectory, "eslint.config.mjs").toPath()); + } + try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/tsconfig.json")) { + Files.copy(eslintRc, new File(projectDirectory, "tsconfig.json").toPath()); + } + try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/package.json")) { + Files.copy(eslintRc, new File(projectDirectory, "package.json").toPath()); + } + try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/ESLintProj.js")) { + Files.copy(eslintRc, new File(projectDirectory, "ESLintProj.js").toPath()); + } + try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/ESLintProj.js")) { + Files.copy(eslintRc, new File(projectDirectory, "ESLintProj.jsx").toPath()); + } + try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/ESLintProj.js")) { + Files.copy(eslintRc, new File(projectDirectory, "ESLintProj.ts").toPath()); + } + try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/ESLintProj.js")) { + Files.copy(eslintRc, new File(projectDirectory, "ESLintProj.tsx").toPath()); + } + ProcessBuilder builder = NodeJSManager.prepareNPMProcessBuilder("install", "--no-bin-links", "--ignore-scripts") + .directory(projectDirectory); + Process dependencyInstaller = builder.start(); + System.out.println(builder.command().toString()); + String result = dependencyInstaller.errorReader().lines().collect(Collectors.joining("\n")); + System.out.println("Error Stream: >>>\n" + result + "\n<<<"); + + result = dependencyInstaller.inputReader().lines().collect(Collectors.joining("\n")); + System.out.println("Output Stream: >>>\n" + result + "\n<<<"); + + assertEquals(0, dependencyInstaller.waitFor(), "npm install didn't complete properly"); + project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); + project.create(desc, null); + project.open(null); + } + + @BeforeEach + public void setUpTestCase() { + AllCleanRule.enableLogging(); + } + + @AfterAll + public static void cleanUp() throws Exception { + new AllCleanRule().afterEach(null); + } + + @Test + void testESLintDiagnosticsInJS() throws Exception { + IFile file = project.getFile("ESLintProj.js"); + IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); + assertESLintIndentMarkerExists(file); + } + + @Test + void testESLintDiagnosticsInTS() throws Exception { + IFile file = project.getFile("ESLintProj.ts"); + IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); + assertESLintIndentMarkerExists(file); + } + + @Test + void testESLintDiagnosticsInJSX() throws Exception { + IFile file = project.getFile("ESLintProj.jsx"); + IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); + assertESLintIndentMarkerExists(file); + } + + @Test + void testESLintDiagnosticsInTSX() throws Exception { + IFile file = project.getFile("ESLintProj.tsx"); + IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); + assertESLintIndentMarkerExists(file); + } + + private void assertESLintIndentMarkerExists(IFile file) throws PartInitException { + IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); + assertTrue(DisplayHelper.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 10000, () -> { + try { + return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0; + } catch (CoreException e) { + e.printStackTrace(); + return false; + } + }), "Diagnostic not published"); + + assertTrue(DisplayHelper.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000, () -> { + try { + return Arrays.asList(file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO)) + .stream().filter(Objects::nonNull) + .anyMatch(m -> m.getAttribute(IMarker.MESSAGE, null).toLowerCase().contains("indentation")); + } catch (CoreException e) { + e.printStackTrace(); + return false; + } + }), "Diagnostic content is incorrect"); + } } diff --git a/org.eclipse.wildwebdeveloper.tests/testProjects/eslint/.eslintrc b/org.eclipse.wildwebdeveloper.tests/testProjects/eslint/.eslintrc deleted file mode 100644 index 3ae8457d55..0000000000 --- a/org.eclipse.wildwebdeveloper.tests/testProjects/eslint/.eslintrc +++ /dev/null @@ -1,12 +0,0 @@ -{ - "parser": "@typescript-eslint/parser", - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/eslint-recommended", - "plugin:@typescript-eslint/recommended" - ], - "plugins": ["@typescript-eslint"], - "rules": { - "indent": "error" - } -} \ No newline at end of file diff --git a/org.eclipse.wildwebdeveloper.tests/testProjects/eslint/eslint.config.mjs b/org.eclipse.wildwebdeveloper.tests/testProjects/eslint/eslint.config.mjs new file mode 100644 index 0000000000..b1ece9b138 --- /dev/null +++ b/org.eclipse.wildwebdeveloper.tests/testProjects/eslint/eslint.config.mjs @@ -0,0 +1,15 @@ +import tsParser from '@typescript-eslint/parser'; + +export default [ + { + rules: { + indent: 'error', + }, + }, + { + files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'], + languageOptions: { + parser: tsParser, + }, + }, +]; \ No newline at end of file diff --git a/org.eclipse.wildwebdeveloper.tests/testProjects/eslint/package.json b/org.eclipse.wildwebdeveloper.tests/testProjects/eslint/package.json index 6c9e0ea96a..e641328e92 100644 --- a/org.eclipse.wildwebdeveloper.tests/testProjects/eslint/package.json +++ b/org.eclipse.wildwebdeveloper.tests/testProjects/eslint/package.json @@ -11,7 +11,7 @@ "devDependencies": { "@typescript-eslint/eslint-plugin": "^8.56.0", "@typescript-eslint/parser": "^8.56.0", - "eslint": "^8.57.1", + "eslint": "^10.1.0", "typescript": "5.9.3" }, "packageManager": "npm@11"