Skip to content

Commit

Permalink
Fix oppia#6799: Add restricted globals rule to eslint (oppia#6923)
Browse files Browse the repository at this point in the history
* Add no-restricted-globals

* Remove globals

* Fix order of dependencies

* Fix test

* Add linebreaks

* Add test
  • Loading branch information
ankita240796 authored and seanlip committed Jun 16, 2019
1 parent 0b15c7d commit 4802241
Show file tree
Hide file tree
Showing 11 changed files with 174 additions and 28 deletions.
12 changes: 12 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@
"error",
"always"
],
"no-restricted-globals": [
"error", "addEventListener", "blur", "close", "closed", "confirm",
"defaultStatus", "event", "external", "defaultstatus", "find", "focus",
"frameElement", "frames", "history", "innerHeight", "innerWidth",
"length", "location", "locationbar", "menubar", "moveBy", "moveTo",
"name", "onblur", "onerror", "onfocus", "onload", "onresize", "onunload",
"open", "opener", "opera", "outerHeight", "outerWidth", "pageXOffset",
"pageYOffset", "parent", "print", "removeEventListener", "resizeBy",
"resizeTo", "screen", "screenLeft", "screenTop", "screenX", "screenY",
"scroll", "scrollbars", "scrollBy", "scrollTo", "scrollX", "scrollY",
"self", "sessionStorage", "status", "statusbar", "stop",
"toolbar", "top"],
"func-style": [
"error",
"expression"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ require('domain/utilities/UrlInterpolationService.ts');
require('services/PromoBarService.ts');

oppia.directive('promoBar', [
'PromoBarService', 'UrlInterpolationService',
function(PromoBarService, UrlInterpolationService) {
'$window', 'PromoBarService', 'UrlInterpolationService',
function($window, PromoBarService, UrlInterpolationService) {
return {
restrict: 'E',
scope: {},
Expand All @@ -36,10 +36,11 @@ oppia.directive('promoBar', [
function() {
var ctrl = this;
var isPromoDismissed = function() {
return !!angular.fromJson(sessionStorage.promoIsDismissed);
return !!angular.fromJson($window.sessionStorage.promoIsDismissed);
};
var setPromoDismissed = function(promoIsDismissed) {
sessionStorage.promoIsDismissed = angular.toJson(promoIsDismissed);
$window.sessionStorage.promoIsDismissed = angular.toJson(
promoIsDismissed);
};

PromoBarService.getPromoBarData().then(function(promoBarObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ require('domain/utilities/UrlInterpolationService.ts');
*/

oppia.controller('About', [
'$scope', 'UrlInterpolationService',
function($scope, UrlInterpolationService) {
'$scope', '$window', 'UrlInterpolationService',
function($scope, $window, UrlInterpolationService) {
// Define constants
$scope.TAB_ID_ABOUT = 'about';
$scope.TAB_ID_FOUNDATION = 'foundation';
Expand Down Expand Up @@ -62,7 +62,7 @@ oppia.controller('About', [
activateTab($scope.TAB_ID_FOUNDATION);
// Ensure page goes to the license section
if (hashChange === 'license') {
location.reload(true);
$window.location.reload(true);
}
} else if (hashChange === $scope.TAB_ID_CREDITS) {
activateTab($scope.TAB_ID_CREDITS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ require('pages/admin-page/services/admin-task-manager.service.ts');
require('pages/admin-page/admin-page.constants.ts');

oppia.directive('adminDevModeActivitiesTab', [
'$http', 'AdminTaskManagerService', 'UrlInterpolationService',
'$http', '$window', 'AdminTaskManagerService', 'UrlInterpolationService',
'ADMIN_HANDLER_URL',
function($http, AdminTaskManagerService, UrlInterpolationService,
function($http, $window, AdminTaskManagerService, UrlInterpolationService,
ADMIN_HANDLER_URL) {
return {
restrict: 'E',
Expand All @@ -44,7 +44,7 @@ oppia.directive('adminDevModeActivitiesTab', [
if (AdminTaskManagerService.isTaskRunning()) {
return;
}
if (!confirm('This action is irreversible. Are you sure?')) {
if (!$window.confirm('This action is irreversible. Are you sure?')) {
return;
}

Expand Down Expand Up @@ -73,7 +73,7 @@ oppia.directive('adminDevModeActivitiesTab', [
if (AdminTaskManagerService.isTaskRunning()) {
return;
}
if (!confirm('This action is irreversible. Are you sure?')) {
if (!$window.confirm('This action is irreversible. Are you sure?')) {
return;
}

Expand Down Expand Up @@ -142,7 +142,7 @@ oppia.directive('adminDevModeActivitiesTab', [
if (AdminTaskManagerService.isTaskRunning()) {
return;
}
if (!confirm('This action is irreversible. Are you sure?')) {
if (!$window.confirm('This action is irreversible. Are you sure?')) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ require('pages/admin-page/services/admin-task-manager.service.ts');
require('pages/admin-page/admin-page.constants.ts');

oppia.directive('adminConfigTab', [
'$http', 'AdminTaskManagerService', 'UrlInterpolationService',
'ADMIN_HANDLER_URL', function($http, AdminTaskManagerService,
'$http', '$window', 'AdminTaskManagerService', 'UrlInterpolationService',
'ADMIN_HANDLER_URL', function($http, $window, AdminTaskManagerService,
UrlInterpolationService, ADMIN_HANDLER_URL) {
return {
restrict: 'E',
Expand Down Expand Up @@ -53,7 +53,7 @@ oppia.directive('adminConfigTab', [
};

ctrl.revertToDefaultConfigPropertyValue = function(configPropertyId) {
if (!confirm('This action is irreversible. Are you sure?')) {
if (!$window.confirm('This action is irreversible. Are you sure?')) {
return;
}

Expand All @@ -73,7 +73,7 @@ oppia.directive('adminConfigTab', [
if (AdminTaskManagerService.isTaskRunning()) {
return;
}
if (!confirm('This action is irreversible. Are you sure?')) {
if (!$window.confirm('This action is irreversible. Are you sure?')) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ oppia.directive('adminMiscTab', [
if (AdminTaskManagerService.isTaskRunning()) {
return;
}
if (!confirm('This action is irreversible. Are you sure?')) {
if (!$window.confirm('This action is irreversible. Are you sure?')) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ oppia.directive('historyTab', ['UrlInterpolationService', function(
controllerAs: '$ctrl',
controller: [
'$http', '$log', '$rootScope', '$scope',
'$uibModal', 'CompareVersionsService',
'$uibModal', '$window', 'CompareVersionsService',
'DateTimeFormatService', 'EditabilityService', 'ExplorationDataService',
'UrlInterpolationService', 'VersionTreeService',
function(
$http, $log, $rootScope, $scope,
$uibModal, CompareVersionsService,
$uibModal, $window, CompareVersionsService,
DateTimeFormatService, EditabilityService, ExplorationDataService,
UrlInterpolationService, VersionTreeService) {
var ctrl = this;
Expand Down Expand Up @@ -295,7 +295,7 @@ oppia.directive('historyTab', ['UrlInterpolationService', function(
current_version: ExplorationDataService.data.version,
revert_to_version: version
}).then(function() {
location.reload();
$window.location.reload();
});
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ require('services/SiteAnalyticsService.ts');
require('services/stateful/FocusManagerService.ts');

oppia.factory('ExplorationSaveService', [
'$log', '$q', '$rootScope', '$timeout', '$uibModal',
'$log', '$q', '$rootScope', '$timeout', '$uibModal', '$window',
'AlertsService', 'AutosaveInfoModalsService', 'ChangeListService',
'ExplorationCategoryService', 'ExplorationDataService',
'ExplorationDiffService', 'ExplorationInitStateNameService',
Expand All @@ -64,7 +64,7 @@ oppia.factory('ExplorationSaveService', [
'RouterService', 'SiteAnalyticsService', 'StatesObjectFactory',
'UrlInterpolationService',
function(
$log, $q, $rootScope, $timeout, $uibModal,
$log, $q, $rootScope, $timeout, $uibModal, $window,
AlertsService, AutosaveInfoModalsService, ChangeListService,
ExplorationCategoryService, ExplorationDataService,
ExplorationDiffService, ExplorationInitStateNameService,
Expand Down Expand Up @@ -299,7 +299,7 @@ oppia.factory('ExplorationSaveService', [
// The reload is necessary because, otherwise, the
// exploration-with-draft-changes will be reloaded
// (since it is already cached in ExplorationDataService).
location.reload();
$window.location.reload();
});
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ require('services/UtilsService.ts');

oppia.controller('Preferences', [
'$http', '$q', '$rootScope', '$scope', '$timeout', '$translate', '$uibModal',
'AlertsService', 'LanguageUtilService', 'UrlInterpolationService',
'$window', 'AlertsService', 'LanguageUtilService', 'UrlInterpolationService',
'UserService', 'UtilsService', 'DASHBOARD_TYPE_CREATOR',
'DASHBOARD_TYPE_LEARNER', 'SUPPORTED_AUDIO_LANGUAGES',
'SUPPORTED_SITE_LANGUAGES',
function(
$http, $q, $rootScope, $scope, $timeout, $translate, $uibModal,
AlertsService, LanguageUtilService, UrlInterpolationService,
$window, AlertsService, LanguageUtilService, UrlInterpolationService,
UserService, UtilsService, DASHBOARD_TYPE_CREATOR,
DASHBOARD_TYPE_LEARNER, SUPPORTED_AUDIO_LANGUAGES,
SUPPORTED_SITE_LANGUAGES) {
Expand Down Expand Up @@ -243,7 +243,7 @@ oppia.controller('Preferences', [
.then(function() {
// The reload is needed in order to update the profile picture in
// the top-right corner.
location.reload();
$window.location.reload();
});
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ oppia.factory('MusicNotesInputRulesService', [
_convertSequenceToMidi(inputs.x));
},
IsLongerThan: function(answer, inputs) {
return _convertSequenceToMidi(answer).length > inputs.x;
return _convertSequenceToMidi(answer).length > inputs.k;
},
// TODO(wxy): validate that inputs.a <= inputs.b
HasLengthInclusivelyBetween: function(answer, inputs) {
var answerLength = _convertSequenceToMidi(answer).length;
return length >= inputs.a && length <= inputs.b;
return answerLength >= inputs.a && answerLength <= inputs.b;
},
IsEqualToExceptFor: function(answer, inputs) {
var targetSequence = _convertSequenceToMidi(inputs.x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,4 +612,137 @@ describe('Music Notes Input rules service', function() {
})).toBe(false);
}
);
it('should have a correct \'is longer than\' rule', function() {
expect(mnirs.IsLongerThan([{
readableNoteName: 'A4',
noteDuration: {
num: 1,
den: 1
}
}, {
readableNoteName: 'D4',
noteDuration: {
num: 1,
den: 1
}
}], {
x: [{
readableNoteName: 'A4',
noteDuration: {
num: 1,
den: 1
}
}],
k: 1
})).toBe(true);

expect(mnirs.IsLongerThan([{
readableNoteName: 'C4',
noteDuration: {
num: 1,
den: 1
}
}, {
readableNoteName: 'D4',
noteDuration: {
num: 1,
den: 1
}
}, {
readableNoteName: 'E4',
noteDuration: {
num: 1,
den: 1
}
}], {
x: [{
readableNoteName: 'C4',
noteDuration: {
num: 1,
den: 1
}
}, {
readableNoteName: 'D4',
noteDuration: {
num: 1,
den: 1
}
}, {
readableNoteName: 'E4',
noteDuration: {
num: 1,
den: 1
}
}],
k: 5
})).toBe(false);
});
it('should have a correct \'has length inclusively between\' rule',
function() {
expect(mnirs.HasLengthInclusivelyBetween([{
readableNoteName: 'A4',
noteDuration: {
num: 1,
den: 1
}
}, {
readableNoteName: 'D4',
noteDuration: {
num: 1,
den: 1
}
}], {
x: [{
readableNoteName: 'A4',
noteDuration: {
num: 1,
den: 1
}
}],
a: 1,
b: 3
})).toBe(true);

expect(mnirs.HasLengthInclusivelyBetween([{
readableNoteName: 'C4',
noteDuration: {
num: 1,
den: 1
}
}, {
readableNoteName: 'D4',
noteDuration: {
num: 1,
den: 1
}
}, {
readableNoteName: 'E4',
noteDuration: {
num: 1,
den: 1
}
}], {
x: [{
readableNoteName: 'C4',
noteDuration: {
num: 1,
den: 1
}
}, {
readableNoteName: 'D4',
noteDuration: {
num: 1,
den: 1
}
}, {
readableNoteName: 'E4',
noteDuration: {
num: 1,
den: 1
}
}],
a: 5,
b: 10
})).toBe(false);
});
});

0 comments on commit 4802241

Please sign in to comment.