Refactor all .length === 0
patterns in JS (#30045)
This pattern comes of often during review, so let's fix it once and for all. Did not test, but changes are trivial enough imho. (cherry picked from commit 8fe26fb314f1710139728d9118b455fc6a16cce2)
This commit is contained in:
parent
c5745f9d24
commit
c55e30ff13
14 changed files with 31 additions and 40 deletions
|
@ -362,7 +362,7 @@ export async function updateIssuesMeta(url, action, issue_ids, id) {
|
|||
}
|
||||
|
||||
export function initRepoIssueComments() {
|
||||
if ($('.repository.view.issue .timeline').length === 0) return;
|
||||
if (!$('.repository.view.issue .timeline').length) return;
|
||||
|
||||
$('.re-request-review').on('click', async function (e) {
|
||||
e.preventDefault();
|
||||
|
@ -377,7 +377,7 @@ export function initRepoIssueComments() {
|
|||
|
||||
$(document).on('click', (event) => {
|
||||
const $urlTarget = $(':target');
|
||||
if ($urlTarget.length === 0) return;
|
||||
if (!$urlTarget.length) return;
|
||||
|
||||
const urlTargetId = $urlTarget.attr('id');
|
||||
if (!urlTargetId) return;
|
||||
|
@ -385,7 +385,7 @@ export function initRepoIssueComments() {
|
|||
|
||||
const $target = $(event.target);
|
||||
|
||||
if ($target.closest(`#${urlTargetId}`).length === 0) {
|
||||
if (!$target.closest(`#${urlTargetId}`).length) {
|
||||
const scrollPosition = $(window).scrollTop();
|
||||
window.location.hash = '';
|
||||
$(window).scrollTop(scrollPosition);
|
||||
|
@ -478,9 +478,7 @@ export function initRepoPullRequestReview() {
|
|||
}
|
||||
|
||||
// The following part is only for diff views
|
||||
if ($('.repository.pull.diff').length === 0) {
|
||||
return;
|
||||
}
|
||||
if (!$('.repository.pull.diff').length) return;
|
||||
|
||||
const $reviewBtn = $('.js-btn-review');
|
||||
const $panel = $reviewBtn.parent().find('.review-box-panel');
|
||||
|
@ -529,7 +527,7 @@ export function initRepoPullRequestReview() {
|
|||
|
||||
const $td = $ntr.find(`.add-comment-${side}`);
|
||||
const $commentCloud = $td.find('.comment-code-cloud');
|
||||
if ($commentCloud.length === 0 && !$ntr.find('button[name="pending_review"]').length) {
|
||||
if (!$commentCloud.length && !$ntr.find('button[name="pending_review"]').length) {
|
||||
try {
|
||||
const response = await GET($(this).closest('[data-new-comment-url]').attr('data-new-comment-url'));
|
||||
const html = await response.text();
|
||||
|
@ -626,7 +624,7 @@ export function initRepoIssueTitleEdit() {
|
|||
};
|
||||
|
||||
const pullrequest_target_update_url = $(this).attr('data-target-update-url');
|
||||
if ($editInput.val().length === 0 || $editInput.val() === $issueTitle.text()) {
|
||||
if (!$editInput.val().length || $editInput.val() === $issueTitle.text()) {
|
||||
$editInput.val($issueTitle.text());
|
||||
await pullrequest_targetbranch_change(pullrequest_target_update_url);
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue