Skip to content

Commit

Permalink
Lint all the JavaScript files.
Browse files Browse the repository at this point in the history
  • Loading branch information
seanlip committed Dec 27, 2015
1 parent dbbe8b2 commit 2e77286
Show file tree
Hide file tree
Showing 163 changed files with 11,154 additions and 9,439 deletions.
12 changes: 9 additions & 3 deletions .jscsrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
{
"preset": "google",
"excludeFiles": [
"third_party/**"
"third_party/**",
"core/templates/dev/head/expressions/parser.js",
"core/templates/prod/**",
"core/tests/protractor.conf.js"
],
"fileExtensions": [".js"],
"extract": ["*.html"],
Expand Down Expand Up @@ -141,12 +144,15 @@
"requireSpacesInNamedFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"safeContextKeyword": ["that"],
"safeContextKeyword": ["that", "context", "textAngular"],
"validateCommentPosition": {
"position": "above"
},
"validateIndentation": 2,
"validateLineBreaks": "LF",
"validateParameterSeparator": ", ",
"validateQuoteMarks": "'"
"validateQuoteMarks": {
"mark": "'",
"escape": true
}
}
97 changes: 53 additions & 44 deletions core/templates/dev/head/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ oppia.config(['$interpolateProvider', '$httpProvider',
$interpolateProvider.endSymbol(']>');

$httpProvider.defaults.headers.post = {
'Content-Type': 'application/x-www-form-urlencoded'};
'Content-Type': 'application/x-www-form-urlencoded'
};
$httpProvider.defaults.headers.put = {
'Content-Type': 'application/x-www-form-urlencoded'};
'Content-Type': 'application/x-www-form-urlencoded'
};

$httpProvider.interceptors.push([
'$q', '$log', 'warningsData', function($q, $log, warningsData) {
Expand Down Expand Up @@ -88,24 +90,25 @@ oppia.config(['$provide', function($provide) {
var _originalError = $delegate.error;

if (window.GLOBALS && !window.GLOBALS.DEV_MODE) {
$delegate.log = function(message) { };
$delegate.info = function(message) { };
$delegate.log = function() {};
$delegate.info = function() {};
// TODO(sll): Send errors (and maybe warnings) to the backend.
$delegate.warn = function(message) { };
$delegate.warn = function() { };
$delegate.error = function(message) {
if (String(message).indexOf('$digest already in progress') === -1) {
_originalError(message);
}
};
$delegate.error.logs = []; // This keeps angular-mocks happy (in tests).
// This keeps angular-mocks happy (in tests).
$delegate.error.logs = [];
}

return $delegate;
}]);
}]);

