Skip to content

Commit 3cd6494

Browse files
Forbid variables containing jQuery collections not having the $ prefix (#29839)
See https://github.com/wikimedia/eslint-plugin-no-jquery/blob/master/docs/rules/variable-pattern.md --------- Signed-off-by: Yarden Shoham <[email protected]> Co-authored-by: silverwind <[email protected]>
1 parent a889381 commit 3cd6494

14 files changed

+193
-193
lines changed

.eslintrc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ rules:
487487
no-jquery/no-visibility: [2]
488488
no-jquery/no-when: [2]
489489
no-jquery/no-wrap: [2]
490-
no-jquery/variable-pattern: [0]
490+
no-jquery/variable-pattern: [2]
491491
no-label-var: [2]
492492
no-labels: [0] # handled by no-restricted-syntax
493493
no-lone-blocks: [2]

web_src/js/components/RepoBranchTagSelector.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ const sfc = {
123123
return -1;
124124
},
125125
scrollToActive() {
126-
let el = this.$refs[`listItem${this.active}`];
126+
let el = this.$refs[`listItem${this.active}`]; // eslint-disable-line no-jquery/variable-pattern
127127
if (!el || !el.length) return;
128128
if (Array.isArray(el)) {
129129
el = el[0];

web_src/js/features/common-global.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ export function initDropzone(el) {
231231
init() {
232232
this.on('success', (file, data) => {
233233
file.uuid = data.uuid;
234-
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
235-
$dropzone.find('.files').append(input);
234+
const $input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
235+
$dropzone.find('.files').append($input);
236236
// Create a "Copy Link" element, to conveniently copy the image
237237
// or file link as Markdown to the clipboard
238238
const copyLinkElement = document.createElement('div');
@@ -305,15 +305,15 @@ export function initGlobalLinkActions() {
305305
filter += `#${$this.attr('data-modal-id')}`;
306306
}
307307

308-
const dialog = $(`.delete.modal${filter}`);
309-
dialog.find('.name').text($this.data('name'));
308+
const $dialog = $(`.delete.modal${filter}`);
309+
$dialog.find('.name').text($this.data('name'));
310310
for (const [key, value] of Object.entries(dataArray)) {
311311
if (key && key.startsWith('data')) {
312-
dialog.find(`.${key}`).text(value);
312+
$dialog.find(`.${key}`).text(value);
313313
}
314314
}
315315

316-
dialog.modal({
316+
$dialog.modal({
317317
closable: false,
318318
onApprove: async () => {
319319
if ($this.data('type') === 'form') {
@@ -380,8 +380,8 @@ function initGlobalShowModal() {
380380
$attrTarget.text(attrib.value); // FIXME: it should be more strict here, only handle div/span/p
381381
}
382382
}
383-
const colorPickers = $modal.find('.color-picker');
384-
if (colorPickers.length > 0) {
383+
const $colorPickers = $modal.find('.color-picker');
384+
if ($colorPickers.length > 0) {
385385
initCompColorPicker(); // FIXME: this might cause duplicate init
386386
}
387387
$modal.modal('setting', {

web_src/js/features/comp/LabelEdit.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ function isExclusiveScopeName(name) {
66
}
77

88
function updateExclusiveLabelEdit(form) {
9-
const nameInput = $(`${form} .label-name-input`);
10-
const exclusiveField = $(`${form} .label-exclusive-input-field`);
11-
const exclusiveCheckbox = $(`${form} .label-exclusive-input`);
12-
const exclusiveWarning = $(`${form} .label-exclusive-warning`);
9+
const $nameInput = $(`${form} .label-name-input`);
10+
const $exclusiveField = $(`${form} .label-exclusive-input-field`);
11+
const $exclusiveCheckbox = $(`${form} .label-exclusive-input`);
12+
const $exclusiveWarning = $(`${form} .label-exclusive-warning`);
1313

14-
if (isExclusiveScopeName(nameInput.val())) {
15-
exclusiveField.removeClass('muted');
16-
exclusiveField.removeAttr('aria-disabled');
17-
if (exclusiveCheckbox.prop('checked') && exclusiveCheckbox.data('exclusive-warn')) {
18-
exclusiveWarning.removeClass('gt-hidden');
14+
if (isExclusiveScopeName($nameInput.val())) {
15+
$exclusiveField.removeClass('muted');
16+
$exclusiveField.removeAttr('aria-disabled');
17+
if ($exclusiveCheckbox.prop('checked') && $exclusiveCheckbox.data('exclusive-warn')) {
18+
$exclusiveWarning.removeClass('gt-hidden');
1919
} else {
20-
exclusiveWarning.addClass('gt-hidden');
20+
$exclusiveWarning.addClass('gt-hidden');
2121
}
2222
} else {
23-
exclusiveField.addClass('muted');
24-
exclusiveField.attr('aria-disabled', 'true');
25-
exclusiveWarning.addClass('gt-hidden');
23+
$exclusiveField.addClass('muted');
24+
$exclusiveField.attr('aria-disabled', 'true');
25+
$exclusiveWarning.addClass('gt-hidden');
2626
}
2727
}
2828

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

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

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

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

6363
$('.edit-label .label-desc-input').val($(this).data('description'));

web_src/js/features/comp/ReactionSelector.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ export function initCompReactionSelector($parent) {
1717

1818
const data = await res.json();
1919
if (data && (data.html || data.empty)) {
20-
const content = $(this).closest('.content');
21-
let react = content.find('.segment.reactions');
22-
if ((!data.empty || data.html === '') && react.length > 0) {
23-
react.remove();
20+
const $content = $(this).closest('.content');
21+
let $react = $content.find('.segment.reactions');
22+
if ((!data.empty || data.html === '') && $react.length > 0) {
23+
$react.remove();
2424
}
2525
if (!data.empty) {
26-
const attachments = content.find('.segment.bottom:first');
27-
react = $(data.html);
28-
if (attachments.length > 0) {
29-
react.insertBefore(attachments);
26+
const $attachments = $content.find('.segment.bottom:first');
27+
$react = $(data.html);
28+
if ($attachments.length > 0) {
29+
$react.insertBefore($attachments);
3030
} else {
31-
react.appendTo(content);
31+
$react.appendTo($content);
3232
}
33-
react.find('.dropdown').dropdown();
34-
initCompReactionSelector(react);
33+
$react.find('.dropdown').dropdown();
34+
initCompReactionSelector($react);
3535
}
3636
}
3737
});

web_src/js/features/notification.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ async function receiveUpdateCount(event) {
4545
}
4646

4747
export function initNotificationCount() {
48-
const notificationCount = $('.notification_count');
48+
const $notificationCount = $('.notification_count');
4949

50-
if (!notificationCount.length) {
50+
if (!$notificationCount.length) {
5151
return;
5252
}
5353

5454
let usingPeriodicPoller = false;
5555
const startPeriodicPoller = (timeout, lastCount) => {
5656
if (timeout <= 0 || !Number.isFinite(timeout)) return;
5757
usingPeriodicPoller = true;
58-
lastCount = lastCount ?? notificationCount.text();
58+
lastCount = lastCount ?? $notificationCount.text();
5959
setTimeout(async () => {
6060
await updateNotificationCountWithCallback(startPeriodicPoller, timeout, lastCount);
6161
}, timeout);
@@ -143,8 +143,8 @@ async function updateNotificationCountWithCallback(callback, timeout, lastCount)
143143
}
144144

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

159159
const data = await response.text();
160160
if ($(data).data('sequence-number') === notificationSequenceNumber) {
161-
notificationDiv.replaceWith(data);
161+
$notificationDiv.replaceWith(data);
162162
initNotificationsTable();
163163
}
164164
} catch (error) {
@@ -177,14 +177,14 @@ async function updateNotificationCount() {
177177

178178
const data = await response.json();
179179

180-
const notificationCount = $('.notification_count');
180+
const $notificationCount = $('.notification_count');
181181
if (data.new === 0) {
182-
notificationCount.addClass('gt-hidden');
182+
$notificationCount.addClass('gt-hidden');
183183
} else {
184-
notificationCount.removeClass('gt-hidden');
184+
$notificationCount.removeClass('gt-hidden');
185185
}
186186

187-
notificationCount.text(`${data.new}`);
187+
$notificationCount.text(`${data.new}`);
188188

189189
return `${data.new}`;
190190
} catch (error) {

web_src/js/features/repo-diff.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ function initRepoDiffConversationForm() {
9797
const data = await response.text();
9898

9999
if ($(this).closest('.conversation-holder').length) {
100-
const conversation = $(data);
101-
$(this).closest('.conversation-holder').replaceWith(conversation);
102-
conversation.find('.dropdown').dropdown();
103-
initCompReactionSelector(conversation);
100+
const $conversation = $(data);
101+
$(this).closest('.conversation-holder').replaceWith($conversation);
102+
$conversation.find('.dropdown').dropdown();
103+
initCompReactionSelector($conversation);
104104
} else {
105105
window.location.reload();
106106
}
@@ -209,8 +209,8 @@ function initRepoDiffShowMore() {
209209

210210
export function initRepoDiffView() {
211211
initRepoDiffConversationForm();
212-
const diffFileList = $('#diff-file-list');
213-
if (diffFileList.length === 0) return;
212+
const $diffFileList = $('#diff-file-list');
213+
if ($diffFileList.length === 0) return;
214214
initDiffFileTree();
215215
initDiffCommitSelect();
216216
initRepoDiffShowMore();

web_src/js/features/repo-editor.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ function initEditPreviewTab($form) {
1515
const $this = $(this);
1616
let context = `${$this.data('context')}/`;
1717
const mode = $this.data('markup-mode') || 'comment';
18-
const treePathEl = $form.find('input#tree_path');
19-
if (treePathEl.length > 0) {
20-
context += treePathEl.val();
18+
const $treePathEl = $form.find('input#tree_path');
19+
if ($treePathEl.length > 0) {
20+
context += $treePathEl.val();
2121
}
2222
context = context.substring(0, context.lastIndexOf('/'));
2323

2424
const formData = new FormData();
2525
formData.append('mode', mode);
2626
formData.append('context', context);
2727
formData.append('text', $form.find(`.tab[data-tab="${$tabMenu.data('write')}"] textarea`).val());
28-
formData.append('file_path', treePathEl.val());
28+
formData.append('file_path', $treePathEl.val());
2929
try {
3030
const response = await POST($this.data('url'), {data: formData});
3131
const data = await response.text();
@@ -78,11 +78,11 @@ export function initRepoEditor() {
7878
const joinTreePath = ($fileNameEl) => {
7979
const parts = [];
8080
$('.breadcrumb span.section').each(function () {
81-
const element = $(this);
82-
if (element.find('a').length) {
83-
parts.push(element.find('a').text());
81+
const $element = $(this);
82+
if ($element.find('a').length) {
83+
parts.push($element.find('a').text());
8484
} else {
85-
parts.push(element.text());
85+
parts.push($element.text());
8686
}
8787
});
8888
if ($fileNameEl.val()) parts.push($fileNameEl.val());
@@ -181,6 +181,6 @@ export function renderPreviewPanelContent($panelPreviewer, data) {
181181
$panelPreviewer.html(data);
182182
initMarkupContent();
183183

184-
const refIssues = $panelPreviewer.find('p .ref-issue');
185-
attachRefIssueContextPopup(refIssues);
184+
const $refIssues = $panelPreviewer.find('p .ref-issue');
185+
attachRefIssueContextPopup($refIssues);
186186
}

web_src/js/features/repo-graph.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ export function initRepoGraphGit() {
6363
(async () => {
6464
const response = await GET(String(ajaxUrl));
6565
const html = await response.text();
66-
const div = $(html);
67-
$('#pagination').html(div.find('#pagination').html());
68-
$('#rel-container').html(div.find('#rel-container').html());
69-
$('#rev-container').html(div.find('#rev-container').html());
66+
const $div = $(html);
67+
$('#pagination').html($div.find('#pagination').html());
68+
$('#rel-container').html($div.find('#rel-container').html());
69+
$('#rev-container').html($div.find('#rev-container').html());
7070
$('#loading-indicator').addClass('gt-hidden');
7171
$('#rel-container').removeClass('gt-hidden');
7272
$('#rev-container').removeClass('gt-hidden');

0 commit comments

Comments
 (0)