Commit 8a7fe44e authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch 'lm-last-underscores' into 'master'

Replace last instances of underscore with lodash

See merge request gitlab-org/gitlab!29644
parents f4b5ccd1 29e147a2
...@@ -5,7 +5,6 @@ import SidebarMediator from '~/sidebar/sidebar_mediator'; ...@@ -5,7 +5,6 @@ import SidebarMediator from '~/sidebar/sidebar_mediator';
import glRegexp from './lib/utils/regexp'; import glRegexp from './lib/utils/regexp';
import AjaxCache from './lib/utils/ajax_cache'; import AjaxCache from './lib/utils/ajax_cache';
import { spriteIcon } from './lib/utils/common_utils'; import { spriteIcon } from './lib/utils/common_utils';
import _ from 'underscore';
function sanitize(str) { function sanitize(str) {
return str.replace(/<(?:.|\n)*?>/gm, ''); return str.replace(/<(?:.|\n)*?>/gm, '');
...@@ -138,7 +137,7 @@ class GfmAutoComplete { ...@@ -138,7 +137,7 @@ class GfmAutoComplete {
tpl += '<%- referencePrefix %>'; tpl += '<%- referencePrefix %>';
} }
} }
return _.template(tpl)({ referencePrefix }); return template(tpl, { interpolate: /<%=([\s\S]+?)%>/g })({ referencePrefix });
}, },
suffix: '', suffix: '',
callbacks: { callbacks: {
......
/* eslint-disable max-classes-per-file, one-var, consistent-return */ /* eslint-disable max-classes-per-file, one-var, consistent-return */
import $ from 'jquery'; import $ from 'jquery';
import _ from 'underscore'; import { escape as esc } from 'lodash';
import fuzzaldrinPlus from 'fuzzaldrin-plus'; import fuzzaldrinPlus from 'fuzzaldrin-plus';
import axios from './lib/utils/axios_utils'; import axios from './lib/utils/axios_utils';
import { visitUrl } from './lib/utils/url_utility'; import { visitUrl } from './lib/utils/url_utility';
...@@ -145,7 +145,7 @@ class GitLabDropdownFilter { ...@@ -145,7 +145,7 @@ class GitLabDropdownFilter {
// { prop: 'foo' }, // { prop: 'foo' },
// { prop: 'baz' } // { prop: 'baz' }
// ] // ]
if (_.isArray(data)) { if (Array.isArray(data)) {
results = fuzzaldrinPlus.filter(data, searchText, { results = fuzzaldrinPlus.filter(data, searchText, {
key: this.options.keys, key: this.options.keys,
}); });
...@@ -261,14 +261,14 @@ class GitLabDropdown { ...@@ -261,14 +261,14 @@ class GitLabDropdown {
// If no input is passed create a default one // If no input is passed create a default one
self = this; self = this;
// If selector was passed // If selector was passed
if (_.isString(this.filterInput)) { if (typeof this.filterInput === 'string') {
this.filterInput = this.getElement(this.filterInput); this.filterInput = this.getElement(this.filterInput);
} }
const searchFields = this.options.search ? this.options.search.fields : []; const searchFields = this.options.search ? this.options.search.fields : [];
if (this.options.data) { if (this.options.data) {
// If we provided data // If we provided data
// data could be an array of objects or a group of arrays // data could be an array of objects or a group of arrays
if (_.isObject(this.options.data) && !_.isFunction(this.options.data)) { if (typeof this.options.data === 'object' && !(this.options.data instanceof Function)) {
this.fullData = this.options.data; this.fullData = this.options.data;
currentIndex = -1; currentIndex = -1;
this.parseData(this.options.data); this.parseData(this.options.data);
...@@ -610,7 +610,7 @@ class GitLabDropdown { ...@@ -610,7 +610,7 @@ class GitLabDropdown {
// eslint-disable-next-line class-methods-use-this // eslint-disable-next-line class-methods-use-this
highlightTemplate(text, template) { highlightTemplate(text, template) {
return `"<b>${_.escape(text)}</b>" ${template}`; return `"<b>${esc(text)}</b>" ${template}`;
} }
// eslint-disable-next-line class-methods-use-this // eslint-disable-next-line class-methods-use-this
......
/* eslint-disable consistent-return, func-names, array-callback-return */ /* eslint-disable consistent-return, func-names, array-callback-return */
import $ from 'jquery'; import $ from 'jquery';
import _ from 'underscore'; import { intersection } from 'lodash';
import axios from './lib/utils/axios_utils'; import axios from './lib/utils/axios_utils';
import Flash from './flash'; import Flash from './flash';
import { __ } from './locale'; import { __ } from './locale';
...@@ -111,7 +111,7 @@ export default { ...@@ -111,7 +111,7 @@ export default {
this.getElement('.selected-issuable:checked').each((i, el) => { this.getElement('.selected-issuable:checked').each((i, el) => {
labelIds.push(this.getElement(`#${this.prefixId}${el.dataset.id}`).data('labels')); labelIds.push(this.getElement(`#${this.prefixId}${el.dataset.id}`).data('labels'));
}); });
return _.intersection.apply(this, labelIds); return intersection.apply(this, labelIds);
}, },
// From issuable's initial bulk selection // From issuable's initial bulk selection
...@@ -120,7 +120,7 @@ export default { ...@@ -120,7 +120,7 @@ export default {
this.getElement('.selected-issuable:checked').each((i, el) => { this.getElement('.selected-issuable:checked').each((i, el) => {
labelIds.push(this.getElement(`#${this.prefixId}${el.dataset.id}`).data('labels')); labelIds.push(this.getElement(`#${this.prefixId}${el.dataset.id}`).data('labels'));
}); });
return _.intersection.apply(this, labelIds); return intersection.apply(this, labelIds);
}, },
// From issuable's initial bulk selection // From issuable's initial bulk selection
...@@ -144,7 +144,7 @@ export default { ...@@ -144,7 +144,7 @@ export default {
// Add uniqueIds to add it as argument for _.intersection // Add uniqueIds to add it as argument for _.intersection
labelIds.unshift(uniqueIds); labelIds.unshift(uniqueIds);
// Return IDs that are present but not in all selected issueables // Return IDs that are present but not in all selected issueables
return _.difference(uniqueIds, _.intersection.apply(this, labelIds)); return uniqueIds.filter(x => !intersection.apply(this, labelIds).includes(x));
}, },
getElement(selector) { getElement(selector) {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
/* global ListMilestone */ /* global ListMilestone */
import $ from 'jquery'; import $ from 'jquery';
import _ from 'underscore'; import { template, escape as esc } from 'lodash';
import { __ } from '~/locale'; import { __ } from '~/locale';
import '~/gl_dropdown'; import '~/gl_dropdown';
import axios from './lib/utils/axios_utils'; import axios from './lib/utils/axios_utils';
...@@ -60,7 +60,7 @@ export default class MilestoneSelect { ...@@ -60,7 +60,7 @@ export default class MilestoneSelect {
selectedMilestone = $dropdown.data('selected') || selectedMilestoneDefault; selectedMilestone = $dropdown.data('selected') || selectedMilestoneDefault;
if (issueUpdateURL) { if (issueUpdateURL) {
milestoneLinkTemplate = _.template( milestoneLinkTemplate = template(
'<a href="<%- web_url %>" class="bold has-tooltip" data-container="body" title="<%- remaining %>"><%- title %></a>', '<a href="<%- web_url %>" class="bold has-tooltip" data-container="body" title="<%- remaining %>"><%- title %></a>',
); );
milestoneLinkNoneTemplate = `<span class="no-value">${__('None')}</span>`; milestoneLinkNoneTemplate = `<span class="no-value">${__('None')}</span>`;
...@@ -106,12 +106,12 @@ export default class MilestoneSelect { ...@@ -106,12 +106,12 @@ export default class MilestoneSelect {
if (showMenuAbove) { if (showMenuAbove) {
$dropdown.data('glDropdown').positionMenuAbove(); $dropdown.data('glDropdown').positionMenuAbove();
} }
$(`[data-milestone-id="${_.escape(selectedMilestone)}"] > a`).addClass('is-active'); $(`[data-milestone-id="${esc(selectedMilestone)}"] > a`).addClass('is-active');
}), }),
renderRow: milestone => ` renderRow: milestone => `
<li data-milestone-id="${_.escape(milestone.name)}"> <li data-milestone-id="${esc(milestone.name)}">
<a href='#' class='dropdown-menu-milestone-link'> <a href='#' class='dropdown-menu-milestone-link'>
${_.escape(milestone.title)} ${esc(milestone.title)}
</a> </a>
</li> </li>
`, `,
...@@ -129,7 +129,7 @@ export default class MilestoneSelect { ...@@ -129,7 +129,7 @@ export default class MilestoneSelect {
}, },
defaultLabel, defaultLabel,
fieldName: $dropdown.data('fieldName'), fieldName: $dropdown.data('fieldName'),
text: milestone => _.escape(milestone.title), text: milestone => esc(milestone.title),
id: milestone => { id: milestone => {
if (!useId && !$dropdown.is('.js-issuable-form-dropdown')) { if (!useId && !$dropdown.is('.js-issuable-form-dropdown')) {
return milestone.name; return milestone.name;
...@@ -148,7 +148,7 @@ export default class MilestoneSelect { ...@@ -148,7 +148,7 @@ export default class MilestoneSelect {
selectedMilestone = $dropdown[0].dataset.selected || selectedMilestoneDefault; selectedMilestone = $dropdown[0].dataset.selected || selectedMilestoneDefault;
} }
$('a.is-active', $el).removeClass('is-active'); $('a.is-active', $el).removeClass('is-active');
$(`[data-milestone-id="${_.escape(selectedMilestone)}"] > a`, $el).addClass('is-active'); $(`[data-milestone-id="${esc(selectedMilestone)}"] > a`, $el).addClass('is-active');
}, },
vue: $dropdown.hasClass('js-issue-board-sidebar'), vue: $dropdown.hasClass('js-issue-board-sidebar'),
clicked: clickEvent => { clicked: clickEvent => {
......
/* eslint-disable no-return-assign, consistent-return, class-methods-use-this */ /* eslint-disable no-return-assign, consistent-return, class-methods-use-this */
import $ from 'jquery'; import $ from 'jquery';
import { escape, throttle } from 'underscore'; import { escape as esc, throttle } from 'lodash';
import { s__, __ } from '~/locale'; import { s__, __ } from '~/locale';
import { getIdenticonBackgroundClass, getIdenticonTitle } from '~/helpers/avatar_helper'; import { getIdenticonBackgroundClass, getIdenticonTitle } from '~/helpers/avatar_helper';
import axios from './lib/utils/axios_utils'; import axios from './lib/utils/axios_utils';
...@@ -448,7 +448,7 @@ export class SearchAutocomplete { ...@@ -448,7 +448,7 @@ export class SearchAutocomplete {
const avatar = avatarUrl const avatar = avatarUrl
? `<img class="search-item-avatar" src="${avatarUrl}" />` ? `<img class="search-item-avatar" src="${avatarUrl}" />`
: `<div class="s16 avatar identicon ${getIdenticonBackgroundClass(id)}">${getIdenticonTitle( : `<div class="s16 avatar identicon ${getIdenticonBackgroundClass(id)}">${getIdenticonTitle(
escape(label), esc(label),
)}</div>`; )}</div>`;
return avatar; return avatar;
......
import _ from 'underscore'; import { omitBy, isUndefined } from 'lodash';
const DEFAULT_SNOWPLOW_OPTIONS = { const DEFAULT_SNOWPLOW_OPTIONS = {
namespace: 'gl', namespace: 'gl',
...@@ -29,7 +29,7 @@ const eventHandler = (e, func, opts = {}) => { ...@@ -29,7 +29,7 @@ const eventHandler = (e, func, opts = {}) => {
context: el.dataset.trackContext, context: el.dataset.trackContext,
}; };
func(opts.category, action + (opts.suffix || ''), _.omit(data, _.isUndefined)); func(opts.category, action + (opts.suffix || ''), omitBy(data, isUndefined));
}; };
const eventHandlers = (category, func) => { const eventHandlers = (category, func) => {
......
import $ from 'jquery'; import $ from 'jquery';
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import { first } from 'underscore';
import EvidenceBlock from '~/releases/components/evidence_block.vue'; import EvidenceBlock from '~/releases/components/evidence_block.vue';
import ReleaseBlock from '~/releases/components/release_block.vue'; import ReleaseBlock from '~/releases/components/release_block.vue';
import ReleaseBlockFooter from '~/releases/components/release_block_footer.vue'; import ReleaseBlockFooter from '~/releases/components/release_block_footer.vue';
...@@ -80,11 +79,11 @@ describe('Release block', () => { ...@@ -80,11 +79,11 @@ describe('Release block', () => {
); );
expect(wrapper.find('.js-sources-dropdown li a').attributes().href).toEqual( expect(wrapper.find('.js-sources-dropdown li a').attributes().href).toEqual(
first(release.assets.sources).url, release.assets.sources[0].url,
); );
expect(wrapper.find('.js-sources-dropdown li a').text()).toContain( expect(wrapper.find('.js-sources-dropdown li a').text()).toContain(
first(release.assets.sources).format, release.assets.sources[0].format,
); );
}); });
...@@ -92,12 +91,10 @@ describe('Release block', () => { ...@@ -92,12 +91,10 @@ describe('Release block', () => {
expect(wrapper.findAll('.js-assets-list li').length).toEqual(release.assets.links.length); expect(wrapper.findAll('.js-assets-list li').length).toEqual(release.assets.links.length);
expect(wrapper.find('.js-assets-list li a').attributes().href).toEqual( expect(wrapper.find('.js-assets-list li a').attributes().href).toEqual(
first(release.assets.links).directAssetUrl, release.assets.links[0].directAssetUrl,
); );
expect(wrapper.find('.js-assets-list li a').text()).toContain( expect(wrapper.find('.js-assets-list li a').text()).toContain(release.assets.links[0].name);
first(release.assets.links).name,
);
}); });
it('renders author avatar', () => { it('renders author avatar', () => {
...@@ -264,7 +261,7 @@ describe('Release block', () => { ...@@ -264,7 +261,7 @@ describe('Release block', () => {
}); });
it('renders a link to the milestone with a tooltip', () => { it('renders a link to the milestone with a tooltip', () => {
const milestone = first(release.milestones); const milestone = release.milestones[0];
const milestoneLink = wrapper.find('.js-milestone-link'); const milestoneLink = wrapper.find('.js-milestone-link');
expect(milestoneLink.exists()).toBe(true); expect(milestoneLink.exists()).toBe(true);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment