Skip to content

Commit 71057b5

Browse files
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 <[email protected]>
1 parent 0c22d51 commit 71057b5

File tree

13 files changed

+51
-48
lines changed

13 files changed

+51
-48
lines changed

src/Umbraco.Web.UI.Client/devops/eslint/rules/enforce-umb-prefix-on-element-name.cjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const ALLOWED_PREFIXES = ['umb-', 'ufm-', 'test-', 'example-'];
2+
13
/** @type {import('eslint').Rule.RuleModule} */
24
module.exports = {
35
meta: {
@@ -23,9 +25,8 @@ module.exports = {
2325
if (isCustomElementDecorator) {
2426
const elementName = node.arguments[0].value;
2527

26-
// check if the element name starts with 'umb-', 'ufm-', or 'test-', to be allow tests to have custom elements:
27-
const prefixes = ['umb-', 'ufm-', 'test-'];
28-
const isElementNameValid = prefixes.some((prefix) => elementName.startsWith(prefix));
28+
// check if the element name starts with an allowed prefix:
29+
const isElementNameValid = ALLOWED_PREFIXES.some((prefix) => elementName.startsWith(prefix));
2930

3031
if (!isElementNameValid) {
3132
context.report({

src/Umbraco.Web.UI.Client/devops/eslint/rules/umb-class-prefix.cjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const ALLOWED_PREFIXES = ['Umb', 'Example'];
2+
13
/** @type {import('eslint').Rule.RuleModule} */
24
module.exports = {
35
meta: {
@@ -11,10 +13,10 @@ module.exports = {
1113
},
1214
create: function (context) {
1315
function checkClassName(node) {
14-
if (node.id && node.id.name && !node.id.name.startsWith('Umb')) {
16+
if (node.id && node.id.name && !ALLOWED_PREFIXES.some((prefix) => node.id.name.startsWith(prefix))) {
1517
context.report({
1618
node: node.id,
17-
message: 'Class declaration should be prefixed with "Umb"',
19+
message: `Class declaration should be prefixed with one of the following prefixes: ${ALLOWED_PREFIXES.join(', ')}`,
1820
});
1921
}
2022
}

src/Umbraco.Web.UI.Client/eslint.config.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,6 @@ export default [
3838

3939
// Global config
4040
{
41-
languageOptions: {
42-
parserOptions: {
43-
project: true,
44-
tsconfigRootDir: import.meta.dirname,
45-
},
46-
globals: {
47-
...globals.browser,
48-
},
49-
},
5041
plugins: {
5142
import: importPlugin,
5243
'local-rules': localRules,
@@ -77,13 +68,6 @@ export default [
7768
excludedFileNames: ['umbraco-package'],
7869
},
7970
],
80-
'@typescript-eslint/no-non-null-assertion': 'off',
81-
'@typescript-eslint/no-explicit-any': 'warn',
82-
'@typescript-eslint/no-unused-vars': 'error',
83-
'@typescript-eslint/consistent-type-exports': 'error',
84-
'@typescript-eslint/consistent-type-imports': 'error',
85-
'@typescript-eslint/no-import-type-side-effects': 'warn',
86-
'@typescript-eslint/no-deprecated': 'warn',
8771
'jsdoc/check-tag-names': [
8872
'warn',
8973
{
@@ -95,6 +79,27 @@ export default [
9579
},
9680

9781
// Pattern-specific overrides
82+
{
83+
files: ['**/*.ts'],
84+
languageOptions: {
85+
parserOptions: {
86+
project: true,
87+
tsconfigRootDir: import.meta.dirname,
88+
},
89+
globals: {
90+
...globals.browser,
91+
},
92+
},
93+
rules: {
94+
'@typescript-eslint/no-non-null-assertion': 'off',
95+
'@typescript-eslint/no-explicit-any': 'warn',
96+
'@typescript-eslint/no-unused-vars': 'error',
97+
'@typescript-eslint/consistent-type-exports': 'error',
98+
'@typescript-eslint/consistent-type-imports': 'error',
99+
'@typescript-eslint/no-import-type-side-effects': 'warn',
100+
'@typescript-eslint/no-deprecated': 'warn',
101+
},
102+
},
98103
{
99104
files: ['**/*.js'],
100105
...tseslint.configs.disableTypeChecked,

src/Umbraco.Web.UI.Client/examples/block-custom-view/block-custom-view.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api';
44
import type { UmbBlockDataType } from '@umbraco-cms/backoffice/block';
55
import type { UmbBlockEditorCustomViewElement } from '@umbraco-cms/backoffice/block-custom-view';
66

7-
// eslint-disable-next-line local-rules/enforce-umb-prefix-on-element-name
87
@customElement('example-block-custom-view')
9-
// eslint-disable-next-line local-rules/umb-class-prefix
108
export class ExampleBlockCustomView extends UmbElementMixin(LitElement) implements UmbBlockEditorCustomViewElement {
11-
//
129
@property({ attribute: false })
1310
content?: UmbBlockDataType;
1411

src/Umbraco.Web.UI.Client/examples/dashboard-with-property-dataset/dataset-dashboard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
22
import { css, html, customElement, LitElement } from '@umbraco-cms/backoffice/external/lit';
33
import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api';
4-
import { type UmbPropertyValueData, type UmbPropertyDatasetElement } from '@umbraco-cms/backoffice/property';
4+
import type { UmbPropertyValueData, UmbPropertyDatasetElement } from '@umbraco-cms/backoffice/property';
55

66
@customElement('example-dataset-dashboard')
77
export class ExampleDatasetDashboard extends UmbElementMixin(LitElement) {

src/Umbraco.Web.UI.Client/examples/icons/icons-dashboard.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
22
import { css, html, customElement, LitElement } from '@umbraco-cms/backoffice/external/lit';
33
import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api';
44

5-
// eslint-disable-next-line local-rules/enforce-umb-prefix-on-element-name
65
@customElement('example-icons-dashboard')
7-
// eslint-disable-next-line local-rules/umb-class-prefix
86
export class ExampleIconsDashboard extends UmbElementMixin(LitElement) {
97
override render() {
108
return html`

src/Umbraco.Web.UI.Client/examples/manifest-picker/manifest-picker-dashboard.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
55
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
66
import type { UUISelectEvent } from '@umbraco-cms/backoffice/external/uui';
77

8-
// eslint-disable-next-line local-rules/enforce-umb-prefix-on-element-name
98
@customElement('example-manifest-picker-dashboard')
10-
// eslint-disable-next-line local-rules/enforce-element-suffix-on-element-class-name, local-rules/umb-class-prefix
11-
export class ExampleManifestPickerDashboard extends UmbLitElement {
9+
export class ExampleManifestPickerDashboardElement extends UmbLitElement {
1210
#options: Array<Option> = [];
1311

1412
@state()
@@ -90,10 +88,10 @@ export class ExampleManifestPickerDashboard extends UmbLitElement {
9088
];
9189
}
9290

93-
export default ExampleManifestPickerDashboard;
91+
export default ExampleManifestPickerDashboardElement;
9492

9593
declare global {
9694
interface HTMLElementTagNameMap {
97-
'example-manifest-picker-dashboard': ExampleManifestPickerDashboard;
95+
'example-manifest-picker-dashboard': ExampleManifestPickerDashboardElement;
9896
}
9997
}

src/Umbraco.Web.UI.Client/examples/sorter-with-nested-containers/sorter-dashboard.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import type { ExampleSorterGroup, ModelEntryType } from './sorter-group.js';
12
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
23
import { css, html, customElement, LitElement } from '@umbraco-cms/backoffice/external/lit';
34
import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api';
4-
import type { ExampleSorterGroup, ModelEntryType } from './sorter-group.js';
55

66
import './sorter-group.js';
7+
78
@customElement('example-sorter-dashboard')
89
export class ExampleSorterDashboard extends UmbElementMixin(LitElement) {
910
groupOneItems: ModelEntryType[] = [

src/Umbraco.Web.UI.Client/examples/sorter-with-nested-containers/sorter-group.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import type { ExampleSorterItem } from './sorter-item.js';
12
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
23
import { css, html, customElement, LitElement, repeat, property } from '@umbraco-cms/backoffice/external/lit';
34
import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api';
45
import { UmbSorterController } from '@umbraco-cms/backoffice/sorter';
56

67
import './sorter-item.js';
7-
import ExampleSorterItem from './sorter-item.js';
88

99
export type ModelEntryType = {
1010
name: string;

src/Umbraco.Web.UI.Client/examples/sorter-with-two-containers/sorter-dashboard.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import type { ModelEntryType } from './sorter-group.js';
12
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
23
import { css, html, customElement, LitElement } from '@umbraco-cms/backoffice/external/lit';
34
import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api';
4-
import type { ModelEntryType } from './sorter-group.js';
55

66
import './sorter-group.js';
7+
78
@customElement('example-sorter-dashboard')
89
export class ExampleSorterDashboard extends UmbElementMixin(LitElement) {
910
groupOneItems: ModelEntryType[] = [

0 commit comments

Comments
 (0)