Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forbid variables containing jQuery collections not having the $ prefix #29839

Merged
merged 3 commits into from Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.yaml
Expand Up @@ -487,7 +487,7 @@ rules:
no-jquery/no-visibility: [2]
no-jquery/no-when: [2]
no-jquery/no-wrap: [2]
no-jquery/variable-pattern: [0]
no-jquery/variable-pattern: [2]
no-label-var: [2]
no-labels: [0] # handled by no-restricted-syntax
no-lone-blocks: [2]
Expand Down
1 change: 1 addition & 0 deletions web_src/js/components/RepoBranchTagSelector.vue
Expand Up @@ -123,6 +123,7 @@ const sfc = {
return -1;
},
scrollToActive() {
// eslint-disable-next-line no-jquery/variable-pattern
let el = this.$refs[`listItem${this.active}`];
yardenshoham marked this conversation as resolved.
Show resolved Hide resolved
if (!el || !el.length) return;
if (Array.isArray(el)) {
Expand Down
16 changes: 8 additions & 8 deletions web_src/js/features/common-global.js
Expand Up @@ -231,8 +231,8 @@ export function initDropzone(el) {
init() {
this.on('success', (file, data) => {
file.uuid = data.uuid;
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
$dropzone.find('.files').append(input);
const $input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
$dropzone.find('.files').append($input);
// Create a "Copy Link" element, to conveniently copy the image
// or file link as Markdown to the clipboard
const copyLinkElement = document.createElement('div');
Expand Down Expand Up @@ -305,15 +305,15 @@ export function initGlobalLinkActions() {
filter += `#${$this.attr('data-modal-id')}`;
}

const dialog = $(`.delete.modal${filter}`);
dialog.find('.name').text($this.data('name'));
const $dialog = $(`.delete.modal${filter}`);
$dialog.find('.name').text($this.data('name'));
for (const [key, value] of Object.entries(dataArray)) {
if (key && key.startsWith('data')) {
dialog.find(`.${key}`).text(value);
$dialog.find(`.${key}`).text(value);
}
}

dialog.modal({
$dialog.modal({
closable: false,
onApprove: async () => {
if ($this.data('type') === 'form') {
Expand Down Expand Up @@ -380,8 +380,8 @@ function initGlobalShowModal() {
$attrTarget.text(attrib.value); // FIXME: it should be more strict here, only handle div/span/p
}
}
const colorPickers = $modal.find('.color-picker');
if (colorPickers.length > 0) {
const $colorPickers = $modal.find('.color-picker');
if ($colorPickers.length > 0) {
initCompColorPicker(); // FIXME: this might cause duplicate init
}
$modal.modal('setting', {
Expand Down
42 changes: 21 additions & 21 deletions web_src/js/features/comp/LabelEdit.js
Expand Up @@ -6,23 +6,23 @@ function isExclusiveScopeName(name) {
}

function updateExclusiveLabelEdit(form) {
const nameInput = $(`${form} .label-name-input`);
const exclusiveField = $(`${form} .label-exclusive-input-field`);
const exclusiveCheckbox = $(`${form} .label-exclusive-input`);
const exclusiveWarning = $(`${form} .label-exclusive-warning`);
const $nameInput = $(`${form} .label-name-input`);
const $exclusiveField = $(`${form} .label-exclusive-input-field`);
const $exclusiveCheckbox = $(`${form} .label-exclusive-input`);
const $exclusiveWarning = $(`${form} .label-exclusive-warning`);

if (isExclusiveScopeName(nameInput.val())) {
exclusiveField.removeClass('muted');
exclusiveField.removeAttr('aria-disabled');
if (exclusiveCheckbox.prop('checked') && exclusiveCheckbox.data('exclusive-warn')) {
exclusiveWarning.removeClass('gt-hidden');
if (isExclusiveScopeName($nameInput.val())) {
$exclusiveField.removeClass('muted');
$exclusiveField.removeAttr('aria-disabled');
if ($exclusiveCheckbox.prop('checked') && $exclusiveCheckbox.data('exclusive-warn')) {
$exclusiveWarning.removeClass('gt-hidden');
} else {
exclusiveWarning.addClass('gt-hidden');
$exclusiveWarning.addClass('gt-hidden');
}
} else {
exclusiveField.addClass('muted');
exclusiveField.attr('aria-disabled', 'true');
exclusiveWarning.addClass('gt-hidden');
$exclusiveField.addClass('muted');
$exclusiveField.attr('aria-disabled', 'true');
$exclusiveWarning.addClass('gt-hidden');
}
}

Expand All @@ -46,18 +46,18 @@ export function initCompLabelEdit(selector) {
$('.edit-label .color-picker').minicolors('value', $(this).data('color'));
$('#label-modal-id').val($(this).data('id'));

const nameInput = $('.edit-label .label-name-input');
nameInput.val($(this).data('title'));
const $nameInput = $('.edit-label .label-name-input');
$nameInput.val($(this).data('title'));

const isArchivedCheckbox = $('.edit-label .label-is-archived-input');
isArchivedCheckbox.prop('checked', this.hasAttribute('data-is-archived'));
const $isArchivedCheckbox = $('.edit-label .label-is-archived-input');
$isArchivedCheckbox.prop('checked', this.hasAttribute('data-is-archived'));

const exclusiveCheckbox = $('.edit-label .label-exclusive-input');
exclusiveCheckbox.prop('checked', this.hasAttribute('data-exclusive'));
const $exclusiveCheckbox = $('.edit-label .label-exclusive-input');
$exclusiveCheckbox.prop('checked', this.hasAttribute('data-exclusive'));
// Warn when label was previously not exclusive and used in issues
exclusiveCheckbox.data('exclusive-warn',
$exclusiveCheckbox.data('exclusive-warn',
$(this).data('num-issues') > 0 &&
(!this.hasAttribute('data-exclusive') || !isExclusiveScopeName(nameInput.val())));
(!this.hasAttribute('data-exclusive') || !isExclusiveScopeName($nameInput.val())));
updateExclusiveLabelEdit('.edit-label');

$('.edit-label .label-desc-input').val($(this).data('description'));
Expand Down
22 changes: 11 additions & 11 deletions web_src/js/features/comp/ReactionSelector.js
Expand Up @@ -17,21 +17,21 @@ export function initCompReactionSelector($parent) {

const data = await res.json();
if (data && (data.html || data.empty)) {
const content = $(this).closest('.content');
let react = content.find('.segment.reactions');
if ((!data.empty || data.html === '') && react.length > 0) {
react.remove();
const $content = $(this).closest('.content');
let $react = $content.find('.segment.reactions');
if ((!data.empty || data.html === '') && $react.length > 0) {
$react.remove();
}
if (!data.empty) {
const attachments = content.find('.segment.bottom:first');
react = $(data.html);
if (attachments.length > 0) {
react.insertBefore(attachments);
const $attachments = $content.find('.segment.bottom:first');
$react = $(data.html);
if ($attachments.length > 0) {
$react.insertBefore($attachments);
} else {
react.appendTo(content);
$react.appendTo($content);
}
react.find('.dropdown').dropdown();
initCompReactionSelector(react);
$react.find('.dropdown').dropdown();
initCompReactionSelector($react);
}
}
});
Expand Down
20 changes: 10 additions & 10 deletions web_src/js/features/notification.js
Expand Up @@ -45,17 +45,17 @@ async function receiveUpdateCount(event) {
}

export function initNotificationCount() {
const notificationCount = $('.notification_count');
const $notificationCount = $('.notification_count');

if (!notificationCount.length) {
if (!$notificationCount.length) {
return;
}

let usingPeriodicPoller = false;
const startPeriodicPoller = (timeout, lastCount) => {
if (timeout <= 0 || !Number.isFinite(timeout)) return;
usingPeriodicPoller = true;
lastCount = lastCount ?? notificationCount.text();
lastCount = lastCount ?? $notificationCount.text();
setTimeout(async () => {
await updateNotificationCountWithCallback(startPeriodicPoller, timeout, lastCount);
}, timeout);
Expand Down Expand Up @@ -143,8 +143,8 @@ async function updateNotificationCountWithCallback(callback, timeout, lastCount)
}

async function updateNotificationTable() {
const notificationDiv = $('#notification_div');
if (notificationDiv.length > 0) {
const $notificationDiv = $('#notification_div');
if ($notificationDiv.length > 0) {
try {
const params = new URLSearchParams(window.location.search);
params.set('div-only', true);
Expand All @@ -158,7 +158,7 @@ async function updateNotificationTable() {

const data = await response.text();
if ($(data).data('sequence-number') === notificationSequenceNumber) {
notificationDiv.replaceWith(data);
$notificationDiv.replaceWith(data);
initNotificationsTable();
}
} catch (error) {
Expand All @@ -177,14 +177,14 @@ async function updateNotificationCount() {

const data = await response.json();

const notificationCount = $('.notification_count');
const $notificationCount = $('.notification_count');
if (data.new === 0) {
notificationCount.addClass('gt-hidden');
$notificationCount.addClass('gt-hidden');
} else {
notificationCount.removeClass('gt-hidden');
$notificationCount.removeClass('gt-hidden');
}

notificationCount.text(`${data.new}`);
$notificationCount.text(`${data.new}`);

return `${data.new}`;
} catch (error) {
Expand Down
12 changes: 6 additions & 6 deletions web_src/js/features/repo-diff.js
Expand Up @@ -97,10 +97,10 @@ function initRepoDiffConversationForm() {
const data = await response.text();

if ($(this).closest('.conversation-holder').length) {
const conversation = $(data);
$(this).closest('.conversation-holder').replaceWith(conversation);
conversation.find('.dropdown').dropdown();
initCompReactionSelector(conversation);
const $conversation = $(data);
$(this).closest('.conversation-holder').replaceWith($conversation);
$conversation.find('.dropdown').dropdown();
initCompReactionSelector($conversation);
} else {
window.location.reload();
}
Expand Down Expand Up @@ -209,8 +209,8 @@ function initRepoDiffShowMore() {

export function initRepoDiffView() {
initRepoDiffConversationForm();
const diffFileList = $('#diff-file-list');
if (diffFileList.length === 0) return;
const $diffFileList = $('#diff-file-list');
if ($diffFileList.length === 0) return;
initDiffFileTree();
initDiffCommitSelect();
initRepoDiffShowMore();
Expand Down
20 changes: 10 additions & 10 deletions web_src/js/features/repo-editor.js
Expand Up @@ -15,17 +15,17 @@ function initEditPreviewTab($form) {
const $this = $(this);
let context = `${$this.data('context')}/`;
const mode = $this.data('markup-mode') || 'comment';
const treePathEl = $form.find('input#tree_path');
if (treePathEl.length > 0) {
context += treePathEl.val();
const $treePathEl = $form.find('input#tree_path');
if ($treePathEl.length > 0) {
context += $treePathEl.val();
}
context = context.substring(0, context.lastIndexOf('/'));

const formData = new FormData();
formData.append('mode', mode);
formData.append('context', context);
formData.append('text', $form.find(`.tab[data-tab="${$tabMenu.data('write')}"] textarea`).val());
formData.append('file_path', treePathEl.val());
formData.append('file_path', $treePathEl.val());
try {
const response = await POST($this.data('url'), {data: formData});
const data = await response.text();
Expand Down Expand Up @@ -78,11 +78,11 @@ export function initRepoEditor() {
const joinTreePath = ($fileNameEl) => {
const parts = [];
$('.breadcrumb span.section').each(function () {
const element = $(this);
if (element.find('a').length) {
parts.push(element.find('a').text());
const $element = $(this);
if ($element.find('a').length) {
parts.push($element.find('a').text());
} else {
parts.push(element.text());
parts.push($element.text());
}
});
if ($fileNameEl.val()) parts.push($fileNameEl.val());
Expand Down Expand Up @@ -181,6 +181,6 @@ export function renderPreviewPanelContent($panelPreviewer, data) {
$panelPreviewer.html(data);
initMarkupContent();

const refIssues = $panelPreviewer.find('p .ref-issue');
attachRefIssueContextPopup(refIssues);
const $refIssues = $panelPreviewer.find('p .ref-issue');
attachRefIssueContextPopup($refIssues);
}
8 changes: 4 additions & 4 deletions web_src/js/features/repo-graph.js
Expand Up @@ -63,10 +63,10 @@ export function initRepoGraphGit() {
(async () => {
const response = await GET(String(ajaxUrl));
const html = await response.text();
const div = $(html);
$('#pagination').html(div.find('#pagination').html());
$('#rel-container').html(div.find('#rel-container').html());
$('#rev-container').html(div.find('#rev-container').html());
const $div = $(html);
$('#pagination').html($div.find('#pagination').html());
$('#rel-container').html($div.find('#rel-container').html());
$('#rev-container').html($div.find('#rev-container').html());
$('#loading-indicator').addClass('gt-hidden');
$('#rel-container').removeClass('gt-hidden');
$('#rev-container').removeClass('gt-hidden');
Expand Down