Skip to content

Commit a5c570c

Browse files
authored
Remove jQuery .map() and enable eslint rules for it (#29272)
- Use case in `repo-commit` was tested until the point where the POST request was sent with the same payload. - Use case in `repo-legacy` was tested completely with comment editing. - `jquery/no-fade` was disabled as well to stay in sync with `no-jquery/no-fade`, had no violations.
1 parent 3f73eab commit a5c570c

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

.eslintrc.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ rules:
296296
jquery/no-delegate: [2]
297297
jquery/no-each: [0]
298298
jquery/no-extend: [2]
299-
jquery/no-fade: [0]
299+
jquery/no-fade: [2]
300300
jquery/no-filter: [0]
301301
jquery/no-find: [0]
302302
jquery/no-global-eval: [2]
@@ -309,7 +309,7 @@ rules:
309309
jquery/no-is-function: [2]
310310
jquery/no-is: [0]
311311
jquery/no-load: [2]
312-
jquery/no-map: [0]
312+
jquery/no-map: [2]
313313
jquery/no-merge: [2]
314314
jquery/no-param: [2]
315315
jquery/no-parent: [0]
@@ -451,7 +451,7 @@ rules:
451451
no-jquery/no-load: [2]
452452
no-jquery/no-map-collection: [0]
453453
no-jquery/no-map-util: [2]
454-
no-jquery/no-map: [0]
454+
no-jquery/no-map: [2]
455455
no-jquery/no-merge: [2]
456456
no-jquery/no-node-name: [2]
457457
no-jquery/no-noop: [2]

web_src/js/features/repo-commit.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,15 @@ export function initRepoEllipsisButton() {
1414
}
1515

1616
export function initRepoCommitLastCommitLoader() {
17-
const entryMap = {};
18-
19-
const entries = $('table#repo-files-table tr.notready')
20-
.map((_, v) => {
21-
entryMap[$(v).attr('data-entryname')] = $(v);
22-
return $(v).attr('data-entryname');
23-
})
24-
.get();
17+
const notReadyEls = document.querySelectorAll('table#repo-files-table tr.notready');
18+
if (!notReadyEls.length) return;
2519

26-
if (entries.length === 0) {
27-
return;
20+
const entryMap = {};
21+
const entries = [];
22+
for (const el of notReadyEls) {
23+
const entryname = el.getAttribute('data-entryname');
24+
entryMap[entryname] = $(el);
25+
entries.push(entryname);
2826
}
2927

3028
const lastCommitLoaderURL = $('table#repo-files-table').data('lastCommitLoaderUrl');

web_src/js/features/repo-legacy.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -398,17 +398,14 @@ async function onEditContent(event) {
398398
}
399399
};
400400

401-
const saveAndRefresh = (dz, $dropzone) => {
401+
const saveAndRefresh = (dz) => {
402402
showElem($renderContent);
403403
hideElem($editContentZone);
404-
const $attachments = $dropzone.find('.files').find('[name=files]').map(function () {
405-
return $(this).val();
406-
}).get();
407404
$.post($editContentZone.attr('data-update-url'), {
408405
_csrf: csrfToken,
409406
content: comboMarkdownEditor.value(),
410407
context: $editContentZone.attr('data-context'),
411-
files: $attachments,
408+
files: dz.files.map((file) => file.uuid),
412409
}, (data) => {
413410
if (!data.content) {
414411
$renderContent.html($('#no-content').html());
@@ -452,7 +449,7 @@ async function onEditContent(event) {
452449
});
453450
$editContentZone.find('.save.button').on('click', (e) => {
454451
e.preventDefault();
455-
saveAndRefresh(dz, $dropzone);
452+
saveAndRefresh(dz);
456453
});
457454
} else {
458455
comboMarkdownEditor = getComboMarkdownEditor($editContentZone.find('.combo-markdown-editor'));

0 commit comments

Comments
 (0)