1413156 - Transfer lodash functions to ES6: includes, indexOf & compact

- includes -> indexOf === -1
- indexOf -> indexOf
- compact -> filter(v => v)
This commit is contained in:
Vincenzo Scalzi 2018-01-23 02:19:13 +01:00 коммит произвёл Cameron Dawson
Родитель 2b826994ea
Коммит bcb4011bb9
10 изменённых файлов: 30 добавлений и 31 удалений

Просмотреть файл

@ -51,7 +51,7 @@ treeherderApp.controller('JobFilterCtrl', [
};
$scope.isFilterOn = function (filter) {
if (_.includes(_.keys($scope.filterGroups), filter)) {
if (_.keys($scope.filterGroups).indexOf(filter) !== -1) {
// this is a filter grouping, so toggle all on/off
return _.some(
_.at($scope.resultStatusFilters,
@ -67,7 +67,7 @@ treeherderApp.controller('JobFilterCtrl', [
*/
$scope.toggleResultStatusFilterChicklet = function (filter) {
var filterValues;
if (_.includes(_.keys($scope.filterGroups), filter)) {
if (_.keys($scope.filterGroups).indexOf(filter) !== -1) {
// this is a filter grouping, so toggle all on/off
filterValues = $scope.filterGroups[filter].resultStatuses;
} else {
@ -111,8 +111,7 @@ treeherderApp.controller('JobFilterCtrl', [
var updateToggleFilters = function () {
for (var i = 0; i < $scope.filterOptions.length; i++) {
var opt = $scope.filterOptions[i];
$scope.resultStatusFilters[opt] = _.includes(
thJobFilters.getResultStatusArray(), opt);
$scope.resultStatusFilters[opt] = thJobFilters.getResultStatusArray().indexOf(opt) !== -1;
}
// whether or not to show classified jobs
@ -120,8 +119,8 @@ treeherderApp.controller('JobFilterCtrl', [
// for a value, just whether the job has any value set or not.
// just a boolean check either way
var classifiedState = thJobFilters.getClassifiedStateArray();
$scope.classifiedFilter = _.includes(classifiedState, 'classified');
$scope.unClassifiedFilter = _.includes(classifiedState, 'unclassified');
$scope.classifiedFilter = classifiedState.indexOf('classified') !== -1;
$scope.unClassifiedFilter = classifiedState.indexOf('unclassified') !== -1;
};
updateToggleFilters();

Просмотреть файл

@ -744,7 +744,7 @@ perf.controller('CompareSubtestResultsCtrl', [
// If there is no data for a given signature, handle it gracefully
if (seriesMap) {
Object.keys(seriesMap).forEach(function (series) {
if (!_.includes($scope.pageList, seriesMap[series].name)) {
if ($scope.pageList.indexOf(seriesMap[series].name) === -1) {
$scope.pageList.push(seriesMap[series].name);
}
});
@ -779,7 +779,7 @@ perf.controller('CompareSubtestResultsCtrl', [
// There is a chance that we haven't received data for the given signature/resultSet yet
if (newSeriesMap) {
Object.keys(newSeriesMap).forEach(function (series) {
if (!_.includes($scope.pageList, newSeriesMap[series].name)) {
if ($scope.pageList.indexOf(newSeriesMap[series].name) === -1) {
$scope.pageList.push(newSeriesMap[series].name);
}
});
@ -846,7 +846,7 @@ perf.controller('CompareSubtestResultsCtrl', [
// There is a chance that we haven't received data for the given signature/resultSet yet
if (newSeriesMap) {
Object.keys(newSeriesMap).forEach(function (series) {
if (!_.includes($scope.pageList, newSeriesMap[series].name)) {
if ($scope.pageList.indexOf(newSeriesMap[series].name) === -1) {
$scope.pageList.push(newSeriesMap[series].name);
}
});

Просмотреть файл

@ -397,11 +397,11 @@ perf.controller('GraphsCtrl', [
// highlight the datapoints too
series.highlightedPoints = _.union(
series.highlightedPoints,
_.compact(_.map(
_.map(
series.flotSeries.resultSetData,
function (seriesResultSetId, index) {
return resultSetId === seriesResultSetId ? index : null;
})));
}).filter(v => v));
}
if ($scope.highlightAlerts) {
@ -1062,7 +1062,7 @@ perf.controller('TestChooserCtrl', ['$scope', '$uibModalInstance',
framework: $scope.selectedFramework.id }).then(function (platformList) {
$scope.platformList = platformList;
$scope.platformList.sort();
if (_.includes($scope.platformList, defaultPlatform)) {
if ($scope.platformList.indexOf(defaultPlatform) !== -1) {
$scope.selectedPlatform = defaultPlatform;
} else {
$scope.selectedPlatform = $scope.platformList[0];

Просмотреть файл

@ -72,7 +72,7 @@ treeherder.controller('TCJobActionsCtrl', [
// only directing loaner tasks to the loaner UI in the tools site.
// It is possible that we may make this a part of the spec later.
const loaners = ['docker-worker-linux-loaner', 'generic-worker-windows-loaner'];
if (_.includes(loaners, $scope.input.selectedAction.name)) {
if (loaners.indexOf($scope.input.selectedAction.name) !== -1) {
message = 'Visit Taskcluster Tools site to access loaner:';
url = `${url}/connect`;
}

Просмотреть файл

@ -332,7 +332,7 @@ treeherder.directive('thCloneJobs', [
// We don't add it to group counts, because it should not be counted
// when filtered out and duplicate jobs are being shown.
// Failures don't get included in counts anyway.
if (_.includes(failResults, resultStatus) ||
if (failResults.indexOf(resultStatus) === -1 ||
(typeSymbolCounts[job.job_type_symbol] > 1 && $scope.showDuplicateJobs)) {
// render the job itself, not a count
addJobBtnToArray(job, lastJobSelected, jobBtnArray);

Просмотреть файл

@ -57,7 +57,7 @@ treeherder.factory('ThRepositoryModel', [
var watchRepo = function (name) {
// Safeguard: Don't allow duplicates in the watch list
// Also, only add items for which we have data for
if (_.includes(watchedRepos, name) || !repos[name]) {
if (watchedRepos.indexOf(name) !== -1 || !repos[name]) {
return;
}
_.extend(repos[name], {
@ -294,11 +294,11 @@ treeherder.factory('ThRepositoryModel', [
// The $interval will pass in the number of times it was called,
// rather than a ``repoName``. So repoName would equal 1, 2, 3. So
// if repoName isn't a valid watched repo, we update all.
var repoNames = _.includes(watchedRepos, repoName) ? [repoName] : watchedRepos;
var repoNames = watchedRepos.indexOf(repoName) !== -1 ? [repoName] : watchedRepos;
// filter out non-watched and unsupported repos to prevent repeatedly
// hitting an endpoint we know will never work.
repoNames = repoNames.filter(repo => _.includes(watchedRepos, repo) && repos[repo].treeStatus.status !== 'unsupported');
repoNames = repoNames.filter(repo => watchedRepos.indexOf(repo) !== -1 && repos[repo].treeStatus.status !== 'unsupported');
var newStatuses = {};
var getStatus = function (repo) {

Просмотреть файл

@ -280,7 +280,7 @@ treeherder.factory('ThResultSetModel', ['$http', '$location',
// 2. The name is a buildbot buildername _scheduled_ through bbb, in which case we
// translate it to the taskcluster label that triggers it.
name = builderToTask[name] || name;
if (_.includes(allLabels, name)) {
if (allLabels.indexOf(name) !== -1) {
tclabels.push(name);
}
});

Просмотреть файл

@ -197,7 +197,7 @@ treeherder.factory('ThResultSetStore', [
// get the new job ids
var jobIds = _.map(jobList, 'id');
// remove the elements that need to be updated
resultSet.jobList = resultSet.jobList.filter(job => _.indexOf(jobIds, job.id) === -1);
resultSet.jobList = resultSet.jobList.filter(job => jobIds.indexOf(job.id) === -1);
resultSet.jobList = resultSet.jobList.concat(jobList);
} else {
resultSet.jobList = jobList;
@ -834,7 +834,7 @@ treeherder.factory('ThResultSetStore', [
// get
var newResultsets = [];
_.each(data.results, function (rs) {
if (!_.includes(rsIds, rs.id)) {
if (rsIds.indexOf(rs.id) === -1) {
newResultsets.push(rs);
}
});
@ -976,7 +976,7 @@ treeherder.factory('ThResultSetStore', [
var isRunnableJobSelected = function (repoName, resultsetId, buildername) {
var selectedRunnableJobs = getSelectedRunnableJobs(repoName, resultsetId);
return _.includes(selectedRunnableJobs, buildername);
return selectedRunnableJobs.indexOf(buildername) !== -1;
};
var getJobMap = function (repoName) {

Просмотреть файл

@ -197,7 +197,7 @@ treeherder.factory('thJobFilters', [
// shown regardless of settings for classified or result state
if (job.result !== "runnable") {
// test against resultStatus and classifiedState
if (!_.includes(cachedResultStatusFilters, thResultStatus(job))) {
if (cachedResultStatusFilters.indexOf(thResultStatus(job)) === -1) {
return false;
}
if (!_checkClassifiedStateFilters(job)) {
@ -247,13 +247,13 @@ treeherder.factory('thJobFilters', [
break;
case MATCH_TYPE.exactstr:
if (!_.includes(values, jobFieldValue)) {
if (values.indexOf(jobFieldValue) === -1) {
return false;
}
break;
case MATCH_TYPE.choice:
if (!_.includes(values, jobFieldValue)) {
if (values.indexOf(jobFieldValue) === -1) {
return false;
}
break;
@ -382,7 +382,7 @@ treeherder.factory('thJobFilters', [
}
function isFilterSetToShow(field, value) {
return _.includes(_getFiltersOrDefaults(field), String(value));
return _getFiltersOrDefaults(field).indexOf(String(value)) !== -1;
}
/**
@ -455,12 +455,12 @@ treeherder.factory('thJobFilters', [
}
function isJobUnclassifiedFailure(job) {
return (_.includes(thFailureResults, job.result) &&
return (thFailureResults.indexOf(job.result) !== -1 &&
!_isJobClassified(job));
}
function _isJobClassified(job) {
return !_.includes(UNCLASSIFIED_IDS, job.failure_classification_id);
return UNCLASSIFIED_IDS.indexOf(job.failure_classification_id) === -1;
}
function stripFiltersFromQueryString(locationSearch) {
@ -495,11 +495,11 @@ treeherder.factory('thJobFilters', [
function _isFieldFilter(field) {
return field.startsWith(PREFIX) &&
!_.includes(['resultStatus', 'classifiedState'], _withoutPrefix(field));
['resultStatus', 'classifiedState'].indexOf(_withoutPrefix(field)) === -1;
}
function _isClearableFilter(field) {
return _.includes(NON_FIELD_FILTERS, field);
return NON_FIELD_FILTERS.indexOf(field) !== -1;
}
/**

Просмотреть файл

@ -27,8 +27,8 @@ treeherder.factory('ThLog', [
ThLog.prototype.error = function () { logIt(this, $log.error, arguments); };
var logIt = function (self, func, args) {
if ((whitelist.length && _.includes(whitelist, self.getClassName())) ||
(blacklist.length && !_.includes(blacklist, self.getClassName())) ||
if ((whitelist.length && whitelist.indexOf(self.getClassName()) !== -1) ||
(blacklist.length && blacklist.indexOf(self.getClassName()) === -1) ||
(!whitelist.length && !blacklist.length)) {
var newArgs = Array.prototype.slice.call(args);
newArgs.unshift(self.getClassName());