diff --git a/src/Umbraco.Web.UI.Client/.eslintrc.json b/src/Umbraco.Web.UI.Client/.eslintrc.json index 12235e837e..88caa66773 100644 --- a/src/Umbraco.Web.UI.Client/.eslintrc.json +++ b/src/Umbraco.Web.UI.Client/.eslintrc.json @@ -43,6 +43,7 @@ "local-rules/prefer-import-aliases": "error", "local-rules/enforce-element-suffix-on-element-class-name": "error", "local-rules/prefer-umbraco-cms-imports": "error", + "local-rules/no-external-imports": "error", "@typescript-eslint/no-non-null-assertion": "off" }, "settings": { diff --git a/src/Umbraco.Web.UI.Client/eslint-local-rules.cjs b/src/Umbraco.Web.UI.Client/eslint-local-rules.cjs index cf5a8913b1..ed1c5036cd 100644 --- a/src/Umbraco.Web.UI.Client/eslint-local-rules.cjs +++ b/src/Umbraco.Web.UI.Client/eslint-local-rules.cjs @@ -43,7 +43,7 @@ module.exports = { type: 'suggestion', docs: { description: - 'Ensures that any API resources from the `@umbraco-cms/backend-api` module are not used directly. Instead you should use the `tryExecuteAndNotify` function from the `@umbraco-cms/resources` module.', + 'Ensures that any API resources from the `@umbraco-cms/backoffice/backend-api` module are not used directly. Instead you should use the `tryExecuteAndNotify` function from the `@umbraco-cms/resources` module.', category: 'Best Practices', recommended: true, }, @@ -107,6 +107,7 @@ module.exports = { }; }, }, + /** @type {import('eslint').Rule.RuleModule} */ 'enforce-element-suffix-on-element-class-name': { meta: { @@ -138,6 +139,7 @@ module.exports = { }; }, }, + // TODO: Its not bullet proof, but it will catch most/some cases. /** @type {import('eslint').Rule.RuleModule} */ 'prefer-umbraco-cms-imports': { @@ -172,4 +174,35 @@ module.exports = { }; }, }, + + /** @type {import('eslint').Rule.RuleModule} */ + 'no-external-imports': { + meta: { + type: 'problem', + docs: { + description: + 'Ensures that the application does not rely on imports from external packages. Instead, use the @umbraco-cms/backoffice libs.', + recommended: true, + }, + fixable: 'code', + schema: [], + }, + create: function (context) { + return { + ImportDeclaration: function (node) { + // Check for imports from "router-slot" + if (node.source.value.startsWith('router-slot')) { + context.report({ + node, + message: + 'Use the `@umbraco-cms/backoffice/router` package instead of importing directly from "router-slot" because we might change that dependency in the future.', + fix: (fixer) => { + return fixer.replaceTextRange(node.source.range, `'@umbraco-cms/backoffice/router'`); + }, + }); + } + }, + }; + }, + }, };