From 97e36cb1d9dfa00bb30e0a343960d8379c3a2f28 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Wed, 27 Sep 2017 11:08:07 -0700 Subject: [PATCH] Fix remaining lint errors, make travis run tests and linters --- .travis.yml | 2 + app/build/tasks/nylaslint-task.js | 34 --------------- .../spec/category-picker-spec.cjsx | 4 +- .../lib/preferences-templates.jsx | 6 +-- .../draft-list/lib/draft-list-toolbar.jsx | 6 ++- .../send-later/lib/send-later-button.jsx | 41 ++++--------------- .../send-later/lib/send-later-status.jsx | 8 +++- .../send-reminders-mailbox-perspective.es6 | 7 +++- .../thread-list/lib/thread-list.cjsx | 2 +- .../lib/thread-toolbar-buttons.jsx | 7 +++- .../thread-snooze/specs/snooze-store-spec.es6 | 9 +--- app/spec/auto-update-manager-spec.coffee | 4 +- .../quoted-html-transformer-spec.coffee | 2 +- app/spec/utils/utils-spec.coffee | 2 +- app/src/browser/mailspring-window.coffee | 2 +- .../contenteditable/clipboard-service.es6 | 7 +++- .../metadata-composer-toggle-button.jsx | 11 +---- app/src/components/notification.jsx | 3 +- app/src/flux/stores/message-store.coffee | 2 +- app/src/regexp-utils.coffee | 2 +- app/src/sheet-toolbar.jsx | 4 +- 21 files changed, 58 insertions(+), 107 deletions(-) diff --git a/.travis.yml b/.travis.yml index f187d05dd..ca9e857bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -78,6 +78,8 @@ before_install: script: - npm run ci-setup-mac-keychain +- npm run lint +- npm test - mailsync/build.sh - mv ./mailsync ./mailsync-src - DEBUG=electron-packager,electron-osx-sign npm run build diff --git a/app/build/tasks/nylaslint-task.js b/app/build/tasks/nylaslint-task.js index 7ac165809..308bd1adc 100644 --- a/app/build/tasks/nylaslint-task.js +++ b/app/build/tasks/nylaslint-task.js @@ -64,14 +64,6 @@ module.exports = grunt => { } } - // NOTE: Comment me in if you want to fix these files. - // _str = require('underscore.string') - // replacer = (match, describeName) -> - // fnName = _str.camelize(describeName, true) - // return "\ndescribe('#{describeName}', function #{fnName}() " - // newContent = content.replace(describeRe, replacer) - // fs.writeFileSync(f, newContent, encoding:'utf8') - // Build the list of ES6 files that export things and categorize for (const f of fileset.src) { if (!esExtensions[path.extname(f)]) { @@ -80,12 +72,6 @@ module.exports = grunt => { const lookupPath = `${path.dirname(f)}/${path.basename(f, path.extname(f))}`; const content = fs.readFileSync(f, { encoding: 'utf8' }); - if (/module.exports\s?=\s?.+/gim.test(content)) { - if (!f.endsWith('mailspring-exports.es6')) { - errors.push(`${f}: Don't use module.exports in ES6`); - } - } - if (/^export/gim.test(content)) { if (/^export default/gim.test(content)) { esExportDefault[lookupPath] = true; @@ -97,26 +83,6 @@ module.exports = grunt => { } } - // Now look again through all ES6 files, this time to check imports - // instead of exports. - for (const f of fileset.src) { - let result = null; - if (!esExtensions[path.extname(f)]) { - continue; - } - const content = fs.readFileSync(f, { encoding: 'utf8' }); - const importRe = /import \{.*\} from ['"](.*?)['"]/gim; - - while ((result = importRe.exec(content))) { - for (const requirePath of result.slice(1)) { - const lookupPath = normalizeRequirePath(requirePath, f); - if (esExportDefault[lookupPath] || esNoExport[lookupPath]) { - errors.push(`${f}: Don't destructure default export ${requirePath}`); - } - } - } - } - // Now look through all coffeescript files // If they require things from ES6 files, ensure they're using the // proper syntax. diff --git a/app/internal_packages/category-picker/spec/category-picker-spec.cjsx b/app/internal_packages/category-picker/spec/category-picker-spec.cjsx index eac6b6736..7beb8194a 100644 --- a/app/internal_packages/category-picker/spec/category-picker-spec.cjsx +++ b/app/internal_packages/category-picker/spec/category-picker-spec.cjsx @@ -25,7 +25,7 @@ describe 'MovePickerPopover', -> beforeEach -> CategoryStore._categoryCache = {} - setupFor = () -> + setupFor = -> @account = { id: TEST_ACCOUNT_ID } @@ -47,7 +47,7 @@ describe 'MovePickerPopover', -> spyOn(FocusedPerspectiveStore, 'current').andCallFake => MailboxPerspective.forCategory(@inboxCategory) - setupForCreateNew = () -> + setupForCreateNew = -> setupFor.call(@) @testThread = new Thread(id: 't1', subject: "fake", accountId: TEST_ACCOUNT_ID, categories: []) diff --git a/app/internal_packages/composer-templates/lib/preferences-templates.jsx b/app/internal_packages/composer-templates/lib/preferences-templates.jsx index e8dc98df6..4817b8af3 100644 --- a/app/internal_packages/composer-templates/lib/preferences-templates.jsx +++ b/app/internal_packages/composer-templates/lib/preferences-templates.jsx @@ -381,9 +381,9 @@ class PreferencesTemplates extends React.Component {

