Skip to content

Commit

Permalink
[TASK] Eliminate eslint warnings
Browse files Browse the repository at this point in the history
Also raise the fixed linters to error level in order
to not introduce similar errors again.

The linter @typescript-eslint/no-explicit-any is disabled for
now, in order for errors to be visible at first glance.

Resolves: #101645
Releases: main, 12.4
Change-Id: I48229f148298ac13acd6d12deb55d606a3c7ef59
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80504
Tested-by: core-ci <typo3@b13.com>
Tested-by: Benjamin Franzke <ben@bnf.dev>
Reviewed-by: Benjamin Franzke <ben@bnf.dev>
  • Loading branch information
bnf committed Aug 10, 2023
1 parent 51b843c commit d4e26a3
Show file tree
Hide file tree
Showing 39 changed files with 143 additions and 154 deletions.
9 changes: 5 additions & 4 deletions Build/.eslintrc.json
Expand Up @@ -29,9 +29,10 @@
"rules": {
"@typescript-eslint/indent": ["error", 2],
"@typescript-eslint/no-inferrable-types": "off", // we want to keep explicit type casting
"@typescript-eslint/ban-types": "warn",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-this-alias": "warn",
"@typescript-eslint/ban-types": "error",
"@typescript-eslint/no-explicit-any": "off", // too many warnings/errors for now, needs be fixed step by step
"@typescript-eslint/no-this-alias": "error",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/member-ordering": "error",
"@typescript-eslint/naming-convention": [
"error",
Expand All @@ -50,7 +51,7 @@
"eol-last": "error",
"guard-for-in": "error",
"lit/no-duplicate-template-bindings": "error",
"lit/no-native-attributes": "warn",
"lit/no-native-attributes": "error",
"lit/no-invalid-escape-sequences": "error",
"lit/no-legacy-imports": "error",
"lit/no-useless-template-literals": "error",
Expand Down
2 changes: 1 addition & 1 deletion Build/Sources/TypeScript/backend/action-dispatcher.ts
Expand Up @@ -34,7 +34,7 @@ declare type ActionDispatchArgument = string | HTMLElement | Event;
* data-dispatch-disabled>
*/
class ActionDispatcher {
private delegates: {[key: string]: Function} = {};
private delegates: {[key: string]: (...args: ActionDispatchArgument[]) => void} = {};

public constructor() {
this.createDelegates();
Expand Down
Expand Up @@ -34,7 +34,7 @@ export class ImmediateActionElement extends HTMLElement {
return ['action', 'args', 'args-list'];
}

private static async getDelegate(action: string): Promise<Function> {
private static async getDelegate(action: string): Promise<(...args: any[]) => void> {
switch (action) {
case 'TYPO3.ModuleMenu.App.refreshMenu':
const { default: moduleMenuApp } = await import('@typo3/backend/module-menu');
Expand Down Expand Up @@ -82,7 +82,7 @@ export class ImmediateActionElement extends HTMLElement {
if (!this.action) {
throw new Error('Missing mandatory action attribute');
}
ImmediateActionElement.getDelegate(this.action).then((callback: Function): void => callback(...this.args));
ImmediateActionElement.getDelegate(this.action).then((callback): void => callback(...this.args));
}
}

Expand Down
22 changes: 14 additions & 8 deletions Build/Sources/TypeScript/backend/event/trigger-request.ts
Expand Up @@ -22,10 +22,12 @@ class TriggerRequest extends InteractionRequest {
if (this === ancestorRequest) {
return true;
}
let request: InteractionRequest = this;
while (request.parentRequest instanceof InteractionRequest) {
request = request.parentRequest;
if (request === ancestorRequest) {
for (
let parentRequest = this.parentRequest;
parentRequest instanceof InteractionRequest;
parentRequest = parentRequest.parentRequest
) {
if (parentRequest === ancestorRequest) {
return true;
}
}
Expand All @@ -36,13 +38,17 @@ class TriggerRequest extends InteractionRequest {
if (types.includes(this.type)) {
return true;
}
let request: InteractionRequest = this;
while (request.parentRequest instanceof InteractionRequest) {
request = request.parentRequest;
if (types.includes(request.type)) {

for (
let parentRequest = this.parentRequest;
parentRequest instanceof InteractionRequest;
parentRequest = parentRequest.parentRequest
) {
if (types.includes(parentRequest.type)) {
return true;
}
}

return false;
}
}
Expand Down
12 changes: 5 additions & 7 deletions Build/Sources/TypeScript/backend/form-engine-review.ts
Expand Up @@ -83,11 +83,10 @@ class FormEngineReview {
* Initialize the events
*/
public initialize(): void {
const me: any = this;
const $document: any = $(document);

DocumentService.ready().then((): void => {
FormEngineReview.attachButtonToModuleHeader(me);
FormEngineReview.attachButtonToModuleHeader(this);
});
$document.on('t3-formengine-postfieldvalidation', this.checkForReviewableField);
}
Expand All @@ -96,7 +95,6 @@ class FormEngineReview {
* Checks if fields have failed validation. In such case, the markup is rendered and the toggle button is unlocked.
*/
public checkForReviewableField = (): void => {
const me: any = this;
const $invalidFields: any = FormEngineReview.findInvalidField();
const toggleButton: HTMLElement = document.querySelector('.' + this.toggleButtonClass);
if (toggleButton === null) {
Expand All @@ -106,15 +104,15 @@ class FormEngineReview {
if ($invalidFields.length > 0) {
const $list: any = $('<div />', { class: 'list-group' });

$invalidFields.each(function(this: Element): void {
const $field: any = $(this);
$invalidFields.each((index: number, element: Element): void => {
const $field: any = $(element);
const $input: JQuery = $field.find('[data-formengine-validation-rules]');

const link = document.createElement('a');
link.classList.add('list-group-item');
link.href = '#';
link.textContent = $field.find(me.labelSelector).text() || $field.find(me.legendSelector).text();
link.addEventListener('click', (e: Event) => me.switchToField(e, $input));
link.textContent = $field.find(this.labelSelector).text() || $field.find(this.legendSelector).text();
link.addEventListener('click', (e: Event) => this.switchToField(e, $input));

$list.append(link);
});
Expand Down
4 changes: 2 additions & 2 deletions Build/Sources/TypeScript/backend/form-engine-validation.ts
Expand Up @@ -143,7 +143,7 @@ export default (function() {
/**
* Format field value
*/
FormEngineValidation.formatValue = function(type: string, value: string|number, config: Object): string {
FormEngineValidation.formatValue = function(type: string, value: string|number, config: object): string {
let theString = '';
let parsedInt: number;
let theTime: Date;
Expand Down Expand Up @@ -752,7 +752,7 @@ export default (function() {
* @param {String} value
* @returns {Object}
*/
FormEngineValidation.pol = function(foreign: string, value: string): Object {
FormEngineValidation.pol = function(foreign: string, value: string): object {
// @todo deprecate
// eslint-disable-next-line no-eval
return eval(((foreign == '-') ? '-' : '') + value);
Expand Down
Expand Up @@ -164,24 +164,22 @@ class FilesControlContainer extends HTMLElement {
}

private registerToggle(): void {
const me = this;
new RegularEvent('click', function(this: HTMLElement, e: Event) {
new RegularEvent('click', (e: Event, targetElement: HTMLElement): void => {
e.preventDefault();
e.stopImmediatePropagation();

me.loadRecordDetails(this.closest(Selectors.toggleSelector).parentElement.dataset.objectId);
this.loadRecordDetails(targetElement.closest(Selectors.toggleSelector).parentElement.dataset.objectId);
}).delegateTo(this.container, `${Selectors.toggleSelector} .form-irre-header-cell:not(${Selectors.controlSectionSelector}`);
}

private registerSort(): void {
const me = this;
new RegularEvent('click', function(this: HTMLElement, e: Event) {
new RegularEvent('click', (e: Event, targetElement: HTMLElement): void => {
e.preventDefault();
e.stopImmediatePropagation();

me.changeSortingByButton(
(<HTMLDivElement>this.closest('[data-object-id]')).dataset.objectId,
<SortDirections>this.dataset.direction,
this.changeSortingByButton(
(<HTMLDivElement>targetElement.closest('[data-object-id]')).dataset.objectId,
<SortDirections>targetElement.dataset.direction,
);
}).delegateTo(this.container, Selectors.controlSectionSelector + ' [data-action="sort"]');
}
Expand Down Expand Up @@ -281,22 +279,21 @@ class FilesControlContainer extends HTMLElement {
}

private registerInfoButton(): void {
new RegularEvent('click', function(this: HTMLElement, e: Event) {
new RegularEvent('click', (e: Event, targetElement: HTMLElement): void => {
e.preventDefault();
e.stopImmediatePropagation();

InfoWindow.showItem(this.dataset.infoTable, this.dataset.infoUid);
InfoWindow.showItem(targetElement.dataset.infoTable, targetElement.dataset.infoUid);
}).delegateTo(this.container, Selectors.infoWindowButton);
}

private registerDeleteButton(): void {
const me = this;
new RegularEvent('click', function(this: HTMLElement, e: Event) {
new RegularEvent('click', (e: Event, targetElement: HTMLElement): void => {
e.preventDefault();
e.stopImmediatePropagation();

const title = TYPO3.lang['label.confirm.delete_record.title'] || 'Delete this record?';
const content = (TYPO3.lang['label.confirm.delete_record.content'] || 'Are you sure you want to delete the record \'%s\'?').replace('%s', this.dataset.recordInfo);
const content = (TYPO3.lang['label.confirm.delete_record.content'] || 'Are you sure you want to delete the record \'%s\'?').replace('%s', targetElement.dataset.recordInfo);
Modal.confirm(title, content, Severity.warning, [
{
text: TYPO3.lang['buttons.confirm.delete_record.no'] || 'Cancel',
Expand All @@ -310,7 +307,7 @@ class FilesControlContainer extends HTMLElement {
btnClass: 'btn-warning',
name: 'yes',
trigger: (e: Event, modal: ModalElement): void => {
me.deleteRecord((<HTMLDivElement>this.closest('[data-object-id]')).dataset.objectId);
this.deleteRecord((<HTMLDivElement>targetElement.closest('[data-object-id]')).dataset.objectId);
modal.hideModal();
}
},
Expand All @@ -319,29 +316,28 @@ class FilesControlContainer extends HTMLElement {
}

private registerSynchronizeLocalize(): void {
const me = this;
new RegularEvent('click', function(this: HTMLElement, e: Event) {
new RegularEvent('click', (e: Event, targetElement: HTMLElement): void => {
e.preventDefault();
e.stopImmediatePropagation();

me.ajaxDispatcher.send(
me.ajaxDispatcher.newRequest(me.ajaxDispatcher.getEndpoint('file_reference_synchronizelocalize')),
[me.container.dataset.objectGroup, this.dataset.type],
this.ajaxDispatcher.send(
this.ajaxDispatcher.newRequest(this.ajaxDispatcher.getEndpoint('file_reference_synchronizelocalize')),
[this.container.dataset.objectGroup, targetElement.dataset.type],
).then(async (response: InlineResponseInterface): Promise<void> => {
me.recordsContainer.insertAdjacentHTML('beforeend', response.data);
this.recordsContainer.insertAdjacentHTML('beforeend', response.data);

const objectIdPrefix = me.container.dataset.objectGroup + Separators.structureSeparator;
const objectIdPrefix = this.container.dataset.objectGroup + Separators.structureSeparator;
for (const itemUid of response.compilerInput.delete) {
me.deleteRecord(objectIdPrefix + itemUid, true);
this.deleteRecord(objectIdPrefix + itemUid, true);
}

for (const item of Object.values(response.compilerInput.localize)) {
if (typeof item.remove !== 'undefined') {
const removableRecordContainer = me.getFileReferenceContainer(objectIdPrefix + item.remove);
const removableRecordContainer = this.getFileReferenceContainer(objectIdPrefix + item.remove);
removableRecordContainer.parentElement.removeChild(removableRecordContainer);
}

me.memorizeAddRecord(item.uid, null);
this.memorizeAddRecord(item.uid, null);
}
});
}).delegateTo(this.container, Selectors.synchronizeLocalizeRecordButtonSelector);
Expand Down

0 comments on commit d4e26a3

Please sign in to comment.