Skip to content

Commit 2def046

Browse files
iOvergaardCopilotnielslyngsoe
authored
Eslint naming conventions (#19880)
* build(eslint): replace local rules with naming conventions * revert relative js extension imports * remove unused local rule * build(eslint): uses recommended setup for import plugin * chore(eslint): conver const to function to follow naming conventions * chore: removes old file * build(eslint): allows Ufm as prefix * build(eslint): allows 'name' and 'extensions' as exports (umbraco-package.ts) * build(eslint): typescript rules should ignore storybook * chore(eslint): ignores eslint for vite definitions * build(eslint): allows UPPER_CASE for properties * build(eslint): ignores umbraco-package.ts files (unconventional exports) * chore(storybook): fixes property editor stylesheet picker * build(eslint): allows Manifest as prefix on interfaces * build(eslint): allows underscore on protected members * build(eslint): allows Meta as prefix on interfaces * build(eslint): allows PascalCase for public members * build(eslint): disables enforcement of booleans with verbs for now as it is too harsh * chore(eslint): add private modifiers as required * deprecates invalid constant name to replace with Umb prefix * renames MediaValueType to comply with naming conventions * chore(eslint): disable naming conventions for local router-slot package * chore(eslint): follow naming conventions * chore(eslint): disable naming conventions for property editor interfaces * chore(eslint): follow naming conventions * chore(storybook): fix story * chore(eslint): follow naming conventions * build(eslint): allows `_host` as public variable * chore(eslint): follow naming conventions * build(eslint): allows double leading underscore on public members * build(eslint): matches #private and public modifiers * build(eslint): ignores language files * chore(eslint): ignores umbraco package file * chore(eslint): follow naming conventions * storybook lang * chore(eslint): follow naming conventions * chore(eslint): follow naming conventions * chore(eslint): make _manager a little more open * chore(eslint): some properties should be protected * Update src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-image-cropper/image-cropper.element.ts Co-authored-by: Copilot <[email protected]> * Update src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-image-cropper/image-cropper.element.ts Co-authored-by: Copilot <[email protected]> * Update src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-image-cropper/image-cropper.element.ts Co-authored-by: Copilot <[email protected]> * proxy type for UrlParametersRecord * _items deprecated property * bring back ConditionTypes type * bring back _items for trash bulk action * ignorer deprecated proxies * keep settingsDataContentTypeKey for satefy --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: Niels Lyngsø <[email protected]> Co-authored-by: Niels Lyngsø <[email protected]>
1 parent b3d5744 commit 2def046

File tree

268 files changed

+1053
-980
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

268 files changed

+1053
-980
lines changed

src/Umbraco.Web.UI.Client/.storybook/preview.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ class UmbStoryBookElement extends UmbLitElement {
140140
new UmbModalManagerContext(this);
141141
new UmbNotificationContext(this);
142142

143-
umbLocalizationRegistry.loadLanguage('en-us'); // register default language
143+
umbLocalizationRegistry.loadLanguage('en'); // register default language
144144

145145
this.consumeContext(UMB_APP_LANGUAGE_CONTEXT, (appLanguageContext) => {
146-
appLanguageContext.setLanguage('en-us'); // set default language
146+
appLanguageContext?.setLanguage('en'); // set default language
147147
});
148148
}
149149

src/Umbraco.Web.UI.Client/devops/eslint/rules/bad-type-import.cjs

Lines changed: 0 additions & 31 deletions
This file was deleted.

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

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/Umbraco.Web.UI.Client/devops/eslint/rules/exported-string-constant-naming.cjs

Lines changed: 0 additions & 54 deletions
This file was deleted.

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

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
11
'use strict';
22

3-
const badTypeImportRule = require('./devops/eslint/rules/bad-type-import.cjs');
43
const enforceElementSuffixOnElementClassNameRule = require('./devops/eslint/rules/enforce-element-suffix-on-element-class-name.cjs');
5-
const enforceUmbPrefixOnElementNameRule = require('./devops/eslint/rules/enforce-umb-prefix-on-element-name.cjs');
64
const enforceUmbracoExternalImportsRule = require('./devops/eslint/rules/enforce-umbraco-external-imports.cjs');
75
const ensureRelativeImportUseJsExtensionRule = require('./devops/eslint/rules/ensure-relative-import-use-js-extension.cjs');
8-
const exportedStringConstantNaming = require('./devops/eslint/rules/exported-string-constant-naming.cjs');
96
const noDirectApiImportRule = require('./devops/eslint/rules/no-direct-api-import.cjs');
107
const preferImportAliasesRule = require('./devops/eslint/rules/prefer-import-aliases.cjs');
118
const preferStaticStylesLastRule = require('./devops/eslint/rules/prefer-static-styles-last.cjs');
12-
const umbClassPrefixRule = require('./devops/eslint/rules/umb-class-prefix.cjs');
139
const noRelativeImportToImportMapModule = require('./devops/eslint/rules/no-relative-import-to-import-map-module.cjs');
1410

1511
module.exports = {
16-
'bad-type-import': badTypeImportRule,
1712
'enforce-element-suffix-on-element-class-name': enforceElementSuffixOnElementClassNameRule,
18-
'enforce-umb-prefix-on-element-name': enforceUmbPrefixOnElementNameRule,
1913
'enforce-umbraco-external-imports': enforceUmbracoExternalImportsRule,
2014
'ensure-relative-import-use-js-extension': ensureRelativeImportUseJsExtensionRule,
21-
'exported-string-constant-naming': exportedStringConstantNaming,
2215
'no-direct-api-import': noDirectApiImportRule,
2316
'prefer-import-aliases': preferImportAliasesRule,
2417
'prefer-static-styles-last': preferStaticStylesLastRule,
25-
'umb-class-prefix': umbClassPrefixRule,
2618
'no-relative-import-to-import-map-module': noRelativeImportToImportMapModule,
2719
};

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

Lines changed: 84 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ import jsdoc from 'eslint-plugin-jsdoc';
1414
export default [
1515
// Recommended config applied to all files
1616
js.configs.recommended,
17+
importPlugin.flatConfigs.recommended,
1718
...tseslint.configs.recommended,
1819
wcPlugin.configs['flat/recommended'],
1920
litPlugin.configs['flat/recommended'], // We use the non typescript version to allow types to be defined in the jsdoc comments. This will allow js docs as an alternative to typescript types.
2021
jsdoc.configs['flat/recommended'],
22+
...storybook.configs['flat/recommended'],
2123
localRules.configs.all,
2224
eslintPluginPrettierRecommended,
2325

@@ -39,35 +41,24 @@ export default [
3941
// Global config
4042
{
4143
plugins: {
42-
import: importPlugin,
4344
'local-rules': localRules,
4445
},
4546
rules: {
4647
semi: ['warn', 'always'],
4748
'prettier/prettier': ['warn', { endOfLine: 'auto' }],
48-
'no-unused-vars': 'off', //Let '@typescript-eslint/no-unused-vars' catch the errors to allow unused function parameters (ex: in interfaces)
4949
'no-var': 'error',
50-
...importPlugin.configs.recommended.rules,
5150
'import/namespace': 'off',
5251
'import/no-unresolved': 'off',
5352
'import/order': ['warn', { groups: ['builtin', 'parent', 'sibling', 'index', 'external'] }],
5453
'import/no-self-import': 'error',
5554
'import/no-cycle': ['error', { maxDepth: 6, allowUnsafeDynamicCyclicDependency: true }],
56-
'import/no-named-as-default': 'off', // Does not work with eslint 9
57-
'import/no-named-as-default-member': 'off', // Does not work with eslint 9
5855
'local-rules/prefer-static-styles-last': 'warn',
5956
'local-rules/enforce-umbraco-external-imports': [
6057
'error',
6158
{
6259
exceptions: ['@umbraco-cms', '@open-wc/testing', '@storybook', 'msw', '.', 'vite', 'uuid', 'diff'],
6360
},
6461
],
65-
'local-rules/exported-string-constant-naming': [
66-
'error',
67-
{
68-
excludedFileNames: ['umbraco-package'],
69-
},
70-
],
7162
'jsdoc/check-tag-names': [
7263
'warn',
7364
{
@@ -81,6 +72,7 @@ export default [
8172
// Pattern-specific overrides
8273
{
8374
files: ['**/*.ts'],
75+
ignores: ['.storybook', '**/*.stories.ts', '**/umbraco-package.ts', 'src/assets/lang/*.ts'],
8476
languageOptions: {
8577
parserOptions: {
8678
project: true,
@@ -90,14 +82,95 @@ export default [
9082
...globals.browser,
9183
},
9284
},
85+
...importPlugin.flatConfigs.typescript,
9386
rules: {
87+
'no-unused-vars': 'off', //Let '@typescript-eslint/no-unused-vars' catch the errors to allow unused function parameters (ex: in interfaces)
88+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
9489
'@typescript-eslint/no-non-null-assertion': 'off',
9590
'@typescript-eslint/no-explicit-any': 'warn',
9691
'@typescript-eslint/no-unused-vars': 'error',
9792
'@typescript-eslint/consistent-type-exports': 'error',
9893
'@typescript-eslint/consistent-type-imports': 'error',
9994
'@typescript-eslint/no-import-type-side-effects': 'warn',
10095
'@typescript-eslint/no-deprecated': 'warn',
96+
'@typescript-eslint/naming-convention': [
97+
'error',
98+
// All private members should be camelCase with leading underscore
99+
// This is to ensure that private members are not used outside the class, as they
100+
// are not part of the public API.
101+
// Example NOT OK: private myPrivateVariable
102+
// Example OK: private _myPrivateVariable
103+
{
104+
selector: 'memberLike',
105+
modifiers: ['private'],
106+
format: ['camelCase'],
107+
leadingUnderscore: 'require',
108+
trailingUnderscore: 'forbid',
109+
},
110+
// All public members and variables should be camelCase without leading underscore
111+
// Example: myPublicVariable, myPublicMethod
112+
{
113+
selector: ['variableLike', 'memberLike'],
114+
modifiers: ['public'],
115+
filter: {
116+
regex: '^_host$',
117+
match: false,
118+
},
119+
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
120+
leadingUnderscore: 'allowDouble',
121+
trailingUnderscore: 'forbid',
122+
},
123+
// All #private members and variables should be camelCase without leading underscore
124+
// Example: #myPublicVariable, #myPublicMethod
125+
{
126+
selector: ['variableLike', 'memberLike'],
127+
modifiers: ['#private'],
128+
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
129+
leadingUnderscore: 'allowDouble',
130+
trailingUnderscore: 'forbid',
131+
},
132+
// All protected members and variables should be camelCase with optional leading underscore (if needed to be pseudo-private)
133+
// Example: protected myPublicVariable, protected _myPublicMethod
134+
{
135+
selector: ['variableLike', 'memberLike'],
136+
modifiers: ['protected'],
137+
format: ['camelCase'],
138+
leadingUnderscore: 'allow',
139+
trailingUnderscore: 'forbid',
140+
},
141+
// Allow quoted properties, as they are often used in JSON or when the property name is not a valid identifier
142+
// This is to ensure that properties can be used in JSON or when the property name
143+
// is not a valid identifier (e.g. contains spaces or special characters)
144+
// Example: { "umb-some-component": UmbSomeComponent }
145+
{
146+
selector: ['objectLiteralProperty', 'typeProperty', 'enumMember'],
147+
modifiers: ['requiresQuotes'],
148+
format: null,
149+
},
150+
// All (exported) types should be PascalCase with leading 'Umb' or 'Example'
151+
// Example: UmbExampleType, ExampleTypeLike
152+
{
153+
selector: 'typeLike',
154+
modifiers: ['exported'],
155+
format: ['PascalCase'],
156+
prefix: ['Umb', 'Ufm', 'Manifest', 'Meta', 'Example']
157+
},
158+
// All exported string constants should be UPPER_CASE with leading 'UMB_'
159+
// Example: UMB_EXAMPLE_CONSTANT
160+
{
161+
selector: 'variable',
162+
modifiers: ['exported', 'const'],
163+
types: ['string', 'number', 'boolean'],
164+
format: ['UPPER_CASE'],
165+
prefix: ['UMB_'],
166+
},
167+
// Allow destructured variables to be named as they are in the object
168+
{
169+
selector: "variable",
170+
modifiers: ["destructured"],
171+
format: null,
172+
},
173+
],
101174
},
102175
},
103176
{
@@ -109,5 +182,4 @@ export default [
109182
},
110183
},
111184
},
112-
...storybook.configs['flat/recommended'],
113185
];

src/Umbraco.Web.UI.Client/src/apps/installer/error/installer-error.element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { UmbProblemDetails } from '@umbraco-cms/backoffice/resources';
88
@customElement('umb-installer-error')
99
export class UmbInstallerErrorElement extends UmbLitElement {
1010
@state()
11-
_error?: UmbProblemDetails;
11+
private _error?: UmbProblemDetails;
1212

1313
private _installerContext?: UmbInstallerContext;
1414

src/Umbraco.Web.UI.Client/src/apps/upgrader/upgrader-view.element.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class UmbUpgraderViewElement extends LitElement {
5252
5353
<p>Simply click <strong>continue</strong> below to be guided through the rest of the upgrade.</p>
5454
55-
<form id="authorizeUpgradeForm" @submit=${this._handleSubmit}>
55+
<form id="authorizeUpgradeForm" @submit=${this.#handleSubmit}>
5656
<p>
5757
<uui-button
5858
data-test="continue-button"
@@ -80,7 +80,7 @@ export class UmbUpgraderViewElement extends LitElement {
8080
return html` ${this.fetching ? html`<div class="center"><uui-loader></uui-loader></div>` : this._renderLayout()} `;
8181
}
8282

83-
_handleSubmit = async (e: SubmitEvent) => {
83+
#handleSubmit = async (e: SubmitEvent) => {
8484
e.preventDefault();
8585
this.dispatchEvent(new CustomEvent('onAuthorizeUpgrade', { detail: e, bubbles: true }));
8686
};

0 commit comments

Comments
 (0)