From 71057b5f0b676ce525a1990695ed10b7d8157c22 Mon Sep 17 00:00:00 2001 From: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Date: Tue, 5 Aug 2025 13:42:39 +0200 Subject: [PATCH] Build: Separate eslint logic for **/*.ts files (#19852) * build: move typescript specific eslint rules to the `**/*ts.` pattern to avoid errors for .js files * allow `Example` as class prefix * allow `example-` as custom element prefix * Removed `eslint-disable-next-line` comments from the Example classes. * Code formatting/tidy-up of Example classes --------- Co-authored-by: leekelleher --- .../enforce-umb-prefix-on-element-name.cjs | 7 ++-- .../devops/eslint/rules/umb-class-prefix.cjs | 6 ++- src/Umbraco.Web.UI.Client/eslint.config.js | 37 +++++++++++-------- .../block-custom-view/block-custom-view.ts | 3 -- .../dataset-dashboard.ts | 2 +- .../examples/icons/icons-dashboard.ts | 2 - .../manifest-picker-dashboard.ts | 8 ++-- .../sorter-dashboard.ts | 3 +- .../sorter-group.ts | 2 +- .../sorter-dashboard.ts | 3 +- .../sorter-group.ts | 2 +- .../counter-status-footer-app.element.ts | 15 +++----- .../reset-counter-menu-item.action.ts | 9 +++-- 13 files changed, 51 insertions(+), 48 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/devops/eslint/rules/enforce-umb-prefix-on-element-name.cjs b/src/Umbraco.Web.UI.Client/devops/eslint/rules/enforce-umb-prefix-on-element-name.cjs index 2fc62a385a..e290422e62 100644 --- a/src/Umbraco.Web.UI.Client/devops/eslint/rules/enforce-umb-prefix-on-element-name.cjs +++ b/src/Umbraco.Web.UI.Client/devops/eslint/rules/enforce-umb-prefix-on-element-name.cjs @@ -1,3 +1,5 @@ +const ALLOWED_PREFIXES = ['umb-', 'ufm-', 'test-', 'example-']; + /** @type {import('eslint').Rule.RuleModule} */ module.exports = { meta: { @@ -23,9 +25,8 @@ module.exports = { if (isCustomElementDecorator) { const elementName = node.arguments[0].value; - // check if the element name starts with 'umb-', 'ufm-', or 'test-', to be allow tests to have custom elements: - const prefixes = ['umb-', 'ufm-', 'test-']; - const isElementNameValid = prefixes.some((prefix) => elementName.startsWith(prefix)); + // check if the element name starts with an allowed prefix: + const isElementNameValid = ALLOWED_PREFIXES.some((prefix) => elementName.startsWith(prefix)); if (!isElementNameValid) { context.report({ diff --git a/src/Umbraco.Web.UI.Client/devops/eslint/rules/umb-class-prefix.cjs b/src/Umbraco.Web.UI.Client/devops/eslint/rules/umb-class-prefix.cjs index b9dce9c039..7856aec460 100644 --- a/src/Umbraco.Web.UI.Client/devops/eslint/rules/umb-class-prefix.cjs +++ b/src/Umbraco.Web.UI.Client/devops/eslint/rules/umb-class-prefix.cjs @@ -1,3 +1,5 @@ +const ALLOWED_PREFIXES = ['Umb', 'Example']; + /** @type {import('eslint').Rule.RuleModule} */ module.exports = { meta: { @@ -11,10 +13,10 @@ module.exports = { }, create: function (context) { function checkClassName(node) { - if (node.id && node.id.name && !node.id.name.startsWith('Umb')) { + if (node.id && node.id.name && !ALLOWED_PREFIXES.some((prefix) => node.id.name.startsWith(prefix))) { context.report({ node: node.id, - message: 'Class declaration should be prefixed with "Umb"', + message: `Class declaration should be prefixed with one of the following prefixes: ${ALLOWED_PREFIXES.join(', ')}`, }); } } diff --git a/src/Umbraco.Web.UI.Client/eslint.config.js b/src/Umbraco.Web.UI.Client/eslint.config.js index 56b90b5f3b..2bcbbb5b51 100644 --- a/src/Umbraco.Web.UI.Client/eslint.config.js +++ b/src/Umbraco.Web.UI.Client/eslint.config.js @@ -38,15 +38,6 @@ export default [ // Global config { - languageOptions: { - parserOptions: { - project: true, - tsconfigRootDir: import.meta.dirname, - }, - globals: { - ...globals.browser, - }, - }, plugins: { import: importPlugin, 'local-rules': localRules, @@ -77,13 +68,6 @@ export default [ excludedFileNames: ['umbraco-package'], }, ], - '@typescript-eslint/no-non-null-assertion': 'off', - '@typescript-eslint/no-explicit-any': 'warn', - '@typescript-eslint/no-unused-vars': 'error', - '@typescript-eslint/consistent-type-exports': 'error', - '@typescript-eslint/consistent-type-imports': 'error', - '@typescript-eslint/no-import-type-side-effects': 'warn', - '@typescript-eslint/no-deprecated': 'warn', 'jsdoc/check-tag-names': [ 'warn', { @@ -95,6 +79,27 @@ export default [ }, // Pattern-specific overrides + { + files: ['**/*.ts'], + languageOptions: { + parserOptions: { + project: true, + tsconfigRootDir: import.meta.dirname, + }, + globals: { + ...globals.browser, + }, + }, + rules: { + '@typescript-eslint/no-non-null-assertion': 'off', + '@typescript-eslint/no-explicit-any': 'warn', + '@typescript-eslint/no-unused-vars': 'error', + '@typescript-eslint/consistent-type-exports': 'error', + '@typescript-eslint/consistent-type-imports': 'error', + '@typescript-eslint/no-import-type-side-effects': 'warn', + '@typescript-eslint/no-deprecated': 'warn', + }, + }, { files: ['**/*.js'], ...tseslint.configs.disableTypeChecked, diff --git a/src/Umbraco.Web.UI.Client/examples/block-custom-view/block-custom-view.ts b/src/Umbraco.Web.UI.Client/examples/block-custom-view/block-custom-view.ts index 5da08329ab..e81e34764b 100644 --- a/src/Umbraco.Web.UI.Client/examples/block-custom-view/block-custom-view.ts +++ b/src/Umbraco.Web.UI.Client/examples/block-custom-view/block-custom-view.ts @@ -4,11 +4,8 @@ import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api'; import type { UmbBlockDataType } from '@umbraco-cms/backoffice/block'; import type { UmbBlockEditorCustomViewElement } from '@umbraco-cms/backoffice/block-custom-view'; -// eslint-disable-next-line local-rules/enforce-umb-prefix-on-element-name @customElement('example-block-custom-view') -// eslint-disable-next-line local-rules/umb-class-prefix export class ExampleBlockCustomView extends UmbElementMixin(LitElement) implements UmbBlockEditorCustomViewElement { - // @property({ attribute: false }) content?: UmbBlockDataType; diff --git a/src/Umbraco.Web.UI.Client/examples/dashboard-with-property-dataset/dataset-dashboard.ts b/src/Umbraco.Web.UI.Client/examples/dashboard-with-property-dataset/dataset-dashboard.ts index 20cc50236d..a03c0f9012 100644 --- a/src/Umbraco.Web.UI.Client/examples/dashboard-with-property-dataset/dataset-dashboard.ts +++ b/src/Umbraco.Web.UI.Client/examples/dashboard-with-property-dataset/dataset-dashboard.ts @@ -1,7 +1,7 @@ import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; import { css, html, customElement, LitElement } from '@umbraco-cms/backoffice/external/lit'; import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api'; -import { type UmbPropertyValueData, type UmbPropertyDatasetElement } from '@umbraco-cms/backoffice/property'; +import type { UmbPropertyValueData, UmbPropertyDatasetElement } from '@umbraco-cms/backoffice/property'; @customElement('example-dataset-dashboard') export class ExampleDatasetDashboard extends UmbElementMixin(LitElement) { diff --git a/src/Umbraco.Web.UI.Client/examples/icons/icons-dashboard.ts b/src/Umbraco.Web.UI.Client/examples/icons/icons-dashboard.ts index 5307bde407..920215eb85 100644 --- a/src/Umbraco.Web.UI.Client/examples/icons/icons-dashboard.ts +++ b/src/Umbraco.Web.UI.Client/examples/icons/icons-dashboard.ts @@ -2,9 +2,7 @@ import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; import { css, html, customElement, LitElement } from '@umbraco-cms/backoffice/external/lit'; import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api'; -// eslint-disable-next-line local-rules/enforce-umb-prefix-on-element-name @customElement('example-icons-dashboard') -// eslint-disable-next-line local-rules/umb-class-prefix export class ExampleIconsDashboard extends UmbElementMixin(LitElement) { override render() { return html` diff --git a/src/Umbraco.Web.UI.Client/examples/manifest-picker/manifest-picker-dashboard.ts b/src/Umbraco.Web.UI.Client/examples/manifest-picker/manifest-picker-dashboard.ts index 43be6cfdd4..e2af9cc43f 100644 --- a/src/Umbraco.Web.UI.Client/examples/manifest-picker/manifest-picker-dashboard.ts +++ b/src/Umbraco.Web.UI.Client/examples/manifest-picker/manifest-picker-dashboard.ts @@ -5,10 +5,8 @@ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; import type { UUISelectEvent } from '@umbraco-cms/backoffice/external/uui'; -// eslint-disable-next-line local-rules/enforce-umb-prefix-on-element-name @customElement('example-manifest-picker-dashboard') -// eslint-disable-next-line local-rules/enforce-element-suffix-on-element-class-name, local-rules/umb-class-prefix -export class ExampleManifestPickerDashboard extends UmbLitElement { +export class ExampleManifestPickerDashboardElement extends UmbLitElement { #options: Array