From 98349a188931106404a9ae4be2a3e6e81ab392b6 Mon Sep 17 00:00:00 2001 From: silverwind Date: Tue, 16 Jul 2024 12:14:27 +0200 Subject: [PATCH] [PORT] Enable `no-jquery/no-class-state` (gitea#31639) Just 4 validations and I specifically tested this by selecting/unselecting issue labels. Co-authored-by: Giteabot --- Clean port. Fixed two additional warnings (cherry picked from commit 3a7454df7a518f810fbeb34b9d784e7c29d173ff) --- .eslintrc.yaml | 2 +- web_src/js/features/repo-legacy.js | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index e591592d97..6600ae189b 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -354,7 +354,7 @@ rules: no-jquery/no-box-model: [2] no-jquery/no-browser: [2] no-jquery/no-camel-case: [2] - no-jquery/no-class-state: [0] + no-jquery/no-class-state: [2] no-jquery/no-class: [0] no-jquery/no-clone: [2] no-jquery/no-closest: [0] diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index d3566fb121..d9aa881127 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -64,7 +64,7 @@ export function initRepoCommentForm() { function initBranchSelector() { const $selectBranch = $('.ui.select-branch'); const $branchMenu = $selectBranch.find('.reference-list-menu'); - const $isNewIssue = $branchMenu.hasClass('new-issue'); + const $isNewIssue = $branchMenu[0]?.classList.contains('new-issue'); $branchMenu.find('.item:not(.no-select)').on('click', async function () { const selectedValue = $(this).data('id'); const editMode = $('#editing_mode').val(); @@ -132,7 +132,7 @@ export function initRepoCommentForm() { $listMenu.find('.item:not(.no-select)').on('click', function (e) { e.preventDefault(); - if ($(this).hasClass('ban-change')) { + if (this.classList.contains('ban-change')) { return false; } @@ -147,7 +147,7 @@ export function initRepoCommentForm() { if (this.getAttribute('data-scope') !== scope) { return true; } - if (this !== clickedItem && !$(this).hasClass('checked')) { + if (this !== clickedItem && !this.classList.contains('checked')) { return true; } } else if (this !== clickedItem) { @@ -155,7 +155,7 @@ export function initRepoCommentForm() { return true; } - if ($(this).hasClass('checked')) { + if (this.classList.contains('checked')) { $(this).removeClass('checked'); $(this).find('.octicon-check').addClass('tw-invisible'); if (hasUpdateAction) { @@ -194,7 +194,7 @@ export function initRepoCommentForm() { const listIds = []; $(this).parent().find('.item').each(function () { - if ($(this).hasClass('checked')) { + if (this.classList.contains('checked')) { listIds.push($(this).data('id')); $($(this).data('id-selector')).removeClass('tw-hidden'); } else { @@ -605,7 +605,7 @@ function initRepoIssueCommentEdit() { const quote = $(`#${target}`).text().replace(/\n/g, '\n> '); const content = `> ${quote}\n\n`; let editor; - if ($(this).hasClass('quote-reply-diff')) { + if (this.classList.contains('quote-reply-diff')) { const $replyBtn = $(this).closest('.comment-code-cloud').find('button.comment-form-reply'); editor = await handleReply($replyBtn); } else {