Skip to content

Commit

Permalink
Fix oppia#1974: Added '==' and '!=' as bad patterns for js files. (op…
Browse files Browse the repository at this point in the history
…pia#1980)

* Added '==' and '!=' as bad patterns for js files.

* Corrected bad patterns in js files. oppia#1974

* Modified bad pattern and fixed linting issues.

* Fixed bad pattern issues.

* Modified pre_commit_linter to support new bad patterns.

* Modified schema of BAD_PATTERNS and BAD_PATTERNS_JS.

* Added exclude_files for ' != ' pattern.
  • Loading branch information
souravbadami authored and bbriggs committed Jun 11, 2016
1 parent 19b6957 commit d76f7c5
Show file tree
Hide file tree
Showing 70 changed files with 267 additions and 234 deletions.
2 changes: 1 addition & 1 deletion core/templates/dev/head/admin/Admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ oppia.controller('Admin', ['$scope', '$http', function($scope, $http) {
};

$scope.saveConfigProperties = function() {
if ($scope.message == 'Saving...') {
if ($scope.message === 'Saving...') {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions core/templates/dev/head/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ oppia.config([

// Prevent the search page from reloading if the search query is changed.
$locationProvider.html5Mode(false);
if (window.location.pathname == '/search/find') {
if (window.location.pathname === '/search/find') {
$locationProvider.html5Mode(true);
}

Expand Down Expand Up @@ -240,10 +240,10 @@ oppia.factory('oppiaDatetimeFormatter', ['$filter', function($filter) {
// Otherwise, returns the full date (with the year abbreviated).
getLocaleAbbreviatedDatetimeString: function(millisSinceEpoch) {
var date = new Date(millisSinceEpoch);
if (date.toLocaleDateString() == new Date().toLocaleDateString()) {
if (date.toLocaleDateString() === new Date().toLocaleDateString()) {
// The replace function removes 'seconds' from the time returned.
return date.toLocaleTimeString().replace(/:\d\d /, ' ');
} else if (date.getFullYear() == new Date().getFullYear()) {
} else if (date.getFullYear() === new Date().getFullYear()) {
return $filter('date')(date, 'MMM d');
} else {
return $filter('date')(date, 'shortDate');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ oppia.factory('CollectionLinearizerService', [
return collection.getExplorationIds().filter(function(explorationId) {
var collectionNode = collection.getCollectionNodeByExplorationId(
explorationId);
return completedExpIds.indexOf(explorationId) == -1 &&
return completedExpIds.indexOf(explorationId) === -1 &&
acquiredSkillList.isSupersetOfSkillList(
collectionNode.getPrerequisiteSkillList());
});
Expand Down Expand Up @@ -72,7 +72,7 @@ oppia.factory('CollectionLinearizerService', [
var _findNodeIndex = function(linearNodeList, explorationId) {
var index = -1;
for (var i = 0; i < linearNodeList.length; i++) {
if (linearNodeList[i].getExplorationId() == explorationId) {
if (linearNodeList[i].getExplorationId() === explorationId) {
index = i;
break;
}
Expand Down Expand Up @@ -142,7 +142,7 @@ oppia.factory('CollectionLinearizerService', [
if (collection.getCollectionNodeCount() > 1) {
var linearNodeList = _getCollectionNodesInPlayableOrder(collection);
var nodeIndex = _findNodeIndex(linearNodeList, explorationId);
if (nodeIndex == -1) {
if (nodeIndex === -1) {
return false;
}
swapFunction(collection, linearNodeList, nodeIndex);
Expand Down Expand Up @@ -204,7 +204,7 @@ oppia.factory('CollectionLinearizerService', [
if (collection.getCollectionNodeCount() > 1) {
var linearNodeList = _getCollectionNodesInPlayableOrder(collection);
var nodeIndex = _findNodeIndex(linearNodeList, explorationId);
if (nodeIndex == -1) {
if (nodeIndex === -1) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ oppia.directive('collectionNodeCreator', [function() {
.loadPublicAndPrivateExplorationSummaries(
[newExplorationId]).then(function(summaries) {
var summaryBackendObject = null;
if (summaries.length != 0 &&
summaries[0].id == newExplorationId) {
if (summaries.length !== 0 &&
summaries[0].id === newExplorationId) {
summaryBackendObject = summaries[0];
}
if (summaryBackendObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ oppia.controller('CollectionPlayer', [
for (var i = 0; i < collectionNodes.length; i++) {
var collectionNode = collectionNodes[i];
var explorationId = collectionNode.getExplorationId();
if (displayedExplorationIds.indexOf(explorationId) == -1) {
if (displayedExplorationIds.indexOf(explorationId) === -1) {
nonRecommendedCollectionNodes.push(collectionNode);
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/templates/dev/head/components/AlertMessageDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ oppia.directive('alertMessage', [function() {
],
link: function(scope) {
var message = scope.getMessage();
if (message.type == 'info') {
if (message.type === 'info') {
scope.toastr.info(message.content, {
onHidden: function() {
scope.alertsService.deleteMessage(message);
}
});
} else if (message.type == 'success') {
} else if (message.type === 'success') {
scope.toastr.success(message.content, {
onHidden: function() {
scope.alertsService.deleteMessage(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ oppia.directive('answerGroupEditor', [function() {
var ruleTypes = Object.keys(ruleDescriptions);
var ruleType = null;
for (var i = 0; i < ruleTypes.length; i++) {
if (ruleTypes[i] != FUZZY_RULE_TYPE) {
if (ruleTypes[i] !== FUZZY_RULE_TYPE) {
ruleType = ruleTypes[i];
break;
}
Expand Down Expand Up @@ -201,7 +201,7 @@ oppia.directive('answerGroupEditor', [function() {
$scope.rules.splice(index, 1);
$scope.saveRules();

if ($scope.rules.length == 0) {
if ($scope.rules.length === 0) {
alertsService.addWarning(
'All answer groups must have at least one rule.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ oppia.directive('explorationSummaryTile', [function() {
tooltipText: contributorName
};

if (GLOBALS.SYSTEM_USERNAMES.indexOf(contributorName) == -1) {
if (GLOBALS.SYSTEM_USERNAMES.indexOf(contributorName) === -1) {
avatarData.link = '/profile/' + contributorName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ oppia.directive('outcomeDestinationEditor', [function() {
StateGraphLayoutService, PLACEHOLDER_OUTCOME_DEST, focusService) {
$scope.$on('saveOutcomeDestDetails', function() {
// Create new state if specified.
if ($scope.outcome.dest == PLACEHOLDER_OUTCOME_DEST) {
if ($scope.outcome.dest === PLACEHOLDER_OUTCOME_DEST) {
var newStateName = $scope.outcome.newStateName;
$scope.outcome.dest = newStateName;
delete $scope.outcome.newStateName;
Expand All @@ -48,7 +48,7 @@ oppia.directive('outcomeDestinationEditor', [function() {
};

$scope.isCreatingNewState = function(outcome) {
return outcome.dest == PLACEHOLDER_OUTCOME_DEST;
return outcome.dest === PLACEHOLDER_OUTCOME_DEST;
};

$scope.newStateNamePattern = /^[a-zA-Z0-9.\s-]+$/;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ oppia.directive('outcomeFeedbackEditor', [function() {
if (feedbackStr) {
nonemptyFeedback.push(feedbackStr);
}
if (!feedbackStr && i == 0) {
if (!feedbackStr && i === 0) {
// If the first feedback is empty, copy no more feedback after.
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ oppia.directive('profileLinkImage', [function() {
var DEFAULT_PROFILE_IMAGE_PATH = '/images/avatar/user_blue_72px.png';

$scope.isUsernameLinkable = function(username) {
return GLOBALS.SYSTEM_USERNAMES.indexOf(username) == -1;
return GLOBALS.SYSTEM_USERNAMES.indexOf(username) === -1;
};

$scope.profileImageUrl = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ oppia.directive('profileLinkText', [function() {
templateUrl: 'components/profileLinkText',
controller: ['$scope', function($scope) {
$scope.isUsernameLinkable = function(username) {
return GLOBALS.SYSTEM_USERNAMES.indexOf(username) == -1;
return GLOBALS.SYSTEM_USERNAMES.indexOf(username) === -1;
};
}]
};
Expand Down
2 changes: 1 addition & 1 deletion core/templates/dev/head/components/RuleEditorDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ oppia.directive('ruleEditor', ['$log', function($log) {
text: i !== 0 ? finalInputArray[i] : '',
type: 'noneditable'
});
if (i == finalInputArray.length - 1) {
if (i === finalInputArray.length - 1) {
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ oppia.directive('ruleTypeSelector', [function() {
var ruleTypesToDescriptions = INTERACTION_SPECS[
stateInteractionIdService.savedMemento].rule_descriptions;
for (var ruleType in ruleTypesToDescriptions) {
if (ruleType == FUZZY_RULE_TYPE) {
if (ruleType === FUZZY_RULE_TYPE) {
continue;
}
numberOfRuleTypes++;
Expand Down
6 changes: 3 additions & 3 deletions core/templates/dev/head/components/SearchBarDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ oppia.directive('searchBar', [function() {
$scope.searchQuery, $scope.selectionDetails.categories.selections,
$scope.selectionDetails.languageCodes.selections
);
if ($window.location.pathname == '/search/find') {
if ($window.location.pathname === '/search/find') {
$location.url('/find?q=' + searchUrlQueryString);
} else {
$window.location.href = '/search/find?q=' + searchUrlQueryString;
Expand All @@ -150,7 +150,7 @@ oppia.directive('searchBar', [function() {

$scope.onSearchQueryChange = function(evt) {
// Query immediately when the enter or space key is pressed.
if (evt.keyCode == 13 || evt.keyCode == 32) {
if (evt.keyCode === 13 || evt.keyCode === 32) {
onSearchQueryChangeExec();
} else {
oppiaDebouncer.debounce(onSearchQueryChangeExec, 650)();
Expand Down Expand Up @@ -194,7 +194,7 @@ oppia.directive('searchBar', [function() {
updateSearchFieldsBasedOnUrlQuery();
}

if ($window.location.pathname == '/search/find') {
if ($window.location.pathname === '/search/find') {
onSearchQueryChangeExec();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ oppia.factory('StateGraphLayoutService', [
queue.shift();

for (var i = 0; i < links.length; i++) {
if (links[i].target == currNodeId &&
if (links[i].target === currNodeId &&
!nodeData[links[i].source].reachableFromEnd) {
nodeData[links[i].source].reachableFromEnd = true;
queue.push(links[i].source);
Expand Down
14 changes: 7 additions & 7 deletions core/templates/dev/head/components/StateGraphVizDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,13 @@ oppia.directive('stateGraphViz', [function() {

for (var i = 0; i < $scope.augmentedLinks.length; i++) {
var link = $scope.augmentedLinks[i];
if (link.source.label != link.target.label) {
if (link.source.label !== link.target.label) {
var sourcex = link.source.xLabel;
var sourcey = link.source.yLabel;
var targetx = link.target.xLabel;
var targety = link.target.yLabel;

if (sourcex == targetx && sourcey == targety) {
if (sourcex === targetx && sourcey === targety) {
// TODO(sll): Investigate why this happens.
return;
}
Expand Down Expand Up @@ -264,8 +264,8 @@ oppia.directive('stateGraphViz', [function() {
var currentNodeIsTerminal = (
$scope.finalStateIds.indexOf(nodeId) !== -1);
return (
nodeId == $scope.currentStateId() ? '3' :
(nodeId == $scope.initStateId2 || currentNodeIsTerminal) ? '2' :
nodeId === $scope.currentStateId() ? '3' :
(nodeId === $scope.initStateId2 || currentNodeIsTerminal) ? '2' :
'1');
};

Expand Down Expand Up @@ -301,7 +301,7 @@ oppia.directive('stateGraphViz', [function() {
};

$scope.onNodeDeletionClick = function(nodeId) {
if (nodeId != initStateId) {
if (nodeId !== initStateId) {
$scope.onDeleteFunction(nodeId);
}
};
Expand All @@ -315,7 +315,7 @@ oppia.directive('stateGraphViz', [function() {
};

$scope.canNavigateToNode = function(nodeId) {
return nodeId != $scope.currentStateId();
return nodeId !== $scope.currentStateId();
};

$scope.getTruncatedLabel = function(nodeLabel) {
Expand Down Expand Up @@ -359,7 +359,7 @@ oppia.directive('stateGraphViz', [function() {
nodeData[nodeId].reachableFromEnd) ? 'bad-node' :
'normal-node');

nodeData[nodeId].canDelete = (nodeId != initStateId);
nodeData[nodeId].canDelete = (nodeId !== initStateId);
$scope.nodeList.push(nodeData[nodeId]);
}

Expand Down
2 changes: 1 addition & 1 deletion core/templates/dev/head/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ oppia.directive('mathjaxBind', [function() {
$scope.$watch($attrs.mathjaxBind, function(value) {
var $script = angular.element(
'<script type="math/tex">'
).html(value == undefined ? '' : value);
).html(value === undefined ? '' : value);
$element.html('');
$element.append($script);
MathJax.Hub.Queue(['Reprocess', MathJax.Hub, $element[0]]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ oppia.factory('CollectionNodeObjectFactory', [
// function is undefined if doesExplorationExist() returns false.
CollectionNode.prototype.isExplorationPrivate = function() {
if (this._explorationSummaryObject) {
return this._explorationSummaryObject.status == ACTIVITY_STATUS_PRIVATE;
return this._explorationSummaryObject.status === (
ACTIVITY_STATUS_PRIVATE);
} else {
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ oppia.factory('CollectionPlaythroughObjectFactory', [function() {
};

CollectionPlaythrough.hasFinishedCollection = function() {
return this._nextExplorationIds.length == 0;
return this._nextExplorationIds.length === 0;
};

// Returns a list of explorations completed that are related to this
Expand All @@ -60,7 +60,7 @@ oppia.factory('CollectionPlaythroughObjectFactory', [function() {
};

CollectionPlaythrough.prototype.hasStartedCollection = function() {
return this._completedExplorationIds.length != 0;
return this._completedExplorationIds.length !== 0;
};

// Static class methods. Note that "this" is not available in static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ oppia.factory('CollectionUpdateService', [
*/
isAddingCollectionNode: function(changeObject) {
var backendChangeObject = changeObject.getBackendChangeObject();
return backendChangeObject.cmd == CMD_ADD_COLLECTION_NODE;
return backendChangeObject.cmd === CMD_ADD_COLLECTION_NODE;
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ oppia.factory('CollectionValidationService', [
}

return collection.getExplorationIds().filter(function(explorationId) {
return completedExpIds.indexOf(explorationId) == -1;
return completedExpIds.indexOf(explorationId) === -1;
});
};

Expand Down Expand Up @@ -84,7 +84,7 @@ oppia.factory('CollectionValidationService', [
}

var startingExpIds = _getStartingExplorationIds(collection);
if (collectionHasNodes && startingExpIds.length != 1) {
if (collectionHasNodes && startingExpIds.length !== 1) {
issues.push(
'There should be exactly 1 exploration initially available to the ' +
'learner.');
Expand All @@ -101,14 +101,14 @@ oppia.factory('CollectionValidationService', [
});

var unreachableExpIds = _getUnreachableExplorationIds(collection);
if (unreachableExpIds.length != 0) {
if (unreachableExpIds.length !== 0) {
issues.push(
'The following exploration(s) are unreachable from the initial ' +
'exploration(s): ' + unreachableExpIds.join(', '));
}

var nonexistentExpIds = _getNonexistentExplorationIds(collection);
if (nonexistentExpIds.length != 0) {
if (nonexistentExpIds.length !== 0) {
issues.push(
'The following exploration(s) either do not exist, or you do not ' +
'have edit access to add them to this collection: ' +
Expand All @@ -117,7 +117,7 @@ oppia.factory('CollectionValidationService', [

if (isPublic) {
var privateExpIds = _getPrivateExplorationIds(collection);
if (privateExpIds.length != 0) {
if (privateExpIds.length !== 0) {
issues.push(
'Private explorations cannot be added to a public collection: ' +
privateExpIds.join(', '));
Expand Down
Loading

0 comments on commit d76f7c5

Please sign in to comment.