eslint --fix

This commit is contained in:
Eric Fischer
2017-12-08 12:36:39 -05:00
parent e0112d18e3
commit 5bc6b31e29
415 changed files with 3554 additions and 3728 deletions

View File

@@ -1,7 +1,7 @@
define(['backbone'], function(Backbone) {
var Course = Backbone.Model.extend({
defaults: {
'name': ''
name: ''
},
validate: function(attrs, options) {
if (!attrs.name) {

View File

@@ -5,8 +5,8 @@ define(['backbone'], function(Backbone) {
url: '',
defaults: {
'updates': null, // UpdateCollection
'handouts': null // HandoutCollection
updates: null, // UpdateCollection
handouts: null // HandoutCollection
}
});
return CourseInfo;

View File

@@ -2,16 +2,16 @@ define(['backbone', 'jquery', 'jquery.ui'], function(Backbone, $) {
// course update -- biggest kludge here is the lack of a real id to map updates to originals
var CourseUpdate = Backbone.Model.extend({
defaults: {
'date': $.datepicker.formatDate('MM d, yy', new Date()),
'content': '',
'push_notification_enabled': false,
'push_notification_selected': false
date: $.datepicker.formatDate('MM d, yy', new Date()),
content: '',
push_notification_enabled: false,
push_notification_selected: false
},
validate: function(attrs) {
var date_exists = (attrs.date !== null && attrs.date !== '');
var date_is_valid_string = ($.datepicker.formatDate('MM d, yy', new Date(attrs.date)) === attrs.date);
if (!(date_exists && date_is_valid_string)) {
return {'date_required': gettext('Action required: Enter a valid date.')};
return {date_required: gettext('Action required: Enter a valid date.')};
}
}
});

View File

@@ -5,7 +5,7 @@
define(['backbone'], function(Backbone) {
return Backbone.Model.extend({
defaults: {
'explicit_url': ''
explicit_url: ''
},
url: function() {
return this.get('explicit_url');

View File

@@ -1,9 +1,9 @@
define(['backbone', 'underscore'], function(Backbone, _) {
var LicenseModel = Backbone.Model.extend({
defaults: {
'type': null,
'options': {},
'custom': false // either `false`, or a string
type: null,
options: {},
custom: false // either `false`, or a string
},
initialize: function(attributes) {
@@ -55,16 +55,16 @@ define(['backbone', 'underscore'], function(Backbone, _) {
if (spaceIndex == -1) {
// if there's no space, it's a license type without options
return this.set({
'type': string,
'options': {},
'custom': false
type: string,
options: {},
custom: false
}, options);
} else {
// if there is a space, it's a custom license
return this.set({
'type': null,
'options': {},
'custom': string
type: null,
options: {},
custom: string
}, options);
}
}
@@ -91,7 +91,7 @@ define(['backbone', 'underscore'], function(Backbone, _) {
});
return this.set({
'type': type, 'options': optionsObj, 'custom': false
type: type, options: optionsObj, custom: false
}, options);
}
});

View File

@@ -9,11 +9,11 @@ define(['backbone', 'underscore'], function(Backbone, _) {
},
toUrl: function(overrides) {
return;
(overrides && overrides['tag'] ? overrides['tag'] : this.get('tag')) + '://' +
(overrides && overrides['org'] ? overrides['org'] : this.get('org')) + '/' +
(overrides && overrides['course'] ? overrides['course'] : this.get('course')) + '/' +
(overrides && overrides['category'] ? overrides['category'] : this.get('category')) + '/' +
(overrides && overrides['name'] ? overrides['name'] : this.get('name')) + '/';
(overrides && overrides.tag ? overrides.tag : this.get('tag')) + '://' +
(overrides && overrides.org ? overrides.org : this.get('org')) + '/' +
(overrides && overrides.course ? overrides.course : this.get('course')) + '/' +
(overrides && overrides.category ? overrides.category : this.get('category')) + '/' +
(overrides && overrides.name ? overrides.name : this.get('name')) + '/';
},
_tagPattern: /[^:]+/g,
_fieldPattern: new RegExp('[^/]+', 'g'),
@@ -27,8 +27,7 @@ define(['backbone', 'underscore'], function(Backbone, _) {
category: payload[3],
name: payload[4]
};
}
else if (_.isString(payload)) {
} else if (_.isString(payload)) {
this._tagPattern.lastIndex = 0; // odd regex behavior requires this to be reset sometimes
var foundTag = this._tagPattern.exec(payload);
if (foundTag) {
@@ -40,18 +39,15 @@ define(['backbone', 'underscore'], function(Backbone, _) {
category: this.getNextField(payload),
name: this.getNextField(payload)
};
}
else return null;
}
else {
} else return null;
} else {
return payload;
}
},
getNextField: function(payload) {
try {
return this._fieldPattern.exec(payload)[0];
}
catch (err) {
} catch (err) {
return '';
}
}

View File

@@ -5,13 +5,13 @@ define(['backbone'], function(Backbone) {
*/
var Metadata = Backbone.Model.extend({
defaults: {
'field_name': null,
'display_name': null,
'value': null,
'explicitly_set': null,
'default_value': null,
'options': null,
'type': null
field_name: null,
display_name: null,
value: null,
explicitly_set: null,
default_value: null,
options: null,
type: null
},
initialize: function() {

View File

@@ -3,10 +3,10 @@ define(['backbone', 'js/utils/module'], function(Backbone, ModuleUtils) {
urlRoot: ModuleUtils.urlRoot,
defaults: {
'id': null,
'data': null,
'metadata': null,
'children': null
id: null,
data: null,
metadata: null,
children: null
}
});
return ModuleInfo;

View File

@@ -2,7 +2,7 @@ define(['backbone', 'gettext', 'common/js/components/views/feedback_notification
function(Backbone, gettext, NotificationView, ModuleUtils) {
var Section = Backbone.Model.extend({
defaults: {
'name': ''
name: ''
},
validate: function(attrs, options) {
if (!attrs.name) {

View File

@@ -90,7 +90,7 @@ define(['backbone', 'underscore', 'gettext', 'js/models/validation_helpers', 'js
set_videosource: function(newsource) {
// newsource either is <video youtube="speed:key, *"/> or just the "speed:key, *" string
// returns the videosource for the preview which iss the key whose speed is closest to 1
if (_.isEmpty(newsource) && !_.isEmpty(this.get('intro_video'))) this.set({'intro_video': null}, {validate: true});
if (_.isEmpty(newsource) && !_.isEmpty(this.get('intro_video'))) this.set({intro_video: null}, {validate: true});
// TODO remove all whitespace w/in string
else {
if (this.get('intro_video') !== newsource) this.set('intro_video', newsource, {validate: true});

View File

@@ -1,21 +1,21 @@
define(['backbone', 'underscore', 'gettext'], function(Backbone, _, gettext) {
var CourseGrader = Backbone.Model.extend({
defaults: {
'type': '', // must be unique w/in collection (ie. w/in course)
'min_count': 1,
'drop_count': 0,
'short_label': '', // what to use in place of type if space is an issue
'weight': 0 // int 0..100
type: '', // must be unique w/in collection (ie. w/in course)
min_count: 1,
drop_count: 0,
short_label: '', // what to use in place of type if space is an issue
weight: 0 // int 0..100
},
parse: function(attrs) {
// round off values while converting them to integer
if (attrs['weight']) {
if (attrs.weight) {
attrs.weight = Math.round(attrs.weight);
}
if (attrs['min_count']) {
if (attrs.min_count) {
attrs.min_count = Math.round(attrs.min_count);
}
if (attrs['drop_count']) {
if (attrs.drop_count) {
attrs.drop_count = Math.round(attrs.drop_count);
}
return attrs;
@@ -23,12 +23,11 @@ define(['backbone', 'underscore', 'gettext'], function(Backbone, _, gettext) {
validate: function(attrs) {
var errors = {};
if (_.has(attrs, 'type')) {
if (_.isEmpty(attrs['type'])) {
if (_.isEmpty(attrs.type)) {
errors.type = gettext('The assignment type must have a name.');
}
else {
} else {
// FIXME somehow this.collection is unbound sometimes. I can't track down when
var existing = this.collection && this.collection.some(function(other) { return (other.cid != this.cid) && (other.get('type') == attrs['type']); }, this);
var existing = this.collection && this.collection.some(function(other) { return (other.cid != this.cid) && (other.get('type') == attrs.type); }, this);
if (existing) {
errors.type = gettext("There's already another assignment type with this name.");
}
@@ -38,8 +37,7 @@ define(['backbone', 'underscore', 'gettext'], function(Backbone, _, gettext) {
var intWeight = Math.round(attrs.weight); // see if this ensures value saved is int
if (!isFinite(intWeight) || /\D+/.test(attrs.weight) || intWeight < 0 || intWeight > 100) {
errors.weight = gettext('Please enter an integer between 0 and 100.');
}
else {
} else {
attrs.weight = intWeight;
if (this.collection && attrs.weight > 0) {
// FIXME b/c saves don't update the models if validation fails, we should
@@ -48,21 +46,20 @@ define(['backbone', 'underscore', 'gettext'], function(Backbone, _, gettext) {
// if ((this.collection.sumWeights() + attrs.weight - this.get('weight')) > 100)
// errors.weight = "The weights cannot add to more than 100.";
}
} }
}
}
if (_.has(attrs, 'min_count')) {
var intMinCount = Math.round(attrs.min_count);
if (!isFinite(intMinCount) || /\D+/.test(attrs.min_count) || intMinCount < 1) {
errors.min_count = gettext('Please enter an integer greater than 0.');
}
else attrs.min_count = intMinCount;
} else attrs.min_count = intMinCount;
}
if (_.has(attrs, 'drop_count')) {
var dropCount = attrs.drop_count;
var intDropCount = Math.round(dropCount);
if (!isFinite(intDropCount) || /\D+/.test(dropCount) || (_.isString(dropCount) && _.isEmpty(dropCount.trim())) || intDropCount < 0) {
errors.drop_count = gettext('Please enter non-negative integer.');
}
else attrs.drop_count = intDropCount;
} else attrs.drop_count = intDropCount;
}
if (_.has(attrs, 'min_count') && _.has(attrs, 'drop_count') && !_.has(errors, 'min_count') && !_.has(errors, 'drop_count') && attrs.drop_count > attrs.min_count) {
var template = _.template(

View File

@@ -8,21 +8,20 @@ define(['backbone', 'js/models/location', 'js/collections/course_grader'],
minimum_grade_credit: null // either null or percentage
},
parse: function(attributes) {
if (attributes['graders']) {
if (attributes.graders) {
var graderCollection;
// interesting race condition: if {parse:true} when newing, then parse called before .attributes created
if (this.attributes && this.has('graders')) {
graderCollection = this.get('graders');
graderCollection.reset(attributes.graders, {parse: true});
}
else {
} else {
graderCollection = new CourseGraderCollection(attributes.graders, {parse: true});
}
attributes.graders = graderCollection;
}
// If grace period is unset or equal to 00:00 on the server,
// it's received as null
if (attributes['grace_period'] === null) {
if (attributes.grace_period === null) {
attributes.grace_period = {
hours: 0,
minutes: 0
@@ -37,15 +36,9 @@ define(['backbone', 'js/models/location', 'js/collections/course_grader'],
},
gracePeriodToDate: function() {
var newDate = new Date();
if (this.has('grace_period') && this.get('grace_period')['hours'])
newDate.setHours(this.get('grace_period')['hours']);
else newDate.setHours(0);
if (this.has('grace_period') && this.get('grace_period')['minutes'])
newDate.setMinutes(this.get('grace_period')['minutes']);
else newDate.setMinutes(0);
if (this.has('grace_period') && this.get('grace_period')['seconds'])
newDate.setSeconds(this.get('grace_period')['seconds']);
else newDate.setSeconds(0);
if (this.has('grace_period') && this.get('grace_period').hours) { newDate.setHours(this.get('grace_period').hours); } else newDate.setHours(0);
if (this.has('grace_period') && this.get('grace_period').minutes) { newDate.setMinutes(this.get('grace_period').minutes); } else newDate.setMinutes(0);
if (this.has('grace_period') && this.get('grace_period').seconds) { newDate.setSeconds(this.get('grace_period').seconds); } else newDate.setSeconds(0);
return newDate;
},
@@ -69,9 +62,9 @@ define(['backbone', 'js/models/location', 'js/collections/course_grader'],
},
validate: function(attrs) {
if (_.has(attrs, 'grace_period')) {
if (attrs['grace_period'] === null) {
if (attrs.grace_period === null) {
return {
'grace_period': gettext('Grace period must be specified in HH:MM format.')
grace_period: gettext('Grace period must be specified in HH:MM format.')
};
}
}
@@ -80,7 +73,7 @@ define(['backbone', 'js/models/location', 'js/collections/course_grader'],
var minimum_grade_cutoff = _.min(_.values(attrs.grade_cutoffs));
if (isNaN(attrs.minimum_grade_credit) || attrs.minimum_grade_credit === null || attrs.minimum_grade_credit < minimum_grade_cutoff) {
return {
'minimum_grade_credit': interpolate(
minimum_grade_credit: interpolate(
gettext('Not able to set passing grade to less than %(minimum_grade_cutoff)s%.'),
{minimum_grade_cutoff: minimum_grade_cutoff * 100},
true

View File

@@ -1,5 +1,5 @@
define(['backbone', 'underscore', 'gettext', 'js/models/chapter', 'js/collections/chapter',
'backbone.associations', 'cms/js/main'],
'backbone.associations', 'cms/js/main'],
function(Backbone, _, gettext, ChapterModel, ChapterCollection) {
var Textbook = Backbone.AssociatedModel.extend({
defaults: function() {
@@ -40,7 +40,7 @@ define(['backbone', 'underscore', 'gettext', 'js/models/chapter', 'js/collection
delete ret.tab_title;
}
if ('url' in ret && !('chapters' in ret)) {
ret.chapters = {'url': ret.url};
ret.chapters = {url: ret.url};
delete ret.url;
}
_.each(ret.chapters, function(chapter, i) {

View File

@@ -1,15 +1,15 @@
define(['backbone', 'underscore', 'gettext'], function(Backbone, _, gettext) {
var FileUpload = Backbone.Model.extend({
defaults: {
'title': '',
'message': '',
'selectedFile': null,
'uploading': false,
'uploadedBytes': 0,
'totalBytes': 0,
'finished': false,
'mimeTypes': [],
'fileFormats': []
title: '',
message: '',
selectedFile: null,
uploading: false,
uploadedBytes: 0,
totalBytes: 0,
finished: false,
mimeTypes: [],
fileFormats: []
},
validate: function(attrs, options) {
if (attrs.selectedFile && !this.checkTypeValidity(attrs.selectedFile)) {

View File

@@ -14,6 +14,6 @@ define(['jquery'],
};
return {
'validateIntegerRange': validateIntegerRange
validateIntegerRange: validateIntegerRange
};
});

View File

@@ -2,7 +2,7 @@ define(['js/models/custom_sync_xblock_info'],
function(CustomSyncXBlockInfo) {
var XBlockContainerInfo = CustomSyncXBlockInfo.extend({
urlRoots: {
'read': '/xblock/container'
read: '/xblock/container'
}
});
return XBlockContainerInfo;

View File

@@ -3,7 +3,7 @@ define(['js/models/custom_sync_xblock_info'],
var XBlockOutlineInfo = CustomSyncXBlockInfo.extend({
urlRoots: {
'read': '/xblock/outline'
read: '/xblock/outline'
},
createChild: function(response) {