Commit 23cdae8e authored by gfyoung's avatar gfyoung

Enable "prefer-destructuring" in JS files

Partially addresses #47006.
parent d38eb9bb
...@@ -69,5 +69,3 @@ rules: ...@@ -69,5 +69,3 @@ rules:
FunctionExpression: FunctionExpression:
parameters: 1 parameters: 1
body: 1 body: 1
## Destructuring: https://eslint.org/docs/rules/prefer-destructuring
prefer-destructuring: off
...@@ -26,7 +26,7 @@ export default class AjaxLoadingSpinner { ...@@ -26,7 +26,7 @@ export default class AjaxLoadingSpinner {
} }
static toggleLoadingIcon(iconElement) { static toggleLoadingIcon(iconElement) {
const classList = iconElement.classList; const { classList } = iconElement;
classList.toggle(iconElement.dataset.icon); classList.toggle(iconElement.dataset.icon);
classList.toggle('fa-spinner'); classList.toggle('fa-spinner');
classList.toggle('fa-spin'); classList.toggle('fa-spin');
......
...@@ -52,7 +52,7 @@ export default function initCopyToClipboard() { ...@@ -52,7 +52,7 @@ export default function initCopyToClipboard() {
* data types to the intended values. * data types to the intended values.
*/ */
$(document).on('copy', 'body > textarea[readonly]', (e) => { $(document).on('copy', 'body > textarea[readonly]', (e) => {
const clipboardData = e.originalEvent.clipboardData; const { clipboardData } = e.originalEvent;
if (!clipboardData) return; if (!clipboardData) return;
const text = e.target.value; const text = e.target.value;
......
...@@ -321,7 +321,7 @@ export class CopyAsGFM { ...@@ -321,7 +321,7 @@ export class CopyAsGFM {
} }
static copyAsGFM(e, transformer) { static copyAsGFM(e, transformer) {
const clipboardData = e.originalEvent.clipboardData; const { clipboardData } = e.originalEvent;
if (!clipboardData) return; if (!clipboardData) return;
const documentFragment = getSelectedFragment(); const documentFragment = getSelectedFragment();
...@@ -338,7 +338,7 @@ export class CopyAsGFM { ...@@ -338,7 +338,7 @@ export class CopyAsGFM {
} }
static pasteGFM(e) { static pasteGFM(e) {
const clipboardData = e.originalEvent.clipboardData; const { clipboardData } = e.originalEvent;
if (!clipboardData) return; if (!clipboardData) return;
const text = clipboardData.getData('text/plain'); const text = clipboardData.getData('text/plain');
......
...@@ -84,7 +84,7 @@ class BalsamiqViewer { ...@@ -84,7 +84,7 @@ class BalsamiqViewer {
renderTemplate(preview) { renderTemplate(preview) {
const resource = this.getResource(preview.resourceID); const resource = this.getResource(preview.resourceID);
const name = BalsamiqViewer.parseTitle(resource); const name = BalsamiqViewer.parseTitle(resource);
const image = preview.image; const { image } = preview;
const template = PREVIEW_TEMPLATE({ const template = PREVIEW_TEMPLATE({
name, name,
......
...@@ -12,7 +12,7 @@ export default function loadBalsamiqFile() { ...@@ -12,7 +12,7 @@ export default function loadBalsamiqFile() {
if (!(viewer instanceof Element)) return; if (!(viewer instanceof Element)) return;
const endpoint = viewer.dataset.endpoint; const { endpoint } = viewer.dataset;
const balsamiqViewer = new BalsamiqViewer(viewer); const balsamiqViewer = new BalsamiqViewer(viewer);
balsamiqViewer.loadFile(endpoint).catch(onError); balsamiqViewer.loadFile(endpoint).catch(onError);
......
...@@ -5,7 +5,7 @@ export default () => { ...@@ -5,7 +5,7 @@ export default () => {
[].slice.call(document.querySelectorAll('.js-material-changer')).forEach((el) => { [].slice.call(document.querySelectorAll('.js-material-changer')).forEach((el) => {
el.addEventListener('click', (e) => { el.addEventListener('click', (e) => {
const target = e.target; const { target } = e;
e.preventDefault(); e.preventDefault();
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
}, },
methods: { methods: {
removeIssue() { removeIssue() {
const issue = this.issue; const { issue } = this;
const lists = issue.getLists(); const lists = issue.getLists();
const listLabelIds = lists.map(list => list.label.id); const listLabelIds = lists.map(list => list.label.id);
......
...@@ -121,7 +121,7 @@ export default () => { ...@@ -121,7 +121,7 @@ export default () => {
this.filterManager.updateTokens(); this.filterManager.updateTokens();
}, },
updateDetailIssue(newIssue) { updateDetailIssue(newIssue) {
const sidebarInfoEndpoint = newIssue.sidebarInfoEndpoint; const { sidebarInfoEndpoint } = newIssue;
if (sidebarInfoEndpoint && newIssue.subscribed === undefined) { if (sidebarInfoEndpoint && newIssue.subscribed === undefined) {
newIssue.setFetchingState('subscriptions', true); newIssue.setFetchingState('subscriptions', true);
BoardService.getIssueInfo(sidebarInfoEndpoint) BoardService.getIssueInfo(sidebarInfoEndpoint)
...@@ -144,7 +144,7 @@ export default () => { ...@@ -144,7 +144,7 @@ export default () => {
Store.detail.issue = {}; Store.detail.issue = {};
}, },
toggleSubscription(id) { toggleSubscription(id) {
const issue = Store.detail.issue; const { issue } = Store.detail;
if (issue.id === id && issue.toggleSubscriptionEndpoint) { if (issue.id === id && issue.toggleSubscriptionEndpoint) {
issue.setFetchingState('subscriptions', true); issue.setFetchingState('subscriptions', true);
BoardService.toggleIssueSubscription(issue.toggleSubscriptionEndpoint) BoardService.toggleIssueSubscription(issue.toggleSubscriptionEndpoint)
......
...@@ -26,7 +26,7 @@ class ModalStore { ...@@ -26,7 +26,7 @@ class ModalStore {
toggleIssue(issueObj) { toggleIssue(issueObj) {
const issue = issueObj; const issue = issueObj;
const selected = issue.selected; const { selected } = issue;
issue.selected = !selected; issue.selected = !selected;
......
...@@ -81,7 +81,7 @@ export default class Clusters { ...@@ -81,7 +81,7 @@ export default class Clusters {
} }
initApplications() { initApplications() {
const store = this.store; const { store } = this;
const el = document.querySelector('#js-cluster-applications'); const el = document.querySelector('#js-cluster-applications');
this.applications = new Vue({ this.applications = new Vue({
......
...@@ -122,7 +122,7 @@ export default class ImageFile { ...@@ -122,7 +122,7 @@ export default class ImageFile {
return $('.swipe.view', this.file).each((function(_this) { return $('.swipe.view', this.file).each((function(_this) {
return function(index, view) { return function(index, view) {
var $swipeWrap, $swipeBar, $swipeFrame, wrapPadding, ref; var $swipeWrap, $swipeBar, $swipeFrame, wrapPadding, ref;
ref = _this.prepareFrames(view), maxWidth = ref[0], maxHeight = ref[1]; ref = _this.prepareFrames(view), [maxWidth, maxHeight] = ref;
$swipeFrame = $('.swipe-frame', view); $swipeFrame = $('.swipe-frame', view);
$swipeWrap = $('.swipe-wrap', view); $swipeWrap = $('.swipe-wrap', view);
$swipeBar = $('.swipe-bar', view); $swipeBar = $('.swipe-bar', view);
...@@ -159,7 +159,7 @@ export default class ImageFile { ...@@ -159,7 +159,7 @@ export default class ImageFile {
return $('.onion-skin.view', this.file).each((function(_this) { return $('.onion-skin.view', this.file).each((function(_this) {
return function(index, view) { return function(index, view) {
var $frame, $track, $dragger, $frameAdded, framePadding, ref, dragging = false; var $frame, $track, $dragger, $frameAdded, framePadding, ref, dragging = false;
ref = _this.prepareFrames(view), maxWidth = ref[0], maxHeight = ref[1]; ref = _this.prepareFrames(view), [maxWidth, maxHeight] = ref;
$frame = $('.onion-skin-frame', view); $frame = $('.onion-skin-frame', view);
$frameAdded = $('.frame.added', view); $frameAdded = $('.frame.added', view);
$track = $('.drag-track', view); $track = $('.drag-track', view);
......
...@@ -281,7 +281,7 @@ export default class CreateMergeRequestDropdown { ...@@ -281,7 +281,7 @@ export default class CreateMergeRequestDropdown {
if (event.target === this.branchInput) { if (event.target === this.branchInput) {
target = 'branch'; target = 'branch';
value = this.branchInput.value; ({ value } = this.branchInput);
} else if (event.target === this.refInput) { } else if (event.target === this.refInput) {
target = 'ref'; target = 'ref';
value = value =
......
...@@ -111,7 +111,7 @@ const DiffNoteAvatars = Vue.extend({ ...@@ -111,7 +111,7 @@ const DiffNoteAvatars = Vue.extend({
}); });
}, },
addNoCommentClass() { addNoCommentClass() {
const notesCount = this.notesCount; const { notesCount } = this;
$(this.$el).closest('.js-avatar-container') $(this.$el).closest('.js-avatar-container')
.toggleClass('no-comment-btn', notesCount > 0) .toggleClass('no-comment-btn', notesCount > 0)
......
...@@ -73,7 +73,7 @@ const JumpToDiscussion = Vue.extend({ ...@@ -73,7 +73,7 @@ const JumpToDiscussion = Vue.extend({
}).toArray(); }).toArray();
}; };
const discussions = this.discussions; const { discussions } = this;
if (activeTab === 'diffs') { if (activeTab === 'diffs') {
discussionsSelector = '.diffs .notes[data-discussion-id]'; discussionsSelector = '.diffs .notes[data-discussion-id]';
......
...@@ -18,7 +18,7 @@ import './components/new_issue_for_discussion'; ...@@ -18,7 +18,7 @@ import './components/new_issue_for_discussion';
export default () => { export default () => {
const projectPathHolder = const projectPathHolder =
document.querySelector('.merge-request') || document.querySelector('.commit-box'); document.querySelector('.merge-request') || document.querySelector('.commit-box');
const projectPath = projectPathHolder.dataset.projectPath; const { projectPath } = projectPathHolder.dataset;
const COMPONENT_SELECTOR = const COMPONENT_SELECTOR =
'resolve-btn, resolve-discussion-btn, jump-to-discussion, comment-and-resolve-btn, new-issue-for-discussion-btn'; 'resolve-btn, resolve-discussion-btn, jump-to-discussion, comment-and-resolve-btn, new-issue-for-discussion-btn';
......
...@@ -47,7 +47,7 @@ export default { ...@@ -47,7 +47,7 @@ export default {
methods: { methods: {
...mapActions(['toggleDiscussion']), ...mapActions(['toggleDiscussion']),
getTooltipText(noteData) { getTooltipText(noteData) {
let note = noteData.note; let { note } = noteData;
if (note.length > LENGTH_OF_AVATAR_TOOLTIP) { if (note.length > LENGTH_OF_AVATAR_TOOLTIP) {
note = truncate(note, LENGTH_OF_AVATAR_TOOLTIP); note = truncate(note, LENGTH_OF_AVATAR_TOOLTIP);
......
...@@ -124,7 +124,7 @@ export default { ...@@ -124,7 +124,7 @@ export default {
const newLineNumber = this.metaData.newPos || 0; const newLineNumber = this.metaData.newPos || 0;
const offset = newLineNumber - oldLineNumber; const offset = newLineNumber - oldLineNumber;
const bottom = this.isBottom; const bottom = this.isBottom;
const fileHash = this.fileHash; const { fileHash } = this;
const view = this.diffViewType; const view = this.diffViewType;
let unfold = true; let unfold = true;
let lineNumber = newLineNumber - 1; let lineNumber = newLineNumber - 1;
......
...@@ -89,7 +89,7 @@ export default { ...@@ -89,7 +89,7 @@ export default {
return isLeftExpanded || isRightExpanded; return isLeftExpanded || isRightExpanded;
}, },
getLineCode(line, side) { getLineCode(line, side) {
const lineCode = side.lineCode; const { lineCode } = side;
if (lineCode) { if (lineCode) {
return lineCode; return lineCode;
} }
......
...@@ -292,7 +292,7 @@ ...@@ -292,7 +292,7 @@
if (this.model && if (this.model &&
this.model.last_deployment && this.model.last_deployment &&
this.model.last_deployment.deployable) { this.model.last_deployment.deployable) {
const deployable = this.model.last_deployment.deployable; const { deployable } = this.model.last_deployment;
return `${deployable.name} #${deployable.id}`; return `${deployable.name} #${deployable.id}`;
} }
return ''; return '';
......
...@@ -146,7 +146,7 @@ export default class EnvironmentsStore { ...@@ -146,7 +146,7 @@ export default class EnvironmentsStore {
* @return {Array} * @return {Array}
*/ */
updateEnvironmentProp(environment, prop, newValue) { updateEnvironmentProp(environment, prop, newValue) {
const environments = this.state.environments; const { environments } = this.state;
const updatedEnvironments = environments.map((env) => { const updatedEnvironments = environments.map((env) => {
const updateEnv = Object.assign({}, env); const updateEnv = Object.assign({}, env);
...@@ -161,7 +161,7 @@ export default class EnvironmentsStore { ...@@ -161,7 +161,7 @@ export default class EnvironmentsStore {
} }
getOpenFolders() { getOpenFolders() {
const environments = this.state.environments; const { environments } = this.state;
return environments.filter(env => env.isFolder && env.isOpen); return environments.filter(env => env.isFolder && env.isOpen);
} }
......
...@@ -35,7 +35,7 @@ export default class DropdownUtils { ...@@ -35,7 +35,7 @@ export default class DropdownUtils {
// Remove the symbol for filter // Remove the symbol for filter
if (value[0] === filterSymbol) { if (value[0] === filterSymbol) {
symbol = value[0]; [symbol] = value;
value = value.slice(1); value = value.slice(1);
} }
...@@ -162,7 +162,7 @@ export default class DropdownUtils { ...@@ -162,7 +162,7 @@ export default class DropdownUtils {
// Determines the full search query (visual tokens + input) // Determines the full search query (visual tokens + input)
static getSearchQuery(untilInput = false) { static getSearchQuery(untilInput = false) {
const container = FilteredSearchContainer.container; const { container } = FilteredSearchContainer;
const tokens = [].slice.call(container.querySelectorAll('.tokens-container li')); const tokens = [].slice.call(container.querySelectorAll('.tokens-container li'));
const values = []; const values = [];
...@@ -220,7 +220,7 @@ export default class DropdownUtils { ...@@ -220,7 +220,7 @@ export default class DropdownUtils {
} }
static getInputSelectionPosition(input) { static getInputSelectionPosition(input) {
const selectionStart = input.selectionStart; const { selectionStart } = input;
let inputValue = input.value; let inputValue = input.value;
// Replace all spaces inside quote marks with underscores // Replace all spaces inside quote marks with underscores
// (will continue to match entire string until an end quote is found if any) // (will continue to match entire string until an end quote is found if any)
......
...@@ -159,7 +159,7 @@ export default class FilteredSearchDropdownManager { ...@@ -159,7 +159,7 @@ export default class FilteredSearchDropdownManager {
load(key, firstLoad = false) { load(key, firstLoad = false) {
const mappingKey = this.mapping[key]; const mappingKey = this.mapping[key];
const glClass = mappingKey.gl; const glClass = mappingKey.gl;
const element = mappingKey.element; const { element } = mappingKey;
let forceShowList = false; let forceShowList = false;
if (!mappingKey.reference) { if (!mappingKey.reference) {
......
...@@ -235,7 +235,7 @@ export default class FilteredSearchManager { ...@@ -235,7 +235,7 @@ export default class FilteredSearchManager {
checkForEnter(e) { checkForEnter(e) {
if (e.keyCode === 38 || e.keyCode === 40) { if (e.keyCode === 38 || e.keyCode === 40) {
const selectionStart = this.filteredSearchInput.selectionStart; const { selectionStart } = this.filteredSearchInput;
e.preventDefault(); e.preventDefault();
this.filteredSearchInput.setSelectionRange(selectionStart, selectionStart); this.filteredSearchInput.setSelectionRange(selectionStart, selectionStart);
...@@ -496,7 +496,7 @@ export default class FilteredSearchManager { ...@@ -496,7 +496,7 @@ export default class FilteredSearchManager {
// Replace underscore with hyphen in the sanitizedkey. // Replace underscore with hyphen in the sanitizedkey.
// e.g. 'my_reaction' => 'my-reaction' // e.g. 'my_reaction' => 'my-reaction'
sanitizedKey = sanitizedKey.replace('_', '-'); sanitizedKey = sanitizedKey.replace('_', '-');
const symbol = match.symbol; const { symbol } = match;
let quotationsToUse = ''; let quotationsToUse = '';
if (sanitizedValue.indexOf(' ') !== -1) { if (sanitizedValue.indexOf(' ') !== -1) {
......
...@@ -101,7 +101,7 @@ export default class FilteredSearchVisualTokens { ...@@ -101,7 +101,7 @@ export default class FilteredSearchVisualTokens {
static updateLabelTokenColor(tokenValueContainer, tokenValue) { static updateLabelTokenColor(tokenValueContainer, tokenValue) {
const filteredSearchInput = FilteredSearchContainer.container.querySelector('.filtered-search'); const filteredSearchInput = FilteredSearchContainer.container.querySelector('.filtered-search');
const baseEndpoint = filteredSearchInput.dataset.baseEndpoint; const { baseEndpoint } = filteredSearchInput.dataset;
const labelsEndpoint = FilteredSearchVisualTokens.getEndpointWithQueryParams( const labelsEndpoint = FilteredSearchVisualTokens.getEndpointWithQueryParams(
`${baseEndpoint}/labels.json`, `${baseEndpoint}/labels.json`,
filteredSearchInput.dataset.endpointQueryParams, filteredSearchInput.dataset.endpointQueryParams,
...@@ -215,7 +215,7 @@ export default class FilteredSearchVisualTokens { ...@@ -215,7 +215,7 @@ export default class FilteredSearchVisualTokens {
static addFilterVisualToken(tokenName, tokenValue, canEdit) { static addFilterVisualToken(tokenName, tokenValue, canEdit) {
const { lastVisualToken, isLastVisualTokenValid } const { lastVisualToken, isLastVisualTokenValid }
= FilteredSearchVisualTokens.getLastVisualTokenBeforeInput(); = FilteredSearchVisualTokens.getLastVisualTokenBeforeInput();
const addVisualTokenElement = FilteredSearchVisualTokens.addVisualTokenElement; const { addVisualTokenElement } = FilteredSearchVisualTokens;
if (isLastVisualTokenValid) { if (isLastVisualTokenValid) {
addVisualTokenElement(tokenName, tokenValue, false, canEdit); addVisualTokenElement(tokenName, tokenValue, false, canEdit);
......
...@@ -29,7 +29,7 @@ class RecentSearchesRoot { ...@@ -29,7 +29,7 @@ class RecentSearchesRoot {
} }
render() { render() {
const state = this.store.state; const { state } = this.store;
this.vm = new Vue({ this.vm = new Vue({
el: this.wrapperElement, el: this.wrapperElement,
components: { components: {
......
...@@ -80,7 +80,7 @@ class GfmAutoComplete { ...@@ -80,7 +80,7 @@ class GfmAutoComplete {
let tpl = '/${name} '; let tpl = '/${name} ';
let referencePrefix = null; let referencePrefix = null;
if (value.params.length > 0) { if (value.params.length > 0) {
referencePrefix = value.params[0][0]; [[referencePrefix]] = value.params;
if (/^[@%~]/.test(referencePrefix)) { if (/^[@%~]/.test(referencePrefix)) {
tpl += '<%- referencePrefix %>'; tpl += '<%- referencePrefix %>';
} }
...@@ -458,7 +458,7 @@ class GfmAutoComplete { ...@@ -458,7 +458,7 @@ class GfmAutoComplete {
static isLoading(data) { static isLoading(data) {
let dataToInspect = data; let dataToInspect = data;
if (data && data.length > 0) { if (data && data.length > 0) {
dataToInspect = data[0]; [dataToInspect] = data;
} }
const loadingState = GfmAutoComplete.defaultLoadingData[0]; const loadingState = GfmAutoComplete.defaultLoadingData[0];
......
...@@ -613,7 +613,7 @@ GitLabDropdown = (function() { ...@@ -613,7 +613,7 @@ GitLabDropdown = (function() {
}; };
GitLabDropdown.prototype.renderItem = function(data, group, index) { GitLabDropdown.prototype.renderItem = function(data, group, index) {
var field, fieldName, html, selected, text, url, value, rowHidden; var field, html, selected, text, url, value, rowHidden;
if (!this.options.renderRow) { if (!this.options.renderRow) {
value = this.options.id ? this.options.id(data) : data.id; value = this.options.id ? this.options.id(data) : data.id;
...@@ -651,7 +651,7 @@ GitLabDropdown = (function() { ...@@ -651,7 +651,7 @@ GitLabDropdown = (function() {
html = this.options.renderRow.call(this.options, data, this); html = this.options.renderRow.call(this.options, data, this);
} else { } else {
if (!selected) { if (!selected) {
fieldName = this.options.fieldName; const { fieldName } = this.options;
if (value) { if (value) {
field = this.dropdown.parent().find(`input[name='${fieldName}'][value='${value}']`); field = this.dropdown.parent().find(`input[name='${fieldName}'][value='${value}']`);
...@@ -705,7 +705,8 @@ GitLabDropdown = (function() { ...@@ -705,7 +705,8 @@ GitLabDropdown = (function() {
GitLabDropdown.prototype.highlightTextMatches = function(text, term) { GitLabDropdown.prototype.highlightTextMatches = function(text, term) {
const occurrences = fuzzaldrinPlus.match(text, term); const occurrences = fuzzaldrinPlus.match(text, term);
const indexOf = [].indexOf; const { indexOf } = [];
return text.split('').map(function(character, i) { return text.split('').map(function(character, i) {
if (indexOf.call(occurrences, i) !== -1) { if (indexOf.call(occurrences, i) !== -1) {
return "<b>" + character + "</b>"; return "<b>" + character + "</b>";
...@@ -721,9 +722,9 @@ GitLabDropdown = (function() { ...@@ -721,9 +722,9 @@ GitLabDropdown = (function() {
}; };
GitLabDropdown.prototype.rowClicked = function(el) { GitLabDropdown.prototype.rowClicked = function(el) {
var field, fieldName, groupName, isInput, selectedIndex, selectedObject, value, isMarking; var field, groupName, isInput, selectedIndex, selectedObject, value, isMarking;
fieldName = this.options.fieldName; const { fieldName } = this.options;
isInput = $(this.el).is('input'); isInput = $(this.el).is('input');
if (this.renderedData) { if (this.renderedData) {
groupName = el.data('group'); groupName = el.data('group');
......
...@@ -29,7 +29,7 @@ export default () => { ...@@ -29,7 +29,7 @@ export default () => {
groupsApp, groupsApp,
}, },
data() { data() {
const dataset = this.$options.el.dataset; const { dataset } = this.$options.el;
const hideProjects = dataset.hideProjects === 'true'; const hideProjects = dataset.hideProjects === 'true';
const store = new GroupsStore(hideProjects); const store = new GroupsStore(hideProjects);
const service = new GroupsService(dataset.endpoint); const service = new GroupsService(dataset.endpoint);
...@@ -42,7 +42,7 @@ export default () => { ...@@ -42,7 +42,7 @@ export default () => {
}; };
}, },
beforeMount() { beforeMount() {
const dataset = this.$options.el.dataset; const { dataset } = this.$options.el;
let groupFilterList = null; let groupFilterList = null;
const form = document.querySelector(dataset.formSel); const form = document.querySelector(dataset.formSel);
const filter = document.querySelector(dataset.filterSel); const filter = document.querySelector(dataset.filterSel);
......
...@@ -30,7 +30,7 @@ export default { ...@@ -30,7 +30,7 @@ export default {
}, },
computed: { computed: {
pathWithEllipsis() { pathWithEllipsis() {
const path = this.file.path; const { path } = this.file;
return path.length < MAX_PATH_LENGTH return path.length < MAX_PATH_LENGTH
? path ? path
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
let { result } = target; let { result } = target;
if (!isText) { if (!isText) {
// eslint-disable-next-line prefer-destructuring
result = result.split('base64,')[1]; result = result.split('base64,')[1];
} }