chore: enable several no-jquery rules (#7408)

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7408
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Reviewed-by: 0ko <0ko@noreply.codeberg.org>
This commit is contained in:
Gusted 2025-04-01 16:08:51 +00:00
commit c497ef9e81
13 changed files with 50 additions and 47 deletions

View file

@ -318,8 +318,9 @@ export default tseslint.config(
'no-jquery/no-data': [0],
'no-jquery/no-deferred': [2],
'no-jquery/no-delegate': [2],
'no-jquery/no-done-fail': [2],
'no-jquery/no-each-collection': [0],
'no-jquery/no-each-util': [0],
'no-jquery/no-each-util': [2],
'no-jquery/no-each': [0],
'no-jquery/no-error-shorthand': [2],
'no-jquery/no-error': [2],
@ -331,6 +332,7 @@ export default tseslint.config(
'no-jquery/no-find-collection': [0],
'no-jquery/no-find-util': [2],
'no-jquery/no-find': [0],
'no-jquery/no-fx': [2],
'no-jquery/no-fx-interval': [2],
'no-jquery/no-global-eval': [2],
'no-jquery/no-global-selector': [0],
@ -350,7 +352,7 @@ export default tseslint.config(
'no-jquery/no-live': [2],
'no-jquery/no-load-shorthand': [2],
'no-jquery/no-load': [2],
'no-jquery/no-map-collection': [0],
'no-jquery/no-map-collection': [2],
'no-jquery/no-map-util': [2],
'no-jquery/no-map': [2],
'no-jquery/no-merge': [2],
@ -374,12 +376,12 @@ export default tseslint.config(
'no-jquery/no-selector-prop': [2],
'no-jquery/no-serialize': [2],
'no-jquery/no-size': [2],
'no-jquery/no-sizzle': [0],
'no-jquery/no-sizzle': [2],
'no-jquery/no-slide': [2],
'no-jquery/no-sub': [2],
'no-jquery/no-support': [2],
'no-jquery/no-text': [0],
'no-jquery/no-trigger': [0],
'no-jquery/no-trigger': [2],
'no-jquery/no-trim': [2],
'no-jquery/no-type': [2],
'no-jquery/no-unique': [2],

View file

@ -98,14 +98,14 @@ const sfc = {
$(`#${this.branchForm} input[name="refType"]`).val('branch');
}
if (this.submitForm) {
$(`#${this.branchForm}`).trigger('submit');
document.getElementById(this.branchForm).requestSubmit();
}
this.menuVisible = false;
}
},
createNewBranch() {
if (!this.showCreateNewBranch) return;
$(this.$refs.newBranchForm).trigger('submit');
this.$refs.newBranchForm.requestSubmit();
},
focusSearchField() {
nextTick(() => {

View file

@ -175,7 +175,7 @@ export function initAdminCommon() {
onUsePagedSearchChange();
}
});
$('#auth_type').trigger('change');
document.getElementById('auth_type').dispatchEvent(new Event('change'));
document.getElementById('security_protocol')?.addEventListener('change', onSecurityProtocolChange);
document.getElementById('use_paged_search')?.addEventListener('change', onUsePagedSearchChange);
document.getElementById('oauth2_provider')?.addEventListener('change', () => onOAuth2Change(true));
@ -200,10 +200,12 @@ export function initAdminCommon() {
}
if (document.querySelector('.admin.authentication')) {
$('#auth_name').on('input', function () {
const authNameEl = document.getElementById('auth_name');
authNameEl.addEventListener('input', (el) => {
// appSubUrl is either empty or is a path that starts with `/` and doesn't have a trailing slash.
document.getElementById('oauth2-callback-url').textContent = `${window.location.origin}${appSubUrl}/user/oauth2/${encodeURIComponent(this.value)}/callback`;
}).trigger('input');
document.getElementById('oauth2-callback-url').textContent = `${window.location.origin}${appSubUrl}/user/oauth2/${encodeURIComponent(el.target.value)}/callback`;
});
authNameEl.dispatchEvent(new Event('input'));
}
// Notice

View file

@ -57,7 +57,7 @@ export function initGlobalEnterQuickSubmit() {
export function initGlobalButtonClickOnEnter() {
$(document).on('keypress', 'div.ui.button,span.ui.button', (e) => {
if (e.code === ' ' || e.code === 'Enter') {
$(e.target).trigger('click');
e.target.click();
e.preventDefault();
}
});
@ -314,7 +314,7 @@ export function initGlobalLinkActions() {
closable: false,
onApprove: async () => {
if ($this.data('type') === 'form') {
$($this.data('form')).trigger('submit');
document.querySelector($this.data('form')).requestSubmit();
return;
}
if ($this[0].getAttribute('hx-confirm')) {

View file

@ -38,7 +38,7 @@ export function initCompLabelEdit(selector) {
form.reportValidity();
return false;
}
$('.new-label.form').trigger('submit');
document.querySelector('.new-label.form').requestSubmit();
},
}).modal('show');
return false;
@ -75,7 +75,7 @@ export function initCompLabelEdit(selector) {
form.reportValidity();
return false;
}
$('.edit-label.form').trigger('submit');
document.querySelector('.edit-label.form').requestSubmit();
},
}).modal('show');
return false;

View file

@ -23,7 +23,7 @@ export function initCompReactionSelector($parent) {
$react.remove();
}
if (!data.empty) {
const $attachments = $content.find('.segment.bottom:first');
const $attachments = $content.find('.segment.bottom').first();
$react = $(data.html);
if ($attachments.length > 0) {
$react.insertBefore($attachments);

View file

@ -10,13 +10,12 @@ export function initOrgTeamSearchRepoBox() {
url: `${appSubUrl}/repo/search?q={query}&uid=${$searchRepoBox.data('uid')}`,
onResponse(response) {
const items = [];
$.each(response.data, (_i, item) => {
for (const item of response.data) {
items.push({
title: item.repository.full_name.split('/')[1],
description: item.repository.full_name,
});
});
}
return {results: items};
},
},

View file

@ -184,7 +184,8 @@ export function initRepoCodeView() {
$('html, body').scrollTop($first.offset().top - 200);
}
}
}).trigger('hashchange');
});
window.dispatchEvent(new Event('hashchange'));
}
$(document).on('click', '.fold-file', ({currentTarget}) => {
invertFileFolding(currentTarget.closest('.file-content'), currentTarget);

View file

@ -33,25 +33,25 @@ export function initRepoArchiveLinks() {
}
export function initRepoCloneLink() {
const $repoCloneSsh = $('#repo-clone-ssh');
const $repoCloneHttps = $('#repo-clone-https');
const $inputLink = $('#repo-clone-url');
const repoCloneSSH = document.getElementById('repo-clone-ssh');
const repoCloneHTTPS = document.getElementById('repo-clone-https');
const inputLink = document.getElementById('repo-clone-url');
if ((!$repoCloneSsh.length && !$repoCloneHttps.length) || !$inputLink.length) {
if ((!repoCloneSSH && !repoCloneHTTPS) || !inputLink) {
return;
}
$repoCloneSsh.on('click', () => {
repoCloneSSH.addEventListener('click', () => {
localStorage.setItem('repo-clone-protocol', 'ssh');
window.updateCloneStates();
});
$repoCloneHttps.on('click', () => {
repoCloneHTTPS.addEventListener('click', () => {
localStorage.setItem('repo-clone-protocol', 'https');
window.updateCloneStates();
});
$inputLink.on('focus', () => {
$inputLink.trigger('select');
inputLink.addEventListener('focus', () => {
inputLink.select();
});
}

View file

@ -185,7 +185,7 @@ export function initRepoEditor() {
$('#edit-empty-content-modal')
.modal({
onApprove() {
$('.edit.form').trigger('submit');
document.querySelector('.edit.form').requestSubmit();
},
})
.modal('show');

View file

@ -37,27 +37,27 @@ export function initRepoIssueTimeTracking() {
$('.issue-start-time-modal').modal({
duration: 200,
onApprove() {
$('#add_time_manual_form').trigger('submit');
document.getElementById('add_time_manual_form').requestSubmit();
},
}).modal('show');
$('.issue-start-time-modal input').on('keydown', (e) => {
if ((e.keyCode || e.key) === 13) {
$('#add_time_manual_form').trigger('submit');
document.getElementById('add_time_manual_form').requestSubmit();
}
});
});
$(document).on('click', '.issue-start-time, .issue-stop-time', () => {
$('#toggle_stopwatch_form').trigger('submit');
document.getElementById('toggle_stopwatch_form').requestSubmit();
});
$(document).on('click', '.issue-cancel-time', () => {
$('#cancel_stopwatch_form').trigger('submit');
document.getElementById('cancel_stopwatch_form').requestSubmit();
});
$(document).on('click', 'button.issue-delete-time', function () {
const sel = `.issue-delete-time-modal[data-id="${$(this).data('id')}"]`;
$(sel).modal({
duration: 200,
onApprove() {
$(`${sel} form`).trigger('submit');
document.getElementById(`${sel} form`).requestSubmit();
},
}).modal('show');
});
@ -139,7 +139,7 @@ export function initRepoIssueSidebarList() {
const filteredResponse = {success: true, results: []};
const currIssueId = $('#new-dependency-drop-list').data('issue-id');
// Parse the response from the api to work with our dropdown
$.each(response, (_i, issue) => {
for (const [_, issue] of Object.entries(response)) {
// Don't list current issue in the dependency list.
if (issue.id === currIssueId) {
return;
@ -149,7 +149,7 @@ export function initRepoIssueSidebarList() {
}<div class="text small tw-break-anywhere">${htmlEscape(issue.repository.full_name)}</div>`,
value: issue.id,
});
});
}
return filteredResponse;
},
cache: false,
@ -247,7 +247,7 @@ export function initRepoIssueDependencyDelete() {
onApprove: () => {
$('#removeDependencyID').val(id);
$('#dependencyType').val(type);
$('#removeDependencyForm').trigger('submit');
document.getElementById('removeDependencyForm').requestSubmit();
},
}).modal('show');
});
@ -345,12 +345,12 @@ export function initRepoIssueReferenceRepositorySearch() {
url: `${appSubUrl}/repo/search?q={query}&limit=20`,
onResponse(response) {
const filteredResponse = {success: true, results: []};
$.each(response.data, (_r, repo) => {
for (const repo of response.data) {
filteredResponse.results.push({
name: htmlEscape(repo.repository.full_name),
value: repo.repository.full_name,
});
});
}
return filteredResponse;
},
cache: false,
@ -369,9 +369,9 @@ export function initRepoIssueWipTitle() {
$('.title_wip_desc > a').on('click', (e) => {
e.preventDefault();
const $issueTitle = $('#issue_title');
$issueTitle.trigger('focus');
const value = $issueTitle.val().trim().toUpperCase();
const issueTitleEl = document.getElementById('issue_title');
issueTitleEl.focus();
const value = issueTitleEl.value.trim().toUpperCase();
const wipPrefixes = $('.title_wip_desc').data('wip-prefixes');
for (const prefix of wipPrefixes) {
@ -380,7 +380,7 @@ export function initRepoIssueWipTitle() {
}
}
$issueTitle.val(`${wipPrefixes[0]} ${$issueTitle.val()}`);
issueTitleEl.value = `${wipPrefixes[0]} ${issueTitleEl.value}`;
});
}

View file

@ -55,13 +55,12 @@ export function initRepoSettingSearchTeamBox() {
headers: {'X-Csrf-Token': csrfToken},
onResponse(response) {
const items = [];
$.each(response.data, (_i, item) => {
for (const item of response.data) {
items.push({
title: item.name,
description: `${item.permission} access`, // TODO: translate this string
});
});
}
return {results: items};
},
},

View file

@ -32,12 +32,12 @@ export function initRepoTemplateSearch() {
value: '',
});
// Parse the response from the api to work with our dropdown
$.each(response.data, (_r, repo) => {
for (const repo of response.data) {
filteredResponse.results.push({
name: htmlEscape(repo.repository.full_name),
value: repo.repository.id,
});
});
}
return filteredResponse;
},
cache: false,