Skip to content

Commit

Permalink
[TASK] Implement @typescript-eslint/no-array-delete rule
Browse files Browse the repository at this point in the history
The eslint configuration now takes the rule
`@typescript-eslint/no-array-delete` [1] into account, prohibiting
element removal from an array via `delete`. The problem with `delete` is
that the element to be removed is in fact replaced with an `empty` slot,
effectible keeping the array's size. Using `splice()` [2] is the
preferred way to remove elements from an array.

[1] https://typescript-eslint.io/rules/no-array-delete/
[2] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice

Resolves: #103375
Releases: main, 12.4
Change-Id: Ic742a43d44cbd8c5cc323f629cc82ad606a9858f
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83443
Tested-by: core-ci <typo3@b13.com>
Tested-by: Andreas Kienast <a.fernandez@scripting-base.de>
Reviewed-by: Andreas Kienast <a.fernandez@scripting-base.de>
  • Loading branch information
andreaskienast committed Mar 12, 2024
1 parent 6055db0 commit 3451b50
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions Build/.eslintrc.js
Expand Up @@ -48,6 +48,7 @@ module.exports = {
"format": ["PascalCase"]
}
],
"@typescript-eslint/no-array-delete": "error",
"curly": "error",
"default-case": "error",
"dot-notation": "error",
Expand Down
Expand Up @@ -465,7 +465,7 @@ class FilesControlContainer extends HTMLElement {
const records = Utility.trimExplode(',', (<HTMLInputElement>formField).value);
const indexOfRemoveUid = records.indexOf(objectUid);
if (indexOfRemoveUid > -1) {
delete records[indexOfRemoveUid];
records.splice(indexOfRemoveUid, 1);

(<HTMLInputElement>formField).value = records.join(',');
(<HTMLInputElement>formField).classList.add('has-change');
Expand Down
Expand Up @@ -683,7 +683,7 @@ class InlineControlContainer {
const records = Utility.trimExplode(',', (<HTMLInputElement>formField).value);
const indexOfRemoveUid = records.indexOf(objectUid);
if (indexOfRemoveUid > -1) {
delete records[indexOfRemoveUid];
records.splice(indexOfRemoveUid, 1);

(<HTMLInputElement>formField).value = records.join(',');
(<HTMLInputElement>formField).classList.add('has-change');
Expand Down
Expand Up @@ -413,7 +413,7 @@ class SiteLanguageContainer extends HTMLElement {
const records = Utility.trimExplode(',', (<HTMLInputElement>formField).value);
const indexOfRemoveUid = records.indexOf(objectUid);
if (indexOfRemoveUid > -1) {
delete records[indexOfRemoveUid];
records.splice(indexOfRemoveUid, 1);

(<HTMLInputElement>formField).value = records.join(',');
(<HTMLInputElement>formField).classList.add('has-change');
Expand Down
Expand Up @@ -110,7 +110,7 @@ export class AjaxDispatcher {
element.type = 'text/css';
element.href = stylesheetFile;
document.querySelector('head').appendChild(element);
delete json.stylesheetFiles[index];
json.stylesheetFiles.splice(index, 1);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Build/Sources/TypeScript/install/ajax/ajax-queue.ts
Expand Up @@ -66,7 +66,7 @@ class AjaxQueue {
this.requests.push(request);
return response.then(payload.onfulfilled, payload.onrejected).then((): void => {
const idx = this.requests.indexOf(request);
delete this.requests[idx];
this.requests.splice(idx, 1);
});
}

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -10,4 +10,4 @@
*
* The TYPO3 project - inspiring people to share!
*/
import AjaxRequest from"@typo3/core/ajax/ajax-request.js";class AjaxQueue{constructor(){this.requests=[],this.requestCount=0,this.threshold=5,this.queue=[]}add(e){this.queue.push(e),this.handleNext()}flush(){this.queue=[],this.requests.forEach((e=>e.abort())),this.requests=[]}handleNext(){this.queue.length>0&&this.requestCount<this.threshold&&(this.incrementRequestCount(),this.sendRequest(this.queue.shift()).finally((()=>{this.decrementRequestCount(),this.handleNext()})))}async sendRequest(e){const t=new AjaxRequest(e.url);let s;return s=void 0!==e.method&&"POST"===e.method.toUpperCase()?t.post(e.data):t.withQueryArguments(e.data||{}).get(),this.requests.push(t),s.then(e.onfulfilled,e.onrejected).then((()=>{const e=this.requests.indexOf(t);delete this.requests[e]}))}incrementRequestCount(){this.requestCount++}decrementRequestCount(){this.requestCount>0&&this.requestCount--}}export default new AjaxQueue;
import AjaxRequest from"@typo3/core/ajax/ajax-request.js";class AjaxQueue{constructor(){this.requests=[],this.requestCount=0,this.threshold=5,this.queue=[]}add(e){this.queue.push(e),this.handleNext()}flush(){this.queue=[],this.requests.forEach((e=>e.abort())),this.requests=[]}handleNext(){this.queue.length>0&&this.requestCount<this.threshold&&(this.incrementRequestCount(),this.sendRequest(this.queue.shift()).finally((()=>{this.decrementRequestCount(),this.handleNext()})))}async sendRequest(e){const t=new AjaxRequest(e.url);let s;return s=void 0!==e.method&&"POST"===e.method.toUpperCase()?t.post(e.data):t.withQueryArguments(e.data||{}).get(),this.requests.push(t),s.then(e.onfulfilled,e.onrejected).then((()=>{const e=this.requests.indexOf(t);this.requests.splice(e,1)}))}incrementRequestCount(){this.requestCount++}decrementRequestCount(){this.requestCount>0&&this.requestCount--}}export default new AjaxQueue;

0 comments on commit 3451b50

Please sign in to comment.