Commit e9296608 authored by Clement Ho's avatar Clement Ho

Merge branch 'remove-monkey-patched-array-prototypes' into 'master'

Remove monkey-patched Array.prototype.first() and last() methods

See merge request !13213
parents fe5086c2 7256626d
...@@ -10,7 +10,7 @@ class AjaxLoadingSpinner { ...@@ -10,7 +10,7 @@ class AjaxLoadingSpinner {
e.target.setAttribute('disabled', ''); e.target.setAttribute('disabled', '');
const iconElement = e.target.querySelector('i'); const iconElement = e.target.querySelector('i');
// get first fa- icon // get first fa- icon
const originalIcon = iconElement.className.match(/(fa-)([^\s]+)/g).first(); const originalIcon = iconElement.className.match(/(fa-)([^\s]+)/g)[0];
iconElement.dataset.icon = originalIcon; iconElement.dataset.icon = originalIcon;
AjaxLoadingSpinner.toggleLoadingIcon(iconElement); AjaxLoadingSpinner.toggleLoadingIcon(iconElement);
$(e.target).off('ajax:beforeSend', AjaxLoadingSpinner.ajaxBeforeSend); $(e.target).off('ajax:beforeSend', AjaxLoadingSpinner.ajaxBeforeSend);
......
...@@ -92,7 +92,7 @@ $(() => { ...@@ -92,7 +92,7 @@ $(() => {
}); });
}, },
selectDefaultStage() { selectDefaultStage() {
const stage = this.state.stages.first(); const stage = this.state.stages[0];
this.selectStage(stage); this.selectStage(stage);
}, },
selectStage(stage) { selectStage(stage) {
......
...@@ -504,7 +504,7 @@ import GpgBadges from './gpg_badges'; ...@@ -504,7 +504,7 @@ import GpgBadges from './gpg_badges';
new gl.DueDateSelectors(); new gl.DueDateSelectors();
break; break;
} }
switch (path.first()) { switch (path[0]) {
case 'sessions': case 'sessions':
case 'omniauth_callbacks': case 'omniauth_callbacks':
if (!gon.u2f) break; if (!gon.u2f) break;
......
...@@ -217,7 +217,7 @@ window.DropzoneInput = (function() { ...@@ -217,7 +217,7 @@ window.DropzoneInput = (function() {
value = e.clipboardData.getData('text/plain'); value = e.clipboardData.getData('text/plain');
} }
value = value.split("\r"); value = value.split("\r");
return value.first(); return value[0];
}; };
const showSpinner = function(e) { const showSpinner = function(e) {
......
// TODO: remove this
// eslint-disable-next-line no-extend-native
Array.prototype.first = function first() {
return this[0];
};
// eslint-disable-next-line no-extend-native
Array.prototype.last = function last() {
return this[this.length - 1];
};
...@@ -123,11 +123,11 @@ class DropdownUtils { ...@@ -123,11 +123,11 @@ class DropdownUtils {
if (!allowMultiple && itemInExistingTokens) { if (!allowMultiple && itemInExistingTokens) {
updatedItem.droplab_hidden = true; updatedItem.droplab_hidden = true;
} else if (!lastKey || searchInput.split('').last() === ' ') { } else if (!lastKey || _.last(searchInput.split('')) === ' ') {
updatedItem.droplab_hidden = false; updatedItem.droplab_hidden = false;
} else if (lastKey) { } else if (lastKey) {
const split = lastKey.split(':'); const split = lastKey.split(':');
const tokenName = split[0].split(' ').last(); const tokenName = _.last(split[0].split(' '));
const match = updatedItem.hint.indexOf(tokenName.toLowerCase()) === -1; const match = updatedItem.hint.indexOf(tokenName.toLowerCase()) === -1;
updatedItem.droplab_hidden = tokenName ? match : false; updatedItem.droplab_hidden = tokenName ? match : false;
......
...@@ -167,7 +167,7 @@ class FilteredSearchDropdownManager { ...@@ -167,7 +167,7 @@ class FilteredSearchDropdownManager {
// Eg. token = 'label:' // Eg. token = 'label:'
const split = lastToken.split(':'); const split = lastToken.split(':');
const dropdownName = split[0].split(' ').last(); const dropdownName = _.last(split[0].split(' '));
this.loadDropdown(split.length > 1 ? dropdownName : ''); this.loadDropdown(split.length > 1 ? dropdownName : '');
} else if (lastToken) { } else if (lastToken) {
// Token has been initialized into an object because it has a value // Token has been initialized into an object because it has a value
......
...@@ -367,7 +367,7 @@ class FilteredSearchManager { ...@@ -367,7 +367,7 @@ class FilteredSearchManager {
const fragments = searchToken.split(':'); const fragments = searchToken.split(':');
if (fragments.length > 1) { if (fragments.length > 1) {
const inputValues = fragments[0].split(' '); const inputValues = fragments[0].split(' ');
const tokenKey = inputValues.last(); const tokenKey = _.last(inputValues);
if (inputValues.length > 1) { if (inputValues.length > 1) {
inputValues.pop(); inputValues.pop();
......
...@@ -16,9 +16,6 @@ import 'mousetrap'; ...@@ -16,9 +16,6 @@ import 'mousetrap';
import 'mousetrap/plugins/pause/mousetrap-pause'; import 'mousetrap/plugins/pause/mousetrap-pause';
import 'vendor/fuzzaldrin-plus'; import 'vendor/fuzzaldrin-plus';
// extensions
import './extensions/array';
// expose common libraries as globals (TODO: remove these) // expose common libraries as globals (TODO: remove these)
window.jQuery = jQuery; window.jQuery = jQuery;
window.$ = jQuery; window.$ = jQuery;
......
...@@ -6,10 +6,10 @@ import '~/abuse_reports'; ...@@ -6,10 +6,10 @@ import '~/abuse_reports';
const FIXTURE = 'abuse_reports/abuse_reports_list.html.raw'; const FIXTURE = 'abuse_reports/abuse_reports_list.html.raw';
const MAX_MESSAGE_LENGTH = 500; const MAX_MESSAGE_LENGTH = 500;
let messages; let $messages;
const assertMaxLength = $message => expect($message.text().length).toEqual(MAX_MESSAGE_LENGTH); const assertMaxLength = $message => expect($message.text().length).toEqual(MAX_MESSAGE_LENGTH);
const findMessage = searchText => messages.filter( const findMessage = searchText => $messages.filter(
(index, element) => element.innerText.indexOf(searchText) > -1, (index, element) => element.innerText.indexOf(searchText) > -1,
).first(); ).first();
...@@ -18,7 +18,7 @@ import '~/abuse_reports'; ...@@ -18,7 +18,7 @@ import '~/abuse_reports';
beforeEach(function () { beforeEach(function () {
loadFixtures(FIXTURE); loadFixtures(FIXTURE);
this.abuseReports = new global.AbuseReports(); this.abuseReports = new global.AbuseReports();
messages = $('.abuse-reports .message'); $messages = $('.abuse-reports .message');
}); });
it('should truncate long messages', () => { it('should truncate long messages', () => {
......
import '~/extensions/array';
import 'jquery'; import 'jquery';
import 'jquery-ujs'; import 'jquery-ujs';
import '~/ajax_loading_spinner'; import '~/ajax_loading_spinner';
......
/* eslint-disable space-before-function-paren, no-var */
import '~/extensions/array';
(function() {
describe('Array extensions', function() {
describe('first', function() {
return it('returns the first item', function() {
var arr;
arr = [0, 1, 2, 3, 4, 5];
return expect(arr.first()).toBe(0);
});
});
describe('last', function() {
return it('returns the last item', function() {
var arr;
arr = [0, 1, 2, 3, 4, 5];
return expect(arr.last()).toBe(5);
});
});
});
}).call(window);
import '~/extensions/array';
import '~/filtered_search/dropdown_utils'; import '~/filtered_search/dropdown_utils';
import '~/filtered_search/filtered_search_tokenizer'; import '~/filtered_search/filtered_search_tokenizer';
import '~/filtered_search/filtered_search_dropdown_manager'; import '~/filtered_search/filtered_search_dropdown_manager';
......
import '~/extensions/array';
import '~/filtered_search/filtered_search_visual_tokens'; import '~/filtered_search/filtered_search_visual_tokens';
import '~/filtered_search/filtered_search_tokenizer'; import '~/filtered_search/filtered_search_tokenizer';
import '~/filtered_search/filtered_search_dropdown_manager'; import '~/filtered_search/filtered_search_dropdown_manager';
......
import '~/extensions/array';
import '~/filtered_search/filtered_search_token_keys'; import '~/filtered_search/filtered_search_token_keys';
describe('Filtered Search Token Keys', () => { describe('Filtered Search Token Keys', () => {
......
import '~/extensions/array';
import '~/filtered_search/filtered_search_token_keys'; import '~/filtered_search/filtered_search_token_keys';
import '~/filtered_search/filtered_search_tokenizer'; import '~/filtered_search/filtered_search_tokenizer';
......
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