From 5643aa7693d579617d9f6f19cf2a788c70771abb Mon Sep 17 00:00:00 2001 From: Clay Diffrient Date: Mon, 7 Oct 2019 10:00:29 -0600 Subject: [PATCH] Run prettier on app/coffeescripts/ from object to util This was achieved by turning the prettier rule on in .eslintrc.js then running: ./node_modules/eslint app/cofeescripts//**/*.js on each folder from the start directory to the end directory listed above. Test Plan: - Automated tests pass refs COREFE-347 flag = none Change-Id: I60a6b87e1df6ef027c22784b78abfa084ac0706b Reviewed-on: https://gerrit.instructure.com/212258 Tested-by: Jenkins Reviewed-by: Ryan Shaw QA-Review: Ryan Shaw Product-Review: Ryan Shaw --- app/coffeescripts/object/flatten.js | 2 +- app/coffeescripts/object/unflatten.js | 10 +- .../presenters/sectionEnrollmentPresenter.js | 50 +++++-- app/coffeescripts/profile/confirmEmail.js | 38 +++-- app/coffeescripts/quizzes/dump_events.js | 2 +- .../react_files/components/FolderChild.js | 2 +- .../react_files/components/FolderTree.js | 2 +- .../components/RestrictedDialogForm.js | 12 +- .../react_files/components/SearchResults.js | 10 +- .../react_files/mixins/dndMixin.js | 2 +- .../react_files/modules/BaseUploader.js | 6 +- .../modules/FileOptionsCollection.js | 2 +- .../react_files/modules/FileUploader.js | 4 +- .../react_files/modules/ZipUploader.js | 10 +- .../react_files/utils/deleteStuff.js | 2 +- .../react_files/utils/downloadStuffAsAZip.js | 2 +- .../utils/updateModelsUsageRights.js | 10 +- app/coffeescripts/regexp/rEscape.js | 2 +- .../str/__tests__/TextHelper.test.js | 22 ++- app/coffeescripts/str/apiUserContent.js | 88 ++++++----- app/coffeescripts/str/i18nLolcalize.js | 6 +- app/coffeescripts/str/splitAssetString.js | 2 +- app/coffeescripts/str/underscore.js | 2 +- app/coffeescripts/util/AvatarWidget.js | 6 +- app/coffeescripts/util/BackoffPoller.js | 20 +-- app/coffeescripts/util/BlobFactory.js | 14 +- app/coffeescripts/util/DateValidator.js | 129 ++++++++++------ app/coffeescripts/util/NumberCompare.js | 16 +- app/coffeescripts/util/PandaPubPoller.js | 9 +- app/coffeescripts/util/Popover.js | 141 ++++++++++-------- app/coffeescripts/util/SisValidationHelper.js | 26 ++-- .../util/addPrivacyLinkToDialog.js | 2 +- app/coffeescripts/util/brandableCss.js | 11 +- app/coffeescripts/util/contextList.js | 8 +- app/coffeescripts/util/coupleTimeFields.js | 6 +- app/coffeescripts/util/dateSelect.js | 14 +- app/coffeescripts/util/deparam.js | 36 +++-- app/coffeescripts/util/enrollmentName.js | 2 +- app/coffeescripts/util/friendlyBytes.js | 2 +- app/coffeescripts/util/generateUUID.js | 6 +- app/coffeescripts/util/groupHasSubmissions.js | 13 +- app/coffeescripts/util/kalturaAnalytics.js | 16 +- app/coffeescripts/util/listWithOthers.js | 12 +- app/coffeescripts/util/markAsDone.js | 2 +- app/coffeescripts/util/mimeClass.js | 82 +++++----- app/coffeescripts/util/natcompare.js | 10 +- app/coffeescripts/util/newCourseForm.js | 6 +- app/coffeescripts/util/rgb2hex.js | 12 +- app/coffeescripts/util/round.js | 2 +- app/coffeescripts/util/secondsToTime.js | 4 +- app/coffeescripts/util/semanticDateRange.js | 19 +-- app/coffeescripts/util/vddTooltip.js | 7 +- 52 files changed, 530 insertions(+), 391 deletions(-) diff --git a/app/coffeescripts/object/flatten.js b/app/coffeescripts/object/flatten.js index bde41e71cf5..eafdb8d1f87 100644 --- a/app/coffeescripts/object/flatten.js +++ b/app/coffeescripts/object/flatten.js @@ -16,7 +16,7 @@ // with this program. If not, see . // turns {foo: {bar: 1}} into {'foo[bar]': 1} -export default function flatten (obj, options = {}, result = {}, prefix) { +export default function flatten(obj, options = {}, result = {}, prefix) { for (let key in obj) { const value = obj[key] key = prefix ? `${prefix}[${key}]` : key diff --git a/app/coffeescripts/object/unflatten.js b/app/coffeescripts/object/unflatten.js index e7a168aba78..20cd66665cc 100644 --- a/app/coffeescripts/object/unflatten.js +++ b/app/coffeescripts/object/unflatten.js @@ -18,7 +18,7 @@ import _ from 'underscore' // turns {'foo[bar]': 1} into {foo: {bar: 1}} -export default function unflatten (obj) { +export default function unflatten(obj) { return _(obj).reduce((newObj, val, key) => { let keys = key.split('][') let lastKey = keys.length - 1 @@ -31,7 +31,10 @@ export default function unflatten (obj) { // Split first keys part into two parts on the [ and add them back onto // the beginning of the keys array. - keys = keys.shift().split('[').concat(keys) + keys = keys + .shift() + .split('[') + .concat(keys) lastKey = keys.length - 1 } else { // Basic 'foo' style key. @@ -53,7 +56,8 @@ export default function unflatten (obj) { while (i <= lastKey) { key = keys[i] === '' ? cur.length : keys[i] - cur = cur[key] = i < lastKey ? cur[key] || (keys[i + 1] && isNaN(keys[i + 1]) ? {} : []) : val + cur = cur[key] = + i < lastKey ? cur[key] || (keys[i + 1] && isNaN(keys[i + 1]) ? {} : []) : val i++ } } else { diff --git a/app/coffeescripts/presenters/sectionEnrollmentPresenter.js b/app/coffeescripts/presenters/sectionEnrollmentPresenter.js index d252a49998f..fda204606c4 100644 --- a/app/coffeescripts/presenters/sectionEnrollmentPresenter.js +++ b/app/coffeescripts/presenters/sectionEnrollmentPresenter.js @@ -29,26 +29,52 @@ import toUnderscore from '../str/underscore' // declare all used i18n keys here to cluttering up the logic const keys = { limited: { - get TeacherEnrollment(){ return I18n.t('enrolled_as_limited_teacher', 'enrolled as a teacher with section-only access')}, - get TaEnrollment(){ return I18n.t('enrolled_as_limited_ta', 'enrolled as a TA with section-only access')}, - get ObserverEnrollment(){ return I18n.t('enrolled_as_limited_observer', 'enrolled as a observer with section-only access')}, - get DesignerEnrollment(){ return I18n.t('enrolled_as_limited_designer', 'enrolled as a designer with section-only access')}, - get StudentEnrollment(){ return I18n.t('enrolled_as_limited_student', 'enrolled as a student with section-only access')}, + get TeacherEnrollment() { + return I18n.t('enrolled_as_limited_teacher', 'enrolled as a teacher with section-only access') + }, + get TaEnrollment() { + return I18n.t('enrolled_as_limited_ta', 'enrolled as a TA with section-only access') + }, + get ObserverEnrollment() { + return I18n.t( + 'enrolled_as_limited_observer', + 'enrolled as a observer with section-only access' + ) + }, + get DesignerEnrollment() { + return I18n.t( + 'enrolled_as_limited_designer', + 'enrolled as a designer with section-only access' + ) + }, + get StudentEnrollment() { + return I18n.t('enrolled_as_limited_student', 'enrolled as a student with section-only access') + } }, standard: { - get TeacherEnrollment(){ return I18n.t('enrolled_as_teacher', 'enrolled as a teacher')}, - get TaEnrollment(){ return I18n.t('enrolled_as_ta', 'enrolled as a TA')}, - get ObserverEnrollment(){ return I18n.t('enrolled_as_observer', 'enrolled as a observer')}, - get DesignerEnrollment(){ return I18n.t('enrolled_as_designer', 'enrolled as a designer')}, - get StudentEnrollment(){ return I18n.t('enrolled_as_student', 'enrolled as a student')}, - }, + get TeacherEnrollment() { + return I18n.t('enrolled_as_teacher', 'enrolled as a teacher') + }, + get TaEnrollment() { + return I18n.t('enrolled_as_ta', 'enrolled as a TA') + }, + get ObserverEnrollment() { + return I18n.t('enrolled_as_observer', 'enrolled as a observer') + }, + get DesignerEnrollment() { + return I18n.t('enrolled_as_designer', 'enrolled as a designer') + }, + get StudentEnrollment() { + return I18n.t('enrolled_as_student', 'enrolled as a student') + } + } } // # // begin returned function here // @param {array} array of enrollments returned from /courses/:course_id/enrollments export default data => - _.map(data, (enrollment) => { + _.map(data, enrollment => { const scope = enrollment.limit_privileges_to_course_section ? 'limited' : 'standard' // add extra fields to enrollments diff --git a/app/coffeescripts/profile/confirmEmail.js b/app/coffeescripts/profile/confirmEmail.js index d9c6d65e379..cef8827e7f1 100644 --- a/app/coffeescripts/profile/confirmEmail.js +++ b/app/coffeescripts/profile/confirmEmail.js @@ -24,22 +24,30 @@ import '../jquery.rails_flash_notifications' $(() => { let resending = false - $('.re_send_confirmation_link').click(preventDefault(function () { - const $this = $(this) - const text = $this.text() + $('.re_send_confirmation_link').click( + preventDefault(function() { + const $this = $(this) + const text = $this.text() - if (resending) return - resending = true - $this.text(I18n.t('resending', 'resending...')) + if (resending) return + resending = true + $this.text(I18n.t('resending', 'resending...')) - $.ajaxJSON($this.attr('href'), 'POST', {}, (data) => { - resending = false - $this.text(text) - $.flashMessage(I18n.t('done_resending', 'Done! Message delivery may take a few minutes.')) - }, (data) => { - resending = false - $this.text(text) - $.flashError(I18n.t('failed_resending', 'Request failed. Try again.')) + $.ajaxJSON( + $this.attr('href'), + 'POST', + {}, + data => { + resending = false + $this.text(text) + $.flashMessage(I18n.t('done_resending', 'Done! Message delivery may take a few minutes.')) + }, + data => { + resending = false + $this.text(text) + $.flashError(I18n.t('failed_resending', 'Request failed. Try again.')) + } + ) }) - })) + ) }) diff --git a/app/coffeescripts/quizzes/dump_events.js b/app/coffeescripts/quizzes/dump_events.js index d3f951dc4c7..cb7897986a1 100644 --- a/app/coffeescripts/quizzes/dump_events.js +++ b/app/coffeescripts/quizzes/dump_events.js @@ -16,7 +16,7 @@ * with this program. If not, see . */ -import eventManager from '../quizzes/log_auditing' +import eventManager from './log_auditing' export default function(unregister) { if (unregister) { diff --git a/app/coffeescripts/react_files/components/FolderChild.js b/app/coffeescripts/react_files/components/FolderChild.js index d7f6f74092d..b66af327783 100644 --- a/app/coffeescripts/react_files/components/FolderChild.js +++ b/app/coffeescripts/react_files/components/FolderChild.js @@ -116,7 +116,7 @@ export default { 'aria-selected': this.props.isSelected, draggable: !this.state.editing, ref: 'FolderChild', - onDragStart: (event) => { + onDragStart: event => { if (!this.props.isSelected) { this.props.toggleSelected() } diff --git a/app/coffeescripts/react_files/components/FolderTree.js b/app/coffeescripts/react_files/components/FolderTree.js index 24680bcdf4f..fdeb3bdfaa3 100644 --- a/app/coffeescripts/react_files/components/FolderTree.js +++ b/app/coffeescripts/react_files/components/FolderTree.js @@ -23,7 +23,7 @@ import PropTypes from 'prop-types' import BBTreeBrowserView from '../modules/BBTreeBrowserView' import RootFoldersFinder from '../../views/RootFoldersFinder' import customPropTypes from '../modules/customPropTypes' -import filesEnv from '../../react_files/modules/filesEnv' +import filesEnv from '../modules/filesEnv' import page from 'page' import '../../jquery.rails_flash_notifications' diff --git a/app/coffeescripts/react_files/components/RestrictedDialogForm.js b/app/coffeescripts/react_files/components/RestrictedDialogForm.js index 57547118ddc..2917c1b0bd7 100644 --- a/app/coffeescripts/react_files/components/RestrictedDialogForm.js +++ b/app/coffeescripts/react_files/components/RestrictedDialogForm.js @@ -120,22 +120,22 @@ export default { }, /* - * Returns true if all the models passed in have usage rights - */ + * Returns true if all the models passed in have usage rights + */ usageRightsOnAll() { return this.props.models.every(model => model.get('usage_rights')) }, /* - * Returns true if all the models passed in are folders. - */ + * Returns true if all the models passed in are folders. + */ allFolders() { return this.props.models.every(model => model instanceof Folder) }, /* - * Returns true if all the models passed in are folders. - */ + * Returns true if all the models passed in are folders. + */ anyFolders() { return this.props.models.filter(model => model instanceof Folder).length }, diff --git a/app/coffeescripts/react_files/components/SearchResults.js b/app/coffeescripts/react_files/components/SearchResults.js index 83fb1087e68..44ed95b9205 100644 --- a/app/coffeescripts/react_files/components/SearchResults.js +++ b/app/coffeescripts/react_files/components/SearchResults.js @@ -54,8 +54,8 @@ export default { const errors = _.isArray(responseText.errors) ? this.translateErrors(responseText.errors) : responseText.errors && responseText.errors.base - ? [{message: `${responseText.errors.base}, ${responseText.status}`}] - : [{message}] + ? [{message: `${responseText.errors.base}, ${responseText.status}`}] + : [{message}] this.setState({errors}) $.screenReaderFlashMessageExclusive(_.map(errors, error => error.message).join(' ')) @@ -68,14 +68,12 @@ export default { } else { return error } - }); + }) }, updateResults(props) { const oldUrl = this.state.collection.url - this.state.collection.url = `${window.location.origin}/api/v1/${this.props.contextType}/${ - this.props.contextId - }/files` + this.state.collection.url = `${window.location.origin}/api/v1/${this.props.contextType}/${this.props.contextId}/files` updateAPIQuerySortParams(this.state.collection, this.props.query) if (this.state.collection.url === oldUrl && this.state.collection.models.length > 0) { diff --git a/app/coffeescripts/react_files/mixins/dndMixin.js b/app/coffeescripts/react_files/mixins/dndMixin.js index 7a67868cb44..eeb16c3c17f 100644 --- a/app/coffeescripts/react_files/mixins/dndMixin.js +++ b/app/coffeescripts/react_files/mixins/dndMixin.js @@ -110,7 +110,7 @@ export default { } } ) - .done(this.clearSelectedItems); + .done(this.clearSelectedItems) } } // @clearSelectedItems() diff --git a/app/coffeescripts/react_files/modules/BaseUploader.js b/app/coffeescripts/react_files/modules/BaseUploader.js index 9097e4829c3..7ef334c8bc1 100644 --- a/app/coffeescripts/react_files/modules/BaseUploader.js +++ b/app/coffeescripts/react_files/modules/BaseUploader.js @@ -52,7 +52,7 @@ export default class BaseUploader { onPreflightComplete = data => { this.uploadData = data return this._actualUpload() - }; + } // kickoff / preflight upload process upload() { @@ -79,14 +79,14 @@ export default class BaseUploader { .catch(this.deferred.reject) } - onUploadPosted = event => {}; + onUploadPosted = event => {} // should be implemented in extensions trackProgress = e => { this.progress = e.loaded / e.total return this.onProgress(this.progress, this.file) - }; + } getProgress() { return this.progress diff --git a/app/coffeescripts/react_files/modules/FileOptionsCollection.js b/app/coffeescripts/react_files/modules/FileOptionsCollection.js index 3a03e15e8ff..a963f166953 100644 --- a/app/coffeescripts/react_files/modules/FileOptionsCollection.js +++ b/app/coffeescripts/react_files/modules/FileOptionsCollection.js @@ -17,7 +17,7 @@ */ import _ from 'underscore' -import UploadQueue from '../modules/UploadQueue' +import UploadQueue from './UploadQueue' import ReactDOM from 'react-dom' /* diff --git a/app/coffeescripts/react_files/modules/FileUploader.js b/app/coffeescripts/react_files/modules/FileUploader.js index f12bc2da83e..d60ae0d019a 100644 --- a/app/coffeescripts/react_files/modules/FileUploader.js +++ b/app/coffeescripts/react_files/modules/FileUploader.js @@ -24,7 +24,7 @@ export default class FileUploader extends BaseUploader { onUploadPosted = fileJson => { const file = this.addFileToCollection(fileJson) return this.deferred.resolve(file) - }; + } addFileToCollection = attrs => { const uploadedFile = new BBFile(attrs, 'no/url/needed/') // we've already done the upload, no preflight needed @@ -39,5 +39,5 @@ export default class FileUploader extends BaseUploader { } } return uploadedFile - }; + } } diff --git a/app/coffeescripts/react_files/modules/ZipUploader.js b/app/coffeescripts/react_files/modules/ZipUploader.js index 7bbb42144d3..4cc5f458db0 100644 --- a/app/coffeescripts/react_files/modules/ZipUploader.js +++ b/app/coffeescripts/react_files/modules/ZipUploader.js @@ -54,11 +54,11 @@ export default class ZipUploader extends BaseUploader { this.uploadData = data.pre_attachment this.contentMigrationId = data.id return this._actualUpload() - }; + } onUploadPosted = () => { return this.getContentMigration() - }; + } // get the content migration when ready and use progress api to pull migration progress getContentMigration = () => { @@ -71,7 +71,7 @@ export default class ZipUploader extends BaseUploader { return this.pullMigrationProgress(results.progress_url) } }) - }; + } pullMigrationProgress = url => { return $.getJSON(url).then(results => { @@ -86,7 +86,7 @@ export default class ZipUploader extends BaseUploader { return this.onMigrationComplete() } }) - }; + } onMigrationComplete() { // reload to get new files to appear @@ -98,7 +98,7 @@ export default class ZipUploader extends BaseUploader { trackProgress = e => { this.progress = e.loaded / e.total return this.onProgress(this.progress, this.file) - }; + } // migration progress is [0..100] trackMigrationProgress(value) { diff --git a/app/coffeescripts/react_files/utils/deleteStuff.js b/app/coffeescripts/react_files/utils/deleteStuff.js index a64638a54ef..d83b80688b8 100644 --- a/app/coffeescripts/react_files/utils/deleteStuff.js +++ b/app/coffeescripts/react_files/utils/deleteStuff.js @@ -90,5 +90,5 @@ export default function deleteStuff(filesAndFolders, args) { if (args && args.returnFocusTo) { $(args.returnFocusTo).focus() } - }); + }) } diff --git a/app/coffeescripts/react_files/utils/downloadStuffAsAZip.js b/app/coffeescripts/react_files/utils/downloadStuffAsAZip.js index b39d69e64a2..63650c50047 100644 --- a/app/coffeescripts/react_files/utils/downloadStuffAsAZip.js +++ b/app/coffeescripts/react_files/utils/downloadStuffAsAZip.js @@ -98,5 +98,5 @@ export default function downloadStuffAsAZip(filesAndFolders, {contextType, conte .always(() => { $(window).off('beforeunload', promptBeforeLeaving) $progressIndicator.remove() - }); + }) } diff --git a/app/coffeescripts/react_files/utils/updateModelsUsageRights.js b/app/coffeescripts/react_files/utils/updateModelsUsageRights.js index 063a776a025..8d61680caa2 100644 --- a/app/coffeescripts/react_files/utils/updateModelsUsageRights.js +++ b/app/coffeescripts/react_files/utils/updateModelsUsageRights.js @@ -22,11 +22,11 @@ import File from '../../models/File' import ModuleFile from '../../models/ModuleFile' /* - * Sets usage rights on the models in memory based on the response from the - * API. - * apiData - the response from the API - * models - an array containing the files/folders to update - */ + * Sets usage rights on the models in memory based on the response from the + * API. + * apiData - the response from the API + * models - an array containing the files/folders to update + */ // Grab the ids affected from the apiData export default function updateModelsUsageRights(apiData, models) { const affectedIds = apiData && apiData.file_ids diff --git a/app/coffeescripts/regexp/rEscape.js b/app/coffeescripts/regexp/rEscape.js index 6aeaf34db65..52ada435d23 100644 --- a/app/coffeescripts/regexp/rEscape.js +++ b/app/coffeescripts/regexp/rEscape.js @@ -15,6 +15,6 @@ // You should have received a copy of the GNU Affero General Public License along // with this program. If not, see . -export default function rEscape (string) { +export default function rEscape(string) { return string.replace(/[\\\^\$\*\+\?\.\(\)\|\{\}\[\]]/g, '\\$&') } diff --git a/app/coffeescripts/str/__tests__/TextHelper.test.js b/app/coffeescripts/str/__tests__/TextHelper.test.js index 92ff52fcc9c..3ed4cf2eed8 100644 --- a/app/coffeescripts/str/__tests__/TextHelper.test.js +++ b/app/coffeescripts/str/__tests__/TextHelper.test.js @@ -1,5 +1,25 @@ +/* + * Copyright (C) 2019 - present Instructure, Inc. + * + * This file is part of Canvas. + * + * Canvas is free software: you can redistribute it and/or modify it under + * the terms of the GNU Affero General Public License as published by the Free + * Software Foundation, version 3 of the License. + * + * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more + * details. + * + * You should have received a copy of the GNU Affero General Public License along + * with this program. If not, see . + */ + import TextHelper from '../TextHelper' test('truncateText', () => { - expect(TextHelper.truncateText('this is longer than 30 characters')).toBe('this is longer than 30...') + expect(TextHelper.truncateText('this is longer than 30 characters')).toBe( + 'this is longer than 30...' + ) }) diff --git a/app/coffeescripts/str/apiUserContent.js b/app/coffeescripts/str/apiUserContent.js index 8f6f38dfde6..62351e7870e 100644 --- a/app/coffeescripts/str/apiUserContent.js +++ b/app/coffeescripts/str/apiUserContent.js @@ -24,24 +24,26 @@ const apiUserContent = { /* xsslint safeString.identifier mathml */ - translateMathmlForScreenreaders ($equationImage) { + translateMathmlForScreenreaders($equationImage) { // note, it is safe to treat the x-canvaslms-safe-mathml as html because it // only ever gets put there by us (in Api::Html::Content::apply_mathml). // Any user content that gets sent to the server will have the // x-canvaslms-safe-mathml attribute stripped out. - const mathml = $('
').html($equationImage.attr('x-canvaslms-safe-mathml')).html() + const mathml = $('
') + .html($equationImage.attr('x-canvaslms-safe-mathml')) + .html() const mathmlSpan = $('') mathmlSpan.html(mathml) return mathmlSpan }, - toMediaCommentLink (node) { + toMediaCommentLink(node) { const $link = $( `` ) $link.html($(node).html()) @@ -53,12 +55,14 @@ const apiUserContent = { */ // use this method to process any user content fields returned in api responses // this is important to handle object/embed tags safely, and to properly display audio/video tags - convert (html, options = {}) { + convert(html, options = {}) { const $dummy = $('
').html(html) // finds any