From eb7c95207400d14eb2e119ee005ad2dc8f42a6a8 Mon Sep 17 00:00:00 2001 From: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Date: Mon, 6 Nov 2023 09:45:03 +0100 Subject: [PATCH] move exceptions to .eslintrc config --- src/Umbraco.Web.UI.Client/.eslintrc.json | 7 ++++++- .../eslint-local-rules.cjs | 21 ++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/.eslintrc.json b/src/Umbraco.Web.UI.Client/.eslintrc.json index 9f44b216df..7bd88d19e9 100644 --- a/src/Umbraco.Web.UI.Client/.eslintrc.json +++ b/src/Umbraco.Web.UI.Client/.eslintrc.json @@ -45,7 +45,12 @@ "local-rules/umb-class-prefix": "error", "local-rules/prefer-static-styles-last": "warn", "local-rules/ensure-relative-import-use-js-extension": "error", - "local-rules/ensure-no-external-imports": "error", + "local-rules/ensure-no-external-imports": [ + "error", + { + "exceptions": ["@umbraco-cms", "@open-wc/testing", "@storybook", "msw", "."] + } + ], "@typescript-eslint/no-non-null-assertion": "off", "@typescript-eslint/no-explicit-any": "warn", "@typescript-eslint/no-unused-vars": "warn" diff --git a/src/Umbraco.Web.UI.Client/eslint-local-rules.cjs b/src/Umbraco.Web.UI.Client/eslint-local-rules.cjs index 015b53aadd..8a7a9d1d1c 100644 --- a/src/Umbraco.Web.UI.Client/eslint-local-rules.cjs +++ b/src/Umbraco.Web.UI.Client/eslint-local-rules.cjs @@ -345,11 +345,23 @@ module.exports = { type: 'problem', docs: { description: 'Ensures that the application does not rely on imports from external packages.', - category: 'Best Practices', recommended: true, }, fixable: 'code', - schema: [], + schema: { + type: "array", + minItems: 0, + maxItems: 1, + items: [ + { + type: "object", + properties: { + exceptions: { type: "array" } + }, + additionalProperties: false + } + ] + } }, create: (context) => { return { @@ -357,8 +369,11 @@ module.exports = { const { source } = node; const { value } = source; + const options = context.options[0] || {}; + const exceptions = options.exceptions || []; + // If import starts with any of the following, then it's allowed - if (['@umbraco-cms', '@open-wc/testing', '@storybook', 'msw', '.'].some(v => value.startsWith(v))) { + if (exceptions.some(v => value.startsWith(v))) { return; }