Skip to content

Commit

Permalink
Introduce eslint: space-before-blocks rule (oppia#6048)
Browse files Browse the repository at this point in the history
Changes have been made as suggested here:
oppia#5842 (comment)
  • Loading branch information
apb7 authored and seanlip committed Jan 4, 2019
1 parent d2a7fc3 commit 718d4d0
Show file tree
Hide file tree
Showing 19 changed files with 54 additions and 49 deletions.
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@
"error",
"always"
],
"space-before-blocks": [
"error",
"always"
],
"space-before-function-paren": [
"error",
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ oppia.factory('ContentIdsToAudioTranslationsObjectFactory', [
for (contentId in this._contentIdsToAudioTranslations) {
var audioTanslations = this._contentIdsToAudioTranslations[contentId];
var audioTranslationsDict = {};
Object.keys(audioTanslations).forEach(function(lang){
Object.keys(audioTanslations).forEach(function(lang) {
audioTranslationsDict[lang] = audioTanslations[lang].toBackendDict();
});
contentIdsToAudioTranslationsDict[contentId] = audioTranslationsDict;
Expand All @@ -152,7 +152,7 @@ oppia.factory('ContentIdsToAudioTranslationsObjectFactory', [
var audioTanslationsDict = (
contentIdsToAudioTranslationsDict[contentId]);
var audioTranslations = {};
Object.keys(audioTanslationsDict).forEach(function(langCode){
Object.keys(audioTanslationsDict).forEach(function(langCode) {
audioTranslations[langCode] = (
AudioTranslationObjectFactory.createFromBackendDict(
audioTanslationsDict[langCode]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe('ContentIdsToAudioTranslations object factory', function() {
citat = citatof.createFromBackendDict(citatDict);
}));

it('should get all content id', function(){
it('should get all content id', function() {
var contentIdList = [
'content', 'default_outcome', 'feedback_1', 'feedback_2', 'hint_1',
'hint_2', 'solution'];
Expand Down Expand Up @@ -158,32 +158,32 @@ describe('ContentIdsToAudioTranslations object factory', function() {
});
});

it('should get all language code for a given content id', function(){
it('should get all language code for a given content id', function() {
var LanguageCodeList = ['en', 'hi'];
expect(citat.getAudioLanguageCodes('hint_1')).toEqual(LanguageCodeList);
});

it('should correctly check content id has audio translations', function(){
it('should correctly check content id has audio translations', function() {
expect(citat.hasAudioTranslations('content')).toBe(true);
expect(citat.hasAudioTranslations('hint_2')).toBe(false);
});

it('should correctly check content id has unflagged audio translations',
function(){
function() {
expect(citat.hasUnflaggedAudioTranslations('content')).toBe(true);
citat.markAllAudioAsNeedingUpdate('solution');
expect(citat.hasUnflaggedAudioTranslations('solution')).toBe(false);
});

it('should add a given content id', function(){
it('should add a given content id', function() {
citat.addContentId('feedback_3');
expect(citat.getBindableAudioTranslations('feedback_3')).toEqual({});
expect(function() {
citat.addContentId('content');
}).toThrowError('Trying to add duplicate content id.');
});

it('should delete a given content id', function(){
it('should delete a given content id', function() {
citat.deleteContentId('feedback_1');
var contentIdList = [
'content', 'default_outcome', 'feedback_2', 'hint_1', 'hint_2',
Expand All @@ -194,7 +194,7 @@ describe('ContentIdsToAudioTranslations object factory', function() {
}).toThrowError('Unable to find the given content id.');
});

it('should delete all feedback content id', function(){
it('should delete all feedback content id', function() {
citat.deleteAllFeedbackContentId();
var contentIdList = [
'content', 'default_outcome', 'hint_1', 'hint_2', 'solution'];
Expand All @@ -214,7 +214,7 @@ describe('ContentIdsToAudioTranslations object factory', function() {
'language code hi-en');
}));

it('should add audio translation in a given content id', function(){
it('should add audio translation in a given content id', function() {
citat.addAudioTranslation('hint_2', 'en', 'filename11.mp3', 1000);
expect(citat.getBindableAudioTranslations('hint_2')).toEqual({
en: atof.createFromBackendDict({
Expand All @@ -228,7 +228,7 @@ describe('ContentIdsToAudioTranslations object factory', function() {
}).toThrowError('Trying to add duplicate language code.');
});

it('should delete audio translation in a given content id', function(){
it('should delete audio translation in a given content id', function() {
citat.deleteAudioTranslation('content', 'hi');
expect(citat.getBindableAudioTranslations('content')).toEqual({
en: atof.createFromBackendDict({
Expand All @@ -239,7 +239,7 @@ describe('ContentIdsToAudioTranslations object factory', function() {
});
});

it('should delete all feedback audio translation', function(){
it('should delete all feedback audio translation', function() {
var contentIdList = [
'content', 'default_outcome', 'feedback_1', 'feedback_2', 'hint_1',
'hint_2', 'solution'];
Expand All @@ -249,15 +249,16 @@ describe('ContentIdsToAudioTranslations object factory', function() {
'content', 'default_outcome', 'hint_1', 'hint_2', 'solution']);
});

it('should toggle needs update attribute in a given content id', function(){
citat.toggleNeedsUpdateAttribute('content', 'hi');
expect(citat.getAudioTranslation('content', 'hi')).toEqual(
atof.createFromBackendDict({
filename: 'filename2.mp3',
file_size_bytes: 11000,
needs_update: true
}));
});
it(
'should toggle needs update attribute in a given content id', function() {
citat.toggleNeedsUpdateAttribute('content', 'hi');
expect(citat.getAudioTranslation('content', 'hi')).toEqual(
atof.createFromBackendDict({
filename: 'filename2.mp3',
file_size_bytes: 11000,
needs_update: true
}));
});

it('should correctly convert to backend dict', function() {
expect(citat.toBackendDict()).toEqual(citatDict);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Feedback thread object factory', function() {
FeedbackThreadObjectFactory = $injector.get('FeedbackThreadObjectFactory');
}));

it('should create a new feedback thread from a backend dict.', function(){
it('should create a new feedback thread from a backend dict.', function() {
feedbackThreadBackendDict = {
last_updated: 1000,
original_author_username: 'author',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Learner playlist service factory', function() {
spyOn(AlertsService, 'addSuccessMessage').and.callThrough();
}));

beforeEach(function(){
beforeEach(function() {
addToLearnerPlaylistUrl = (
UrlInterpolationService.interpolateUrl(
'/learnerplaylistactivityhandler/<activityType>/<activityId>', {
Expand All @@ -55,7 +55,7 @@ describe('Learner playlist service factory', function() {
$httpBackend.verifyNoOutstandingRequest();
});

it('should successfully add playlist to play later list', function(){
it('should successfully add playlist to play later list', function() {
var response = {
belongs_to_completed_or_incomplete_list: false,
belongs_to_subscribed_activities: false,
Expand All @@ -73,7 +73,7 @@ describe('Learner playlist service factory', function() {
});

it('should not add playlist to play later list' +
'and show belongs to completed or incomplete list', function(){
'and show belongs to completed or incomplete list', function() {
var response = {
belongs_to_completed_or_incomplete_list: true,
belongs_to_subscribed_activities: false,
Expand All @@ -91,7 +91,7 @@ describe('Learner playlist service factory', function() {
});

it('should not add playlist to play later list' +
'and show belongs to subscribed activities', function(){
'and show belongs to subscribed activities', function() {
var response = {
belongs_to_completed_or_incomplete_list: false,
belongs_to_subscribed_activities: true,
Expand All @@ -109,7 +109,7 @@ describe('Learner playlist service factory', function() {
});

it('should not add playlist to play later list' +
'and show playlist limit exceeded', function(){
'and show playlist limit exceeded', function() {
var response = {
belongs_to_completed_or_incomplete_list: false,
belongs_to_subscribed_activities: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ describe('SidebarStatusService', function() {
expect(SidebarStatusService.isSidebarShown()).toBe(false);
});

it('should toggle the sidebar to open and then close', function(){
it('should toggle the sidebar to open and then close', function() {
SidebarStatusService.toggleSidebar();
expect(SidebarStatusService.isSidebarShown()).toBe(true);
SidebarStatusService.toggleSidebar();
expect(SidebarStatusService.isSidebarShown()).toBe(false);
});


it('should falsify pendingSidebarClick on document click', function(){
it('should falsify pendingSidebarClick on document click', function() {
SidebarStatusService.openSidebar();
SidebarStatusService.onDocumentClick();
expect(SidebarStatusService.isSidebarShown()).toBe(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ oppia.factory('StoryContentsObjectFactory', [
nodesQueue.push(nodeId);
}
}
for (var i = 0; i < nodeIsVisited.length; i++){
for (var i = 0; i < nodeIsVisited.length; i++) {
if (!nodeIsVisited[i]) {
_disconnectedNodeIds.push(nodeIds[i]);
issues.push(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Suggestion object factory', function() {
SuggestionObjectFactory = $injector.get('SuggestionObjectFactory');
}));

it('should create a new suggestion from a backend dict.', function(){
it('should create a new suggestion from a backend dict.', function() {
suggestionBackendDict = {
suggestion_id: 'exploration.exp1.thread1',
suggestion_type: 'edit_exploration_state_content',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Suggestion thread object factory', function() {
SuggestionObjectFactory = $injector.get('SuggestionObjectFactory');
}));

it('should create a new suggestion thread from a backend dict.', function(){
it('should create a new suggestion thread from a backend dict.', function() {
suggestionThreadBackendDict = {
last_updated: 1000,
original_author_username: 'author',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,10 @@ describe('URL Interpolation Service', function() {
expect(uis.getStoryUrl('/storyId', {})).toBe('/story/storyId');
expect(uis.getStoryUrl('/storyId123', {})).toBe('/story/storyId123');
expect(uis.getStoryUrl('/story&Id', {})).toBe('/story/story&Id');
expect(function(){
expect(function() {
uis.getStoryUrl('', {});
}).toThrowError('Empty path passed in method.');
expect(function(){
expect(function() {
uis.getStoryUrl('storyId', {});
}).toThrowError('Path must start with \'/\': \'storyId\'.');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ oppia.factory('ImagePreloaderService', [
return _filenamesOfImageCurrentlyDownloading;
},
getImageUrl: function(filename) {
return $q(function(resolve, reject){
return $q(function(resolve, reject) {
if (AssetsBackendApiService.isCached(filename) ||
_isInFailedDownload(filename)) {
_getImageUrl(filename, resolve, reject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ oppia.directive('searchBar', [
* onMenuKeypress($event, 'category', {enter: 'open'})
*/

$scope.onMenuKeypress = function(evt, menuName, eventsTobeHandled){
$scope.onMenuKeypress = function(evt, menuName, eventsTobeHandled) {
NavigationService.onMenuKeypress(evt, menuName, eventsTobeHandled);
$scope.activeMenuName = NavigationService.activeMenuName;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('GenerateContentIdService', function() {
.toEqual('worked_example_2');
});

it('should throw error for unknown content id', function(){
it('should throw error for unknown content id', function() {
expect(function() {
gcis.getNextId('xyz');
}).toThrowError('Unknown component name provided.');
Expand Down
2 changes: 1 addition & 1 deletion core/templates/dev/head/services/NavigationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @fileoverview Factory for navigating the top navigation bar with
* tab and shift-tab.
*/
oppia.factory('NavigationService', [function(){
oppia.factory('NavigationService', [function() {
var navigation = {};
navigation.activeMenuName = '';
navigation.ACTION_OPEN = 'open';
Expand Down
8 changes: 4 additions & 4 deletions core/templates/dev/head/services/contextual/UrlServiceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,24 @@ describe('Url Service', function() {
UrlService.getTopicNameFromLearnerUrl()
).toBe('topic name');
mockLocation.pathname = '/topc/abcdefgijklm';
expect(function(){
expect(function() {
UrlService.getTopicNameFromLearnerUrl();
}).toThrowError('Invalid URL for topic');
});

it('should correctly retrieve story id from url', function() {
mockLocation.pathname = '/story_editor/abcdefgijklm';
expect(function(){
expect(function() {
UrlService.getStoryIdFromUrl();
}).toThrow();

mockLocation.pathname = '/storyeditor/abcdefgijklm/012345678901';
expect(function(){
expect(function() {
UrlService.getStoryIdFromUrl();
}).toThrow();

mockLocation.pathname = '/story_editor/abcdefgijlm/012345678901';
expect(function(){
expect(function() {
UrlService.getStoryIdFromUrl();
}).toThrow();

Expand Down
4 changes: 2 additions & 2 deletions core/tests/protractor_desktop/editorAndPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ describe('Full exploration editor', function() {
general.moveToPlayer();
explorationPlayerPage.submitAnswer('Continue');
element.all(
by.css('.protractor-test-back-button')).then(function(buttons){
by.css('.protractor-test-back-button')).then(function(buttons) {
expect(buttons.length).toBe(1);
});
explorationPlayerPage.submitAnswer('LogicProof');
element.all(
by.css('.protractor-test-back-button')).then(function(buttons){
by.css('.protractor-test-back-button')).then(function(buttons) {
expect(buttons.length).toBe(0);
});

Expand Down
4 changes: 2 additions & 2 deletions core/tests/protractor_utils/AdminPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var forms = require('./forms.js');
var general = require('./general.js');
var waitFor = require('./waitFor.js');

var AdminPage = function(){
var AdminPage = function() {
var ADMIN_URL_SUFFIX = '/admin';
var configTab = element(by.css('.protractor-test-admin-config-tab'));
var saveAllConfigs = element(by.css('.protractor-test-save-all-configs'));
Expand Down Expand Up @@ -112,7 +112,7 @@ var AdminPage = function(){
});
};

this.get = function(){
this.get = function() {
browser.get(ADMIN_URL_SUFFIX);
return waitFor.pageToFullyLoad();
};
Expand Down
2 changes: 1 addition & 1 deletion core/tests/protractor_utils/ExplorationEditorHistoryTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ var ExplorationEditorHistoryTab = function() {
expect(states.length).toEqual(expectedStates.length);
// Note: we need to compare this way because the state graph is
// sometimes generated with states in different configurations.
states.forEach(function(element){
states.forEach(function(element) {
expect(expectedStates).toContain(element);
});
});
Expand Down
4 changes: 2 additions & 2 deletions core/tests/protractor_utils/LibraryPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
var forms = require('./forms.js');
var waitFor = require('./waitFor.js');

var LibraryPage = function(){
var LibraryPage = function() {
var LIBRARY_URL_SUFFIX = '/library';
var allCollectionSummaryTile = element.all(
by.css('.protractor-test-collection-summary-tile'));
Expand Down Expand Up @@ -162,7 +162,7 @@ var LibraryPage = function(){
});
};

this.clickCreateActivity = function(){
this.clickCreateActivity = function() {
createActivityButton.click();
waitFor.pageToFullyLoad();
};
Expand Down

0 comments on commit 718d4d0

Please sign in to comment.