Reply templates are saved as HTML files in the{' '} - {`${AppEnv.getConfigDirPath()}/templates`} directory on your - computer. In raw HTML, variables are defined as HTML <code> tags with class - "var empty". + {`${AppEnv.getConfigDirPath()}/templates`} directory on your computer. + In raw HTML, variables are defined as HTML <code> tags with class "var + empty".

diff --git a/app/internal_packages/draft-list/lib/draft-list-toolbar.jsx b/app/internal_packages/draft-list/lib/draft-list-toolbar.jsx index b23d36c74..1e709d671 100644 --- a/app/internal_packages/draft-list/lib/draft-list-toolbar.jsx +++ b/app/internal_packages/draft-list/lib/draft-list-toolbar.jsx @@ -1,5 +1,9 @@ import React, { Component } from 'react'; -import { ListensToObservable, MultiselectToolbar, InjectedComponentSet } from 'mailspring-component-kit'; +import { + ListensToObservable, + MultiselectToolbar, + InjectedComponentSet, +} from 'mailspring-component-kit'; import PropTypes from 'prop-types'; import DraftListStore from './draft-list-store'; diff --git a/app/internal_packages/send-later/lib/send-later-button.jsx b/app/internal_packages/send-later/lib/send-later-button.jsx index 2092b5841..8ae0cf5dd 100644 --- a/app/internal_packages/send-later/lib/send-later-button.jsx +++ b/app/internal_packages/send-later/lib/send-later-button.jsx @@ -2,11 +2,11 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import ReactDOM from 'react-dom'; import moment from 'moment'; -import { Actions, NylasAPIHelpers, FeatureUsageStore } from 'mailspring-exports'; +import { Actions, FeatureUsageStore } from 'mailspring-exports'; import { RetinaImg } from 'mailspring-component-kit'; import SendLaterPopover from './send-later-popover'; -import { PLUGIN_ID, PLUGIN_NAME } from './send-later-constants'; +import { PLUGIN_ID } from './send-later-constants'; function sendLaterDateForDraft(draft) { return ((draft && draft.metadataForPluginId(PLUGIN_ID)) || {}).expiration; @@ -82,41 +82,16 @@ class SendLaterButton extends Component { label: dateLabel, }); } - this.onSetMetadata({ expiration: sendLaterDate }); + this.props.session.changes.addPluginMetadata(PLUGIN_ID, { + expiration: sendLaterDate, + }); }; onCancelSendLater = () => { Actions.closePopover(); - this.onSetMetadata({ expiration: null }); - }; - - onSetMetadata = async ({ expiration }) => { - const { draft, session } = this.props; - - if (!this.mounted) { - return; - } - this.setState({ saving: true }); - - try { - if (!this.mounted) { - return; - } - - session.changes.addPluginMetadata(PLUGIN_ID, { expiration }); - - if (expiration && AppEnv.isComposerWindow()) { - AppEnv.close(); - } - } catch (error) { - AppEnv.reportError(error); - AppEnv.showErrorDialog(`Sorry, we were unable to schedule this message. ${error.message}`); - } - - if (!this.mounted) { - return; - } - this.setState({ saving: false }); + this.props.session.changes.addPluginMetadata(PLUGIN_ID, { + expiration: null, + }); }; onClick = () => { diff --git a/app/internal_packages/send-later/lib/send-later-status.jsx b/app/internal_packages/send-later/lib/send-later-status.jsx index 5b7856c07..7f8179158 100644 --- a/app/internal_packages/send-later/lib/send-later-status.jsx +++ b/app/internal_packages/send-later/lib/send-later-status.jsx @@ -1,7 +1,13 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import moment from 'moment'; -import { DateUtils, Actions, SyncbackMetadataTask, TaskQueue, SendDraftTask } from 'mailspring-exports'; +import { + DateUtils, + Actions, + SyncbackMetadataTask, + TaskQueue, + SendDraftTask, +} from 'mailspring-exports'; import { RetinaImg } from 'mailspring-component-kit'; import { PLUGIN_ID } from './send-later-constants'; diff --git a/app/internal_packages/send-reminders/lib/send-reminders-mailbox-perspective.es6 b/app/internal_packages/send-reminders/lib/send-reminders-mailbox-perspective.es6 index 10449dddb..f410c96d7 100644 --- a/app/internal_packages/send-reminders/lib/send-reminders-mailbox-perspective.es6 +++ b/app/internal_packages/send-reminders/lib/send-reminders-mailbox-perspective.es6 @@ -1,4 +1,9 @@ -import { Thread, MailboxPerspective, MutableQuerySubscription, DatabaseStore } from 'mailspring-exports'; +import { + Thread, + MailboxPerspective, + MutableQuerySubscription, + DatabaseStore, +} from 'mailspring-exports'; import { PLUGIN_ID } from './send-reminders-constants'; diff --git a/app/internal_packages/thread-list/lib/thread-list.cjsx b/app/internal_packages/thread-list/lib/thread-list.cjsx index fa24dbb69..eb94fe3ab 100644 --- a/app/internal_packages/thread-list/lib/thread-list.cjsx +++ b/app/internal_packages/thread-list/lib/thread-list.cjsx @@ -289,7 +289,7 @@ class ThreadList extends React.Component return unless threads return unless AppEnv.config.get('core.workspace.showImportant') - Actions.queueTasks(TaskFactory.tasksForThreadsByAccountId(threads, (accountThreads, accountId) => + Actions.queueTasks(TaskFactory.tasksForThreadsByAccountId(threads, (accountThreads, accountId) => return new ChangeLabelsTask({ threads: accountThreads, source: "Keyboard Shortcut" diff --git a/app/internal_packages/thread-list/lib/thread-toolbar-buttons.jsx b/app/internal_packages/thread-list/lib/thread-toolbar-buttons.jsx index 34db3c570..2db292636 100644 --- a/app/internal_packages/thread-list/lib/thread-toolbar-buttons.jsx +++ b/app/internal_packages/thread-list/lib/thread-toolbar-buttons.jsx @@ -2,7 +2,12 @@ import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import { RetinaImg } from 'mailspring-component-kit'; -import { Actions, TaskFactory, FocusedContentStore, FocusedPerspectiveStore } from 'mailspring-exports'; +import { + Actions, + TaskFactory, + FocusedContentStore, + FocusedPerspectiveStore, +} from 'mailspring-exports'; import ThreadListStore from './thread-list-store'; diff --git a/app/internal_packages/thread-snooze/specs/snooze-store-spec.es6 b/app/internal_packages/thread-snooze/specs/snooze-store-spec.es6 index dbfc7b8b6..0b2189857 100644 --- a/app/internal_packages/thread-snooze/specs/snooze-store-spec.es6 +++ b/app/internal_packages/thread-snooze/specs/snooze-store-spec.es6 @@ -1,11 +1,4 @@ -import { - AccountStore, - CategoryStore, - NylasAPIHelpers, - Thread, - Actions, - Folder, -} from 'mailspring-exports'; +import { AccountStore, CategoryStore, Thread, Actions, Folder } from 'mailspring-exports'; import * as SnoozeUtils from '../lib/snooze-utils'; import SnoozeStore from '../lib/snooze-store'; diff --git a/app/spec/auto-update-manager-spec.coffee b/app/spec/auto-update-manager-spec.coffee index e132fc10b..893f325c2 100644 --- a/app/spec/auto-update-manager-spec.coffee +++ b/app/spec/auto-update-manager-spec.coffee @@ -37,7 +37,7 @@ describe "AutoUpdateManager", -> it "should update the feed URL", -> m = new AutoUpdateManager("3.222.1", @config, @specMode) spyOn(m, "setupAutoUpdater") - expect(m.feedURL.includes('anonymous')).toEqual(true); + expect(m.feedURL.includes('anonymous')).toEqual(true) @nylasIdentityId = 'test-nylas-id' m.updateFeedURL() - expect(m.feedURL.includes(@nylasIdentityId)).toEqual(true); + expect(m.feedURL.includes(@nylasIdentityId)).toEqual(true) diff --git a/app/spec/services/quoted-html-transformer-spec.coffee b/app/spec/services/quoted-html-transformer-spec.coffee index 361583820..b92674f33 100644 --- a/app/spec/services/quoted-html-transformer-spec.coffee +++ b/app/spec/services/quoted-html-transformer-spec.coffee @@ -17,7 +17,7 @@ describe "QuotedHTMLTransformer", -> html.match(re)?.length ? 0 [1..28].forEach (n) -> - fit "properly parses email_#{n}", -> + it "properly parses email_#{n}", -> opts = keepIfWholeBodyIsQuote: true actual = removeQuotedHTML("email_#{n}.html", opts).trim() expected = readFile("email_#{n}_stripped.html").trim() diff --git a/app/spec/utils/utils-spec.coffee b/app/spec/utils/utils-spec.coffee index b44be955c..c875787b6 100644 --- a/app/spec/utils/utils-spec.coffee +++ b/app/spec/utils/utils-spec.coffee @@ -38,7 +38,7 @@ describe 'Utils', -> expect(revived).toEqual([@testThread]) it "should re-inflate Models in places they're not explicitly declared types", -> - b = {id: "ThreadsToProcess", json: [@testThread]}; + b = {id: "ThreadsToProcess", json: [@testThread]} jsonString = JSON.stringify(b) expectedString = '{"id":"ThreadsToProcess","json":[{"id":"local-1","aid":"1","metadata":[],"subject":"Test 1234","categories":[],"participants":[{"id":"local-a","aid":"1","name":"Juan","email":"juan@nylas.com","thirdPartyData":{},"__cls":"Contact"},{"id":"local-b","aid":"1","name":"Ben","email":"ben@nylas.com","thirdPartyData":{},"__cls":"Contact"}],"__cls":"Thread"}]}' diff --git a/app/src/browser/mailspring-window.coffee b/app/src/browser/mailspring-window.coffee index db53e5b25..26762e509 100644 --- a/app/src/browser/mailspring-window.coffee +++ b/app/src/browser/mailspring-window.coffee @@ -80,7 +80,7 @@ class MailspringWindow loadSettings = Object.assign({}, settings) loadSettings.windowState ?= '{}' - loadSettings.appVersion = global.application.version; + loadSettings.appVersion = global.application.version loadSettings.resourcePath = @resourcePath loadSettings.devMode ?= false loadSettings.safeMode ?= false diff --git a/app/src/components/contenteditable/clipboard-service.es6 b/app/src/components/contenteditable/clipboard-service.es6 index 53fc9fc28..ba2cdece4 100644 --- a/app/src/components/contenteditable/clipboard-service.es6 +++ b/app/src/components/contenteditable/clipboard-service.es6 @@ -1,5 +1,10 @@ /* eslint global-require: 0 */ -import { InlineStyleTransformer, SanitizeTransformer, RegExpUtils, Utils } from 'mailspring-exports'; +import { + InlineStyleTransformer, + SanitizeTransformer, + RegExpUtils, + Utils, +} from 'mailspring-exports'; import ContenteditableService from './contenteditable-service'; diff --git a/app/src/components/metadata-composer-toggle-button.jsx b/app/src/components/metadata-composer-toggle-button.jsx index 03df24ae7..605152c14 100644 --- a/app/src/components/metadata-composer-toggle-button.jsx +++ b/app/src/components/metadata-composer-toggle-button.jsx @@ -1,11 +1,4 @@ -import { - React, - PropTypes, - Actions, - MailspringAPIRequest, - NylasAPIHelpers, - APIError, -} from 'mailspring-exports'; +import { React, PropTypes, Actions, MailspringAPIRequest, APIError } from 'mailspring-exports'; import { RetinaImg } from 'mailspring-component-kit'; import classnames from 'classnames'; import _ from 'underscore'; @@ -60,7 +53,7 @@ export default class MetadataComposerToggleButton extends React.Component { } async _setEnabled(enabled) { - const { pluginId, pluginName, draft, session, metadataEnabledValue } = this.props; + const { pluginId, session, metadataEnabledValue } = this.props; const metadataValue = enabled ? metadataEnabledValue : null; this.setState({ pending: true }); diff --git a/app/src/components/notification.jsx b/app/src/components/notification.jsx index 38702b52f..85fe105ef 100644 --- a/app/src/components/notification.jsx +++ b/app/src/components/notification.jsx @@ -103,8 +103,7 @@ export default class Notification extends React.Component { actions.push({ label: 'Dismiss', fn: () => { - AppEnv.savedState.dismissedNotificationAsks[this.props.displayName] = - this._numAsks() + 1; + AppEnv.savedState.dismissedNotificationAsks[this.props.displayName] = this._numAsks() + 1; this.setState({ isDismissed: true }); }, }); diff --git a/app/src/flux/stores/message-store.coffee b/app/src/flux/stores/message-store.coffee index c968e7f2c..4355d2d44 100644 --- a/app/src/flux/stores/message-store.coffee +++ b/app/src/flux/stores/message-store.coffee @@ -252,7 +252,7 @@ class MessageStore extends MailspringStore @trigger(@) _fetchMissingBodies: (items) -> - missing = items.filter((i) -> i.body == null); + missing = items.filter((i) -> i.body == null) if missing.length > 0 Actions.fetchBodies(missing) diff --git a/app/src/regexp-utils.coffee b/app/src/regexp-utils.coffee index b96666802..5c0058380 100644 --- a/app/src/regexp-utils.coffee +++ b/app/src/regexp-utils.coffee @@ -1,6 +1,6 @@ _ = require('underscore') -EmojiData = null; +EmojiData = null UnicodeEmailChars = '\u0080-\u00FF\u0100-\u017F\u0180-\u024F\u0250-\u02AF\u0300-\u036F\u0370-\u03FF\u0400-\u04FF\u0500-\u052F\u0530-\u058F\u0590-\u05FF\u0600-\u06FF\u0700-\u074F\u0750-\u077F\u0780-\u07BF\u07C0-\u07FF\u0900-\u097F\u0980-\u09FF\u0A00-\u0A7F\u0A80-\u0AFF\u0B00-\u0B7F\u0B80-\u0BFF\u0C00-\u0C7F\u0C80-\u0CFF\u0D00-\u0D7F\u0D80-\u0DFF\u0E00-\u0E7F\u0E80-\u0EFF\u0F00-\u0FFF\u1000-\u109F\u10A0-\u10FF\u1100-\u11FF\u1200-\u137F\u1380-\u139F\u13A0-\u13FF\u1400-\u167F\u1680-\u169F\u16A0-\u16FF\u1700-\u171F\u1720-\u173F\u1740-\u175F\u1760-\u177F\u1780-\u17FF\u1800-\u18AF\u1900-\u194F\u1950-\u197F\u1980-\u19DF\u19E0-\u19FF\u1A00-\u1A1F\u1B00-\u1B7F\u1D00-\u1D7F\u1D80-\u1DBF\u1DC0-\u1DFF\u1E00-\u1EFF\u1F00-\u1FFF\u20D0-\u20FF\u2100-\u214F\u2C00-\u2C5F\u2C60-\u2C7F\u2C80-\u2CFF\u2D00-\u2D2F\u2D30-\u2D7F\u2D80-\u2DDF\u2F00-\u2FDF\u2FF0-\u2FFF\u3040-\u309F\u30A0-\u30FF\u3100-\u312F\u3130-\u318F\u3190-\u319F\u31C0-\u31EF\u31F0-\u31FF\u3200-\u32FF\u3300-\u33FF\u3400-\u4DBF\u4DC0-\u4DFF\u4E00-\u9FFF\uA000-\uA48F\uA490-\uA4CF\uA700-\uA71F\uA800-\uA82F\uA840-\uA87F\uAC00-\uD7AF\uF900-\uFAFF' diff --git a/app/src/sheet-toolbar.jsx b/app/src/sheet-toolbar.jsx index 02e546187..6df238670 100644 --- a/app/src/sheet-toolbar.jsx +++ b/app/src/sheet-toolbar.jsx @@ -34,9 +34,7 @@ class WindowTitle extends React.Component { } componentDidMount() { - this.disposable = AppEnv.onWindowPropsReceived(() => - this.setState(AppEnv.getLoadSettings()) - ); + this.disposable = AppEnv.onWindowPropsReceived(() => this.setState(AppEnv.getLoadSettings())); } componentWillUnmount() {