From e4d2d691a67e07db56f53afdf4d2c6e4f0c141c8 Mon Sep 17 00:00:00 2001 From: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Date: Mon, 23 Jan 2023 11:01:01 +0100 Subject: [PATCH 1/3] add src folder to debug command --- src/Umbraco.Web.UI.Client/.vscode/launch.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Web.UI.Client/.vscode/launch.json b/src/Umbraco.Web.UI.Client/.vscode/launch.json index 828c6a84f0..d4241510db 100644 --- a/src/Umbraco.Web.UI.Client/.vscode/launch.json +++ b/src/Umbraco.Web.UI.Client/.vscode/launch.json @@ -5,7 +5,7 @@ "version": "0.2.0", "configurations": [ { - "command": "npx eslint", + "command": "npx eslint src", "name": "Debug eslint", "request": "launch", "type": "node-terminal" From 264fc9c910f2ca64f2f4912410cce799a27ff92b Mon Sep 17 00:00:00 2001 From: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Date: Mon, 23 Jan 2023 11:01:51 +0100 Subject: [PATCH 2/3] add definitions for rule to check for absolute imports from the src folder --- .../eslint-local-rules.cjs | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Web.UI.Client/eslint-local-rules.cjs b/src/Umbraco.Web.UI.Client/eslint-local-rules.cjs index a4d6a82658..1ec3bed82c 100644 --- a/src/Umbraco.Web.UI.Client/eslint-local-rules.cjs +++ b/src/Umbraco.Web.UI.Client/eslint-local-rules.cjs @@ -64,5 +64,30 @@ module.exports = { }; }, - } + }, + + /** @type {import('eslint').Rule.RuleModule} */ + 'prefer-import-aliases': { + meta: { + type: 'suggestion', + docs: { + description: 'Ensures that the application does not rely on file system paths for imports. Instead, use import aliases or relative imports. This also solves a problem where GitHub fails on the test runner step.', + category: 'Best Practices', + recommended: true + }, + schema: [], + }, + create: function (context) { + return { + ImportDeclaration: function (node) { + if (node.source.value.startsWith('src/')) { + context.report({ + node, + message: 'Prefer using import aliases or relative imports instead of absolute imports. Example: `import { MyComponent } from "src/components/MyComponent";` should be `import { MyComponent } from "@components/MyComponent";`' + }); + } + }, + }; + } + }, }; From cd7d5daa8d623ce0fdf3da98eaa36a44da8d8ea9 Mon Sep 17 00:00:00 2001 From: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Date: Mon, 23 Jan 2023 11:02:06 +0100 Subject: [PATCH 3/3] enable eslint rule for absolute imports as a warning --- src/Umbraco.Web.UI.Client/.eslintrc.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Umbraco.Web.UI.Client/.eslintrc.json b/src/Umbraco.Web.UI.Client/.eslintrc.json index 1d78b5edbf..b120238897 100644 --- a/src/Umbraco.Web.UI.Client/.eslintrc.json +++ b/src/Umbraco.Web.UI.Client/.eslintrc.json @@ -35,6 +35,7 @@ "import/order": "warn", "local-rules/bad-type-import": "error", "local-rules/no-direct-api-import": "warn", + "local-rules/prefer-import-aliases": "warn", "@typescript-eslint/no-non-null-assertion": "off" }, "settings": {