//Returns true if the user is on a mobile device.
//See here: http://stackoverflow.com/a/14301832/5020618
// Returns true if the user is on a mobile device.
// See: http://stackoverflow.com/a/14301832/5020618
oppia.factory('deviceInfoService', ['$window', function($window) {
return {
isMobileDevice: function() {
Expand All @@ -123,6 +126,7 @@ oppia.factory('$exceptionHandler', ['$log', function($log) {
return function(exception, cause) {
var messageAndSourceAndStackTrace = [
'',
'Cause: ' + cause,
'Source: ' + window.location.href,
exception.message,
String(exception.stack)
Expand All @@ -137,14 +141,16 @@ oppia.factory('$exceptionHandler', ['$log', function($log) {
url: '/frontend_errors',
data: $.param({
csrf_token: GLOBALS.csrf_token,
payload: JSON.stringify({error: messageAndSourceAndStackTrace}),
payload: JSON.stringify({
error: messageAndSourceAndStackTrace
}),
source: document.URL
}, true),
contentType: 'application/x-www-form-urlencoded',
dataType: 'text',
async: true
});
} catch(loggingError) {
} catch (loggingError) {
$log.warn('Error logging failed.');
}

Expand Down Expand Up @@ -176,7 +182,7 @@ oppia.factory('oppiaHtmlEscaper', ['$log', function($log) {
escapedStrToUnescapedStr: function(value) {
return String(value)
.replace(/"/g, '"')
.replace(/'/g, "'")
.replace(/'/g, '\'')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&amp;/g, '&');
Expand Down Expand Up @@ -215,8 +221,9 @@ oppia.factory('validatorsService', [
/**
* Checks whether an entity name is valid, and displays a warning message
* if it isn't.
* @param {string} input The input to be checked.
* @param {boolean} showWarnings Whether to show warnings in the butterbar.
* @param {string} input - The input to be checked.
* @param {boolean} showWarnings - Whether to show warnings in the
* butterbar.
* @return {boolean} True if the entity name is valid, false otherwise.
*/
isValidEntityName: function(input, showWarnings) {
Expand Down Expand Up @@ -269,7 +276,7 @@ oppia.factory('validatorsService', [
}
return true;
}
}
};
}]);

oppia.constant('LABEL_FOR_CLEARING_FOCUS', 'labelForClearingFocus');
Expand All @@ -279,42 +286,44 @@ oppia.constant('LABEL_FOR_CLEARING_FOCUS', 'labelForClearingFocus');
// Note: This requires LABEL_FOR_CLEARING_FOCUS to exist somewhere in the HTML
// page.
oppia.factory('focusService', [
'$rootScope', '$timeout', 'deviceInfoService', 'LABEL_FOR_CLEARING_FOCUS',
function($rootScope, $timeout, deviceInfoService, LABEL_FOR_CLEARING_FOCUS) {
var _nextLabelToFocusOn = null;
return {
clearFocus: function() {
this.setFocus(LABEL_FOR_CLEARING_FOCUS);
},
setFocus: function(name) {
if (_nextLabelToFocusOn) {
return;
}
'$rootScope', '$timeout', 'deviceInfoService', 'LABEL_FOR_CLEARING_FOCUS',
function($rootScope, $timeout, deviceInfoService, LABEL_FOR_CLEARING_FOCUS) {
var _nextLabelToFocusOn = null;
return {
clearFocus: function() {
this.setFocus(LABEL_FOR_CLEARING_FOCUS);
},
setFocus: function(name) {
if (_nextLabelToFocusOn) {
return;
}

_nextLabelToFocusOn = name;
$timeout(function() {
$rootScope.$broadcast('focusOn', _nextLabelToFocusOn);
_nextLabelToFocusOn = null;
});
},
setFocusIfOnDesktop: function(newFocusLabel) {
if (!deviceInfoService.isMobileDevice()) {
this.setFocus(newFocusLabel);
_nextLabelToFocusOn = name;
$timeout(function() {
$rootScope.$broadcast('focusOn', _nextLabelToFocusOn);
_nextLabelToFocusOn = null;
});
},
setFocusIfOnDesktop: function(newFocusLabel) {
if (!deviceInfoService.isMobileDevice()) {
this.setFocus(newFocusLabel);
}
},
// Generates a random string (to be used as a focus label).
generateFocusLabel: function() {
return Math.random().toString(36).slice(2);
}
},
// Generates a random string (to be used as a focus label).
generateFocusLabel: function() {
return Math.random().toString(36).slice(2);
}
};
}]);
};
}
]);

// Service for manipulating the page URL.
oppia.factory('urlService', ['$window', function($window) {
return {
getUrlParams: function() {
var params = {};
var parts = $window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) {
var parts = $window.location.href.replace(
/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) {
params[key] = value;
});
return params;
Expand All @@ -337,7 +346,7 @@ oppia.factory('windowDimensionsService', ['$window', function($window) {
}]);

// Service for debouncing function calls.
oppia.factory('oppiaDebouncer', ['$log', function($log) {
oppia.factory('oppiaDebouncer', [function() {
return {
// Returns a function that will not be triggered as long as it continues to
// be invoked. The function only gets executed after it stops being called
Expand All @@ -361,7 +370,7 @@ oppia.factory('oppiaDebouncer', ['$log', function($log) {
args = null;
}
}
}
};

return function() {
context = this;
Expand Down
46 changes: 28 additions & 18 deletions core/templates/dev/head/appSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ describe('Validators service', function() {
}));

it('should correctly validate entity names', function() {
GLOBALS = {INVALID_NAME_CHARS: 'xyz'};
GLOBALS = {
INVALID_NAME_CHARS: 'xyz'
};

expect(vs.isValidEntityName('b')).toBe(true);
expect(vs.isValidEntityName('b ')).toBe(true);
Expand Down Expand Up @@ -64,7 +66,8 @@ describe('HTML escaper', function() {
ohe = $injector.get('oppiaHtmlEscaper');
}));

it('should correctly translate between escaped and unescaped strings', function() {
it('should correctly translate between escaped and unescaped strings',
function() {
var strs = ['abc', 'a&b<html>', '&&&&&'];
for (var i = 0; i < strs.length; i++) {
expect(ohe.escapedStrToUnescapedStr(
Expand All @@ -73,7 +76,9 @@ describe('HTML escaper', function() {
});

it('should correctly escape and unescape JSON', function() {
var objs = [{'a': 'b'}, ['a', 'b'], 2, true, 'abc'];
var objs = [{
a: 'b'
}, ['a', 'b'], 2, true, 'abc'];
for (var i = 0; i < objs.length; i++) {
expect(ohe.escapedJsonToObj(
ohe.objToEscapedJson(objs[i]))).toEqual(objs[i]);
Expand All @@ -90,7 +95,7 @@ describe('Datetime Formatter', function() {
var NOW_MILLIS = 1416563100000;
var YESTERDAY_MILLIS = NOW_MILLIS - 24 * 60 * 60 * 1000;
var df = null;
var oldDate = Date;
var OldDate = Date;

beforeEach(inject(function($injector) {
df = $injector.get('oppiaDatetimeFormatter');
Expand All @@ -99,51 +104,56 @@ describe('Datetime Formatter', function() {
// doesn't seem to be a good way to set the timezone locale directly.)
spyOn(window, 'Date').andCallFake(function(optionalMillisSinceEpoch) {
if (optionalMillisSinceEpoch) {
return new oldDate(optionalMillisSinceEpoch);
return new OldDate(optionalMillisSinceEpoch);
} else {
return new oldDate(NOW_MILLIS);
return new OldDate(NOW_MILLIS);
}
});
}));

it('should show only the time for a datetime occurring today', function() {
// In any timezone, 10 minutes before xx:45:00 should still fall within the
// same date as xx:45:00 in getLocaleAbbreviateDatetimeString().
// In any timezone, 10 minutes before xx:45:00 should still fall within
// the same date as xx:45:00 in getLocaleAbbreviateDatetimeString().
expect(df.getLocaleAbbreviatedDatetimeString(
NOW_MILLIS - 10 * 60 * 1000)).not.toBe('11/21/2014');
expect(df.getLocaleAbbreviatedDatetimeString(
NOW_MILLIS - 10 * 60 * 1000)).not.toBe('2014/11/21');
});

it('should show only the date for a datetime occurring before today', function() {
it('should show only the date for a datetime occurring before today',
function() {
// 72 hours ago. This is 18 Nov 2014 09:45:00 GMT, which corresponds to
// 17 Nov 2014 in some parts of the world, and 18 Nov 2014 in others.
// Also have into account different locales where the order of time/date
// formatting is different. This should hold true in
// getLocaleAbbreviateDatetimeString()
expect(['11/18/2014', '11/17/2014', '2014/11/18', '2014/11/17', '18/11/2014']).toContain(
expect([
'11/18/2014', '11/17/2014', '2014/11/18', '2014/11/17', '18/11/2014'
]).toContain(
df.getLocaleAbbreviatedDatetimeString(
NOW_MILLIS - 72 * 60 * 60 * 1000));
});

it('should show the date even for a datetime occurring today', function() {
// In any timezone, 10 minutes before xx:45:00 should still fall within the
// same date as xx:45:00 in getLocaleDateString(). The date should always
// be shown as '11/21/2014'
// In any timezone, 10 minutes before xx:45:00 should still fall within
// the same date as xx:45:00 in getLocaleDateString(). The date should
// always be shown as '11/21/2014'
expect(df.getLocaleDateString(
NOW_MILLIS - 10 * 60 * 1000)).toBe('11/21/2014');
expect(df.getLocaleDateString(
NOW_MILLIS - 10 * 60 * 1000)).not.toBe('2014/11/21');
});

it('should show only the date for a datetime occurring before today', function() {
it('should show only the date for a datetime occurring before today',
function() {
// 72 hours ago. This is 18 Nov 2014 09:45:00 GMT, which corresponds to
// 17 Nov 2014 in some parts of the world, and 18 Nov 2014 in others.
// Also have into account different locales where the order of time/date
// formatting is different. This should hold true in getLocaleDateString().
expect(['11/18/2014', '11/17/2014', '2014/11/18', '2014/11/17', '18/11/2014']).toContain(
df.getLocaleDateString(
NOW_MILLIS - 72 * 60 * 60 * 1000));
// formatting is different. This should hold true in
// getLocaleDateString().
expect([
'11/18/2014', '11/17/2014', '2014/11/18', '2014/11/17', '18/11/2014'
]).toContain(df.getLocaleDateString(NOW_MILLIS - 72 * 60 * 60 * 1000));
});
});
});
Loading

0 comments on commit 2e77286

Please sign in to comment.