From 0e4b14cd3b10f78a6a0686424a0ee0dc7b94c7a0 Mon Sep 17 00:00:00 2001 From: Navin Kumar Date: Thu, 14 Nov 2019 10:26:41 +0000 Subject: [PATCH 1/4] Replaced var with const and let. --- app/assets/javascripts/notes.js | 90 ++++++++++++++++----------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/app/assets/javascripts/notes.js b/app/assets/javascripts/notes.js index defa278c089254..ef7377eca497a3 100644 --- a/app/assets/javascripts/notes.js +++ b/app/assets/javascripts/notes.js @@ -224,7 +224,7 @@ export default class Notes { } keydownNoteText(e) { - var $textarea, + let $textarea, discussionNoteForm, editNote, myLastNote, @@ -318,14 +318,14 @@ export default class Notes { /** * Increase @pollingInterval up to 120 seconds on every function call, - * if `shouldReset` has a truthy value, 'null' or 'undefined' the variable + * if `shouldReset` has a truthy value, 'null' or 'undefined' the letiable * will reset to @basePollingInterval. * * Note: this function is used to gradually increase the polling interval * if there aren't new notes coming from the server */ setPollingInterval(shouldReset) { - var nthInterval; + let nthInterval; if (shouldReset == null) { shouldReset = true; } @@ -339,7 +339,7 @@ export default class Notes { } handleQuickActions(noteEntity) { - var votesBlock; + let votesBlock; if (noteEntity.commands_changes) { if ('merge' in noteEntity.commands_changes) { Notes.checkMergeRequestStatus(); @@ -462,7 +462,7 @@ export default class Notes { * Render note in discussion area. To render inline notes use renderDiscussionNote. */ renderDiscussionNote(noteEntity, $form) { - var discussionContainer, form, row, lineType, diffAvatarContainer; + let discussionContainer, form, row, lineType, diffAvatarContainer; if (!Notes.isNewNote(noteEntity, this.note_ids)) { return; @@ -491,15 +491,15 @@ export default class Notes { } if (discussionContainer.length === 0) { if (noteEntity.diff_discussion_html) { - var $discussion = $(noteEntity.diff_discussion_html).renderGFM(); + let $discussion = $(noteEntity.diff_discussion_html).renderGFM(); if (!this.isParallelView() || row.hasClass('js-temp-notes-holder') || noteEntity.on_image) { // insert the note and the reply button after the temp row row.after($discussion); } else { // Merge new discussion HTML in - var $notes = $discussion.find(`.notes[data-discussion-id="${noteEntity.discussion_id}"]`); - var contentContainerClass = $notes + let $notes = $discussion.find(`.notes[data-discussion-id="${noteEntity.discussion_id}"]`); + let contentContainerClass = $notes .closest('.notes-content') .attr('class') .split(' ') @@ -537,7 +537,7 @@ export default class Notes { } renderDiscussionAvatar(diffAvatarContainer, noteEntity) { - var avatarHolder = diffAvatarContainer.find('.diff-comment-avatar-holders'); + let avatarHolder = diffAvatarContainer.find('.diff-comment-avatar-holders'); if (!avatarHolder.length) { avatarHolder = document.createElement('diff-note-avatars'); @@ -557,7 +557,7 @@ export default class Notes { * Resets buttons. */ resetMainTargetForm(e) { - var form; + let form; form = $('.js-main-target-form'); // remove validation errors form.find('.js-errors').remove(); @@ -572,7 +572,7 @@ export default class Notes { .data('autosave') .reset(); - var event = document.createEvent('Event'); + let event = document.createEvent('Event'); event.initEvent('autosize:update', true, false); form.find('.js-autosize')[0].dispatchEvent(event); @@ -580,7 +580,7 @@ export default class Notes { } reenableTargetFormSubmitButton() { - var form; + let form; form = $('.js-main-target-form'); return form.find('.js-note-text').trigger('input'); } @@ -591,7 +591,7 @@ export default class Notes { * Sets some hidden fields in the form. */ setupMainTargetNoteForm(enableGFM) { - var form; + let form; // find the form form = $('.js-new-note-form'); // Set a global clone of the form for later cloning @@ -626,7 +626,7 @@ export default class Notes { * show the form */ setupNoteForm(form, enableGFM = defaultAutocompleteConfig) { - var textarea, key; + let textarea, key; this.glForm = new GLForm(form, enableGFM); textarea = form.find('.js-note-text'); key = [ @@ -686,8 +686,8 @@ export default class Notes { */ addDiscussionNote($form, note, isNewDiffComment) { if ($form.attr('data-resolve-all') != null) { - var discussionId = $form.data('discussionId'); - var mergeRequestId = $form.data('noteableIid'); + let discussionId = $form.data('discussionId'); + let mergeRequestId = $form.data('noteableIid'); if (ResolveService != null) { ResolveService.toggleResolveForDiscussion(mergeRequestId, discussionId); @@ -707,7 +707,7 @@ export default class Notes { * Updates the current note field. */ updateNote(noteEntity, $targetNote) { - var $noteEntityEl, $note_li; + let $noteEntityEl, $note_li; // Convert returned HTML to a jQuery object so we can modify it further $noteEntityEl = $(noteEntity.html); this.revertNoteEditForm($targetNote); @@ -724,17 +724,17 @@ export default class Notes { } checkContentToAllowEditing($el) { - var initialContent = $el + let initialContent = $el .find('.original-note-content') .text() .trim(); - var currentContent = $el.find('.js-note-text').val(); - var isAllowed = true; + let currentContent = $el.find('.js-note-text').val(); + let isAllowed = true; if (currentContent === initialContent) { this.removeNoteEditForm($el); } else { - var isWidgetVisible = isInViewport($el.get(0)); + let isWidgetVisible = isInViewport($el.get(0)); if (!isWidgetVisible) { scrollToElement($el); @@ -756,13 +756,13 @@ export default class Notes { showEditForm(e) { e.preventDefault(); - var $target = $(e.target); - var $editForm = $(this.getEditFormSelector($target)); - var $note = $target.closest('.note'); - var $currentlyEditing = $('.note.is-editing:visible'); + let $target = $(e.target); + let $editForm = $(this.getEditFormSelector($target)); + let $note = $target.closest('.note'); + let $currentlyEditing = $('.note.is-editing:visible'); if ($currentlyEditing.length) { - var isEditAllowed = this.checkContentToAllowEditing($currentlyEditing); + let isEditAllowed = this.checkContentToAllowEditing($currentlyEditing); if (!isEditAllowed) { return; @@ -802,8 +802,8 @@ export default class Notes { revertNoteEditForm($target) { $target = $target || $('.note.is-editing:visible'); - var selector = this.getEditFormSelector($target); - var $editForm = $(selector); + let selector = this.getEditFormSelector($target); + let $editForm = $(selector); $editForm.insertBefore('.diffs'); $editForm.find('.js-comment-save-button').enable(); @@ -811,7 +811,7 @@ export default class Notes { } getEditFormSelector($el) { - var selector = '.note-edit-form:not(.mr-note-edit-form)'; + let selector = '.note-edit-form:not(.mr-note-edit-form)'; if ($el.parents('#diffs').length) { selector = '.note-edit-form.mr-note-edit-form'; @@ -821,7 +821,7 @@ export default class Notes { } removeNoteEditForm($note) { - var form = $note.find('.diffs .current-note-edit-form'); + let form = $note.find('.diffs .current-note-edit-form'); $note.removeClass('is-editing'); form.removeClass('current-note-edit-form'); @@ -837,7 +837,7 @@ export default class Notes { * Removes the whole discussion if the last note is being removed. */ removeNote(e) { - var noteElId, $note; + let noteElId, $note; $note = $(e.currentTarget).closest('.note'); noteElId = $note.attr('id'); $(`.note[id="${noteElId}"]`).each((i, el) => { @@ -915,7 +915,7 @@ export default class Notes { } replyToDiscussionNote(target) { - var form, replyLink; + let form, replyLink; form = this.cleanForm(this.formClone.clone()); replyLink = $(target).closest('.js-discussion-reply-button'); // insert the form after the button @@ -942,7 +942,7 @@ export default class Notes { diffFileData = dataHolder.closest('.image'); } - var discussionID = dataHolder.data('discussionId'); + let discussionID = dataHolder.data('discussionId'); if (discussionID) { form.attr('data-discussion-id', discussionID); @@ -985,7 +985,7 @@ export default class Notes { form.removeClass('js-main-target-form').addClass('discussion-form js-discussion-note-form'); if (typeof gl.diffNotesCompileComponents !== 'undefined') { - var $commentBtn = form.find('comment-and-resolve-btn'); + let $commentBtn = form.find('comment-and-resolve-btn'); $commentBtn.attr(':discussion-id', `'${discussionID}'`); gl.diffNotesCompileComponents(); @@ -1042,7 +1042,7 @@ export default class Notes { } toggleDiffNote({ target, lineType, forceShow, showReplyInput = false }) { - var $link, addForm, hasNotes, newForm, noteForm, replyButton, row, rowCssToAdd; + let $link, addForm, hasNotes, newForm, noteForm, replyButton, row, rowCssToAdd; $link = $(target); row = $link.closest('tr'); const nextRow = row.next(); @@ -1111,7 +1111,7 @@ export default class Notes { * Removes the form and if necessary it's temporary row. */ removeDiscussionNoteForm(form) { - var glForm, row; + let glForm, row; row = form.closest('tr'); glForm = form.data('glForm'); glForm.destroy(); @@ -1158,7 +1158,7 @@ export default class Notes { * Updates the file name for the selected attachment. */ updateFormAttachment() { - var filename, form; + let filename, form; form = $(this).closest('form'); // get only the basename filename = $(this) @@ -1175,7 +1175,7 @@ export default class Notes { } updateTargetButtons(e) { - var closebtn, closetext, form, reopenbtn, reopentext, textarea; + let closebtn, closetext, form, reopenbtn, reopentext, textarea; textarea = $(e.target); form = textarea.parents('form'); reopenbtn = form.find('.js-note-target-reopen'); @@ -1215,16 +1215,16 @@ export default class Notes { } putEditFormInPlace($el) { - var $editForm = $(this.getEditFormSelector($el)); - var $note = $el.closest('.note'); + let $editForm = $(this.getEditFormSelector($el)); + let $note = $el.closest('.note'); $editForm.insertAfter($note.find('.note-text')); - var $originalContentEl = $note.find('.original-note-content'); - var originalContent = $originalContentEl.text().trim(); - var postUrl = $originalContentEl.data('postUrl'); - var targetId = $originalContentEl.data('targetId'); - var targetType = $originalContentEl.data('targetType'); + let $originalContentEl = $note.find('.original-note-content'); + let originalContent = $originalContentEl.text().trim(); + let postUrl = $originalContentEl.data('postUrl'); + let targetId = $originalContentEl.data('targetId'); + let targetType = $originalContentEl.data('targetType'); this.glForm = new GLForm($editForm.find('form'), this.enableGFM); -- GitLab From e46b8c0894a26cbec9512ed7e6a6f7d787a680ed Mon Sep 17 00:00:00 2001 From: Navin Kumar Date: Thu, 14 Nov 2019 12:15:39 +0000 Subject: [PATCH 2/4] Solved issue #36269 : Replaced var with const and let. --- app/assets/javascripts/notes.js | 52 +++++++++++++++------------------ 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/app/assets/javascripts/notes.js b/app/assets/javascripts/notes.js index ef7377eca497a3..0ec7e2cecada27 100644 --- a/app/assets/javascripts/notes.js +++ b/app/assets/javascripts/notes.js @@ -155,11 +155,7 @@ export default class Notes { this.$wrapperEl.on('click', '.system-note-commit-list-toggler', this.toggleCommitList); this.$wrapperEl.on('click', '.js-toggle-lazy-diff', this.loadLazyDiff); - this.$wrapperEl.on( - 'click', - '.js-toggle-lazy-diff-retry-button', - this.onClickRetryLazyLoad.bind(this), - ); + this.$wrapperEl.on('click', '.js-toggle-lazy-diff-retry-button', this.onClickRetryLazyLoad.bind(this)); // fetch notes when tab becomes visible this.$wrapperEl.on('visibilitychange', this.visibilityChange); @@ -172,7 +168,7 @@ export default class Notes { this.$wrapperEl.on( 'ajax:complete', '.js-main-target-form', - this.reenableTargetFormSubmitButton, + this.reenableTargetFormSubmitButton ); // when a key is clicked on the notes this.$wrapperEl.on('keydown', '.js-note-text', this.keydownNoteText); @@ -244,7 +240,7 @@ export default class Notes { } myLastNote = $( `li.note[data-author-id='${gon.current_user_id}'][data-editable]:last`, - $textarea.closest('.note, .notes_holder, #notes'), + $textarea.closest('.note, .notes_holder, #notes') ); if (myLastNote.length) { myLastNoteEditBtn = myLastNote.find('.js-note-edit'); @@ -326,7 +322,7 @@ export default class Notes { */ setPollingInterval(shouldReset) { let nthInterval; - if (shouldReset == null) { + if (shouldReset === null) { shouldReset = true; } nthInterval = this.basePollingInterval * Math.pow(2, this.maxPollingSteps - 1); @@ -432,7 +428,7 @@ export default class Notes { $note .find('.original-note-content') .text() - .trim(), + .trim() ); const $textarea = $note.find('.js-note-text'); const currentContent = $textarea.val(); @@ -665,17 +661,17 @@ export default class Notes { } return this.addFlash( __( - 'Your comment could not be submitted! Please check your network connection and try again.', + 'Your comment could not be submitted! Please check your network connection and try again.' ), 'alert', - formParentTimeline.get(0), + formParentTimeline.get(0) ); } updateNoteError() { // eslint-disable-next-line no-new new Flash( - __('Your comment could not be updated! Please check your network connection and try again.'), + __('Your comment could not be updated! Please check your network connection and try again.') ); } @@ -685,11 +681,11 @@ export default class Notes { * Adds new note to list. */ addDiscussionNote($form, note, isNewDiffComment) { - if ($form.attr('data-resolve-all') != null) { + if ($form.attr('data-resolve-all') !== null) { let discussionId = $form.data('discussionId'); let mergeRequestId = $form.data('noteableIid'); - if (ResolveService != null) { + if (ResolveService !== null) { ResolveService.toggleResolveForDiscussion(mergeRequestId, discussionId); } } @@ -969,10 +965,10 @@ export default class Notes { form .prepend( `
${escape(gon.current_user_fullname)}
`, + gon.current_user_avatar_url + )}" alt="${escape(gon.current_user_fullname)}" />` ) .append('') .find('.js-close-discussion-note-form') @@ -1248,12 +1244,12 @@ export default class Notes { const $alert = $(`
${sprintf( s__( - 'Notes|This comment has changed since you started editing, please review the %{open_link}updated comment%{close_link} to ensure information is not lost', + 'Notes|This comment has changed since you started editing, please review the %{open_link}updated comment%{close_link} to ensure information is not lost' ), { open_link, close_link: '', - }, + } )}
`); $alert.insertAfter($note.find('.note-text')); @@ -1414,7 +1410,7 @@ export default class Notes { .find('.original-note-content') .first() .text() - .trim(), + .trim() ); return sanitizedNoteEntityText !== currentNoteText; } @@ -1525,7 +1521,7 @@ export default class Notes { - `, + ` ); $tempNote.find('.d-none.d-sm-inline-block').text(_.escape(currentUserFullname)); @@ -1558,7 +1554,7 @@ export default class Notes { ${formContent} - `, + ` ); return $tempNote; @@ -1636,7 +1632,7 @@ export default class Notes { currentUsername: gon.current_username, currentUserFullname: gon.current_user_fullname, currentUserAvatar: gon.current_user_avatar_url, - }), + }) ); } @@ -1647,10 +1643,10 @@ export default class Notes { this.createPlaceholderSystemNote({ formContent: this.getQuickActionDescription( formContent, - AjaxCache.get(gl.GfmAutoComplete.dataSources.commands), + AjaxCache.get(gl.GfmAutoComplete.dataSources.commands) ), uniqueId: systemNoteUniqueId, - }), + }) ); } @@ -1812,8 +1808,8 @@ export default class Notes { .find('.note-headline-meta a') .html( ``, + 'Comment is being updated' + )}" aria-hidden="true">` ); // Make request to update comment on server -- GitLab From 764d24a3d493068e5ee5cae2c2d42bfe5ed5a198 Mon Sep 17 00:00:00 2001 From: Navin Kumar Date: Thu, 14 Nov 2019 16:34:51 +0000 Subject: [PATCH 3/4] Issue #36269 : Replaced var with const and let. --- app/assets/javascripts/notes.js | 54 ++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/app/assets/javascripts/notes.js b/app/assets/javascripts/notes.js index 0ec7e2cecada27..fd0a9d01257beb 100644 --- a/app/assets/javascripts/notes.js +++ b/app/assets/javascripts/notes.js @@ -155,7 +155,11 @@ export default class Notes { this.$wrapperEl.on('click', '.system-note-commit-list-toggler', this.toggleCommitList); this.$wrapperEl.on('click', '.js-toggle-lazy-diff', this.loadLazyDiff); - this.$wrapperEl.on('click', '.js-toggle-lazy-diff-retry-button', this.onClickRetryLazyLoad.bind(this)); + this.$wrapperEl.on( + 'click', + '.js-toggle-lazy-diff-retry-button', + this.onClickRetryLazyLoad.bind(this), + ); // fetch notes when tab becomes visible this.$wrapperEl.on('visibilitychange', this.visibilityChange); @@ -168,7 +172,7 @@ export default class Notes { this.$wrapperEl.on( 'ajax:complete', '.js-main-target-form', - this.reenableTargetFormSubmitButton + this.reenableTargetFormSubmitButton, ); // when a key is clicked on the notes this.$wrapperEl.on('keydown', '.js-note-text', this.keydownNoteText); @@ -240,7 +244,7 @@ export default class Notes { } myLastNote = $( `li.note[data-author-id='${gon.current_user_id}'][data-editable]:last`, - $textarea.closest('.note, .notes_holder, #notes') + $textarea.closest('.note, .notes_holder, #notes'), ); if (myLastNote.length) { myLastNoteEditBtn = myLastNote.find('.js-note-edit'); @@ -314,7 +318,7 @@ export default class Notes { /** * Increase @pollingInterval up to 120 seconds on every function call, - * if `shouldReset` has a truthy value, 'null' or 'undefined' the letiable + * if `shouldReset` has a truthy value, 'null' or 'undefined' the variable * will reset to @basePollingInterval. * * Note: this function is used to gradually increase the polling interval @@ -322,7 +326,7 @@ export default class Notes { */ setPollingInterval(shouldReset) { let nthInterval; - if (shouldReset === null) { + if (shouldReset == null) { shouldReset = true; } nthInterval = this.basePollingInterval * Math.pow(2, this.maxPollingSteps - 1); @@ -428,7 +432,7 @@ export default class Notes { $note .find('.original-note-content') .text() - .trim() + .trim(), ); const $textarea = $note.find('.js-note-text'); const currentContent = $textarea.val(); @@ -661,17 +665,17 @@ export default class Notes { } return this.addFlash( __( - 'Your comment could not be submitted! Please check your network connection and try again.' + 'Your comment could not be submitted! Please check your network connection and try again.', ), 'alert', - formParentTimeline.get(0) + formParentTimeline.get(0), ); } updateNoteError() { // eslint-disable-next-line no-new new Flash( - __('Your comment could not be updated! Please check your network connection and try again.') + __('Your comment could not be updated! Please check your network connection and try again.'), ); } @@ -681,11 +685,11 @@ export default class Notes { * Adds new note to list. */ addDiscussionNote($form, note, isNewDiffComment) { - if ($form.attr('data-resolve-all') !== null) { + if ($form.attr('data-resolve-all') != null) { let discussionId = $form.data('discussionId'); let mergeRequestId = $form.data('noteableIid'); - if (ResolveService !== null) { + if (ResolveService != null) { ResolveService.toggleResolveForDiscussion(mergeRequestId, discussionId); } } @@ -965,10 +969,10 @@ export default class Notes { form .prepend( `
${escape(gon.current_user_fullname)}
` + gon.current_user_avatar_url, + )}" alt="${escape(gon.current_user_fullname)}" />`, ) .append('') .find('.js-close-discussion-note-form') @@ -1244,12 +1248,12 @@ export default class Notes { const $alert = $(`
${sprintf( s__( - 'Notes|This comment has changed since you started editing, please review the %{open_link}updated comment%{close_link} to ensure information is not lost' + 'Notes|This comment has changed since you started editing, please review the %{open_link}updated comment%{close_link} to ensure information is not lost', ), { open_link, close_link: '', - } + }, )}
`); $alert.insertAfter($note.find('.note-text')); @@ -1410,7 +1414,7 @@ export default class Notes { .find('.original-note-content') .first() .text() - .trim() + .trim(), ); return sanitizedNoteEntityText !== currentNoteText; } @@ -1521,7 +1525,7 @@ export default class Notes { - ` + `, ); $tempNote.find('.d-none.d-sm-inline-block').text(_.escape(currentUserFullname)); @@ -1554,7 +1558,7 @@ export default class Notes { ${formContent} - ` + `, ); return $tempNote; @@ -1632,7 +1636,7 @@ export default class Notes { currentUsername: gon.current_username, currentUserFullname: gon.current_user_fullname, currentUserAvatar: gon.current_user_avatar_url, - }) + }), ); } @@ -1643,10 +1647,10 @@ export default class Notes { this.createPlaceholderSystemNote({ formContent: this.getQuickActionDescription( formContent, - AjaxCache.get(gl.GfmAutoComplete.dataSources.commands) + AjaxCache.get(gl.GfmAutoComplete.dataSources.commands), ), uniqueId: systemNoteUniqueId, - }) + }), ); } @@ -1808,8 +1812,8 @@ export default class Notes { .find('.note-headline-meta a') .html( `` + 'Comment is being updated', + )}" aria-hidden="true">`, ); // Make request to update comment on server -- GitLab From 49a1c0d8584dbc95bb04854f386b1a229aa27288 Mon Sep 17 00:00:00 2001 From: Navin Kumar Date: Fri, 15 Nov 2019 12:14:06 +0000 Subject: [PATCH 4/4] Updated notes.js --- app/assets/javascripts/notes.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/notes.js b/app/assets/javascripts/notes.js index fd0a9d01257beb..36a3fb5039e87d 100644 --- a/app/assets/javascripts/notes.js +++ b/app/assets/javascripts/notes.js @@ -1,7 +1,7 @@ -/* eslint-disable no-restricted-properties, no-var, camelcase, -no-unused-expressions, one-var, default-case, +/* eslint-disable no-restricted-properties, camelcase, +no-unused-expressions, default-case, consistent-return, no-alert, no-param-reassign, no-else-return, -vars-on-top, no-shadow, no-useless-escape, +no-shadow, no-useless-escape, class-methods-use-this */ /* global ResolveService */ -- GitLab