From 64d63b9d4ab3c6f6d1f48c4e9f06010913f7970c Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Thu, 21 Feb 2019 14:49:43 +0100 Subject: [PATCH 1/9] Fix syntax error in fixture --- packages/go-to-line/spec/fixtures/sample.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/go-to-line/spec/fixtures/sample.js b/packages/go-to-line/spec/fixtures/sample.js index cb53d4078..e09a93919 100644 --- a/packages/go-to-line/spec/fixtures/sample.js +++ b/packages/go-to-line/spec/fixtures/sample.js @@ -14,7 +14,7 @@ var quicksort = function () { // adapted from: // https://github.com/nzakas/computer-science-in-javascript/tree/master/algorithms/sorting/merge-sort-recursive -var mergeSort function (items){ +var mergeSort = function (items){ var merge = function (left, right){ var result = []; var il = 0; From 7e23d4dc7a77bb5b226bfd2c2965fabab851d89c Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Thu, 21 Feb 2019 14:48:21 +0100 Subject: [PATCH 2/9] Run prettier on packages/ folder --- packages/about/lib/about.js | 30 +- .../about/lib/components/about-status-bar.js | 20 +- packages/about/lib/components/about-view.js | 159 ++++++--- packages/about/lib/components/atom-logo.js | 81 ++++- packages/about/lib/components/update-view.js | 142 +++++--- packages/about/lib/etch-component.js | 3 +- packages/about/lib/main.js | 35 +- packages/about/lib/update-manager.js | 17 +- packages/about/spec/about-spec.js | 11 +- packages/about/spec/about-status-bar-spec.js | 12 +- .../about/spec/helpers/async-spec-helpers.js | 6 +- packages/about/spec/mocks/updater.js | 4 +- packages/about/spec/update-manager-spec.js | 20 +- packages/about/spec/update-view-spec.js | 217 +++++++++--- packages/dalek/lib/dalek.js | 4 +- packages/dalek/test/dalek.test.js | 53 ++- packages/dalek/test/runner.js | 2 +- .../lib/deprecation-cop-view.js | 321 +++++++++++------ packages/deprecation-cop/lib/main.js | 39 ++- .../dev-live-reload/lib/base-theme-watcher.js | 11 +- packages/dev-live-reload/lib/main.js | 12 +- .../dev-live-reload/lib/package-watcher.js | 6 +- packages/dev-live-reload/lib/ui-watcher.js | 80 +++-- packages/dev-live-reload/lib/watcher.js | 12 +- .../spec/async-spec-helpers.js | 7 +- .../spec/dev-live-reload-spec.js | 28 +- .../dev-live-reload/spec/ui-watcher-spec.js | 111 ++++-- packages/exception-reporting/lib/main.js | 44 ++- packages/exception-reporting/lib/reporter.js | 122 ++++--- .../exception-reporting/spec/reporter-spec.js | 331 +++++++++++------- packages/git-diff/lib/diff-list-view.js | 30 +- packages/git-diff/lib/git-diff-view.js | 82 +++-- packages/git-diff/lib/main.js | 12 +- packages/git-diff/spec/diff-list-view-spec.js | 10 +- packages/git-diff/spec/git-diff-spec.js | 91 +++-- packages/go-to-line/lib/go-to-line-view.js | 18 +- packages/go-to-line/spec/go-to-line-spec.js | 8 +- .../grammar-selector/lib/grammar-list-view.js | 17 +- .../lib/grammar-status-view.js | 37 +- packages/grammar-selector/lib/main.js | 12 +- .../spec/async-spec-helpers.js | 5 +- .../spec/grammar-selector-spec.js | 101 ++++-- .../lib/incompatible-packages-component.js | 78 +++-- packages/incompatible-packages/lib/main.js | 30 +- .../lib/status-icon-component.js | 4 +- .../incompatible-packages-component-spec.js | 180 ++++++---- .../spec/incompatible-packages-spec.js | 10 +- packages/line-ending-selector/lib/main.js | 191 +++++----- .../lib/status-bar-item.js | 17 +- .../spec/line-ending-selector-spec.js | 100 ++++-- packages/link/lib/link.js | 36 +- packages/link/spec/async-spec-helpers.js | 7 +- packages/link/spec/link-spec.js | 28 +- packages/one-dark-ui/spec/theme-spec.js | 26 +- packages/one-light-ui/spec/theme-spec.js | 26 +- 55 files changed, 2077 insertions(+), 1019 deletions(-) diff --git a/packages/about/lib/about.js b/packages/about/lib/about.js index 1221bda6d..1fe660e9f 100644 --- a/packages/about/lib/about.js +++ b/packages/about/lib/about.js @@ -1,4 +1,4 @@ -const {CompositeDisposable, Emitter} = require('atom') +const { CompositeDisposable, Emitter } = require('atom') const AboutView = require('./components/about-view') // Deferred requires @@ -14,16 +14,22 @@ module.exports = class About { aboutView: null } - this.subscriptions.add(atom.workspace.addOpener((uriToOpen) => { - if (uriToOpen === this.state.uri) { - return this.deserialize() - } - })) + this.subscriptions.add( + atom.workspace.addOpener(uriToOpen => { + if (uriToOpen === this.state.uri) { + return this.deserialize() + } + }) + ) - this.subscriptions.add(atom.commands.add('atom-workspace', 'about:view-release-notes', () => { - shell = shell || require('electron').shell - shell.openExternal(this.state.updateManager.getReleaseNotesURLForCurrentVersion()) - })) + this.subscriptions.add( + atom.commands.add('atom-workspace', 'about:view-release-notes', () => { + shell = shell || require('electron').shell + shell.openExternal( + this.state.updateManager.getReleaseNotesURLForCurrentVersion() + ) + }) + ) } destroy () { @@ -31,14 +37,14 @@ module.exports = class About { this.views.aboutView = null if (this.state.updateManager) this.state.updateManager.dispose() - this.setState({updateManager: null}) + this.setState({ updateManager: null }) this.subscriptions.dispose() } setState (newState) { if (newState && typeof newState === 'object') { - let {state} = this + let { state } = this this.state = Object.assign({}, state, newState) this.didChange() diff --git a/packages/about/lib/components/about-status-bar.js b/packages/about/lib/components/about-status-bar.js index d55800f5d..4529b6ae8 100644 --- a/packages/about/lib/components/about-status-bar.js +++ b/packages/about/lib/components/about-status-bar.js @@ -1,16 +1,20 @@ -const {CompositeDisposable} = require('atom') +const { CompositeDisposable } = require('atom') const etch = require('etch') const EtchComponent = require('../etch-component') const $ = etch.dom -module.exports = -class AboutStatusBar extends EtchComponent { +module.exports = class AboutStatusBar extends EtchComponent { constructor () { super() this.subscriptions = new CompositeDisposable() - this.subscriptions.add(atom.tooltips.add(this.element, {title: 'An update will be installed the next time Atom is relaunched.

Click the squirrel icon for more information.'})) + this.subscriptions.add( + atom.tooltips.add(this.element, { + title: + 'An update will be installed the next time Atom is relaunched.

Click the squirrel icon for more information.' + }) + ) } handleClick () { @@ -18,8 +22,12 @@ class AboutStatusBar extends EtchComponent { } render () { - return $.div({className: 'about-release-notes inline-block', onclick: this.handleClick.bind(this)}, - $.span({type: 'button', className: 'icon icon-squirrel'}) + return $.div( + { + className: 'about-release-notes inline-block', + onclick: this.handleClick.bind(this) + }, + $.span({ type: 'button', className: 'icon icon-squirrel' }) ) } diff --git a/packages/about/lib/components/about-view.js b/packages/about/lib/components/about-view.js index 3e370b171..34fb7cba9 100644 --- a/packages/about/lib/components/about-view.js +++ b/packages/about/lib/components/about-view.js @@ -1,4 +1,4 @@ -const {Disposable} = require('atom') +const { Disposable } = require('atom') const etch = require('etch') const shell = require('shell') const AtomLogo = require('./atom-logo') @@ -7,8 +7,7 @@ const UpdateView = require('./update-view') const $ = etch.dom -module.exports = -class AboutView extends EtchComponent { +module.exports = class AboutView extends EtchComponent { handleAtomVersionClick (e) { e.preventDefault() atom.clipboard.write(this.props.currentAtomVersion) @@ -31,12 +30,17 @@ class AboutView extends EtchComponent { handleReleaseNotesClick (e) { e.preventDefault() - shell.openExternal(this.props.updateManager.getReleaseNotesURLForAvailableVersion()) + shell.openExternal( + this.props.updateManager.getReleaseNotesURLForAvailableVersion() + ) } handleLicenseClick (e) { e.preventDefault() - atom.commands.dispatch(atom.views.getView(atom.workspace), 'application:open-license') + atom.commands.dispatch( + atom.views.getView(atom.workspace), + 'application:open-license' + ) } handleTermsOfUseClick (e) { @@ -46,7 +50,9 @@ class AboutView extends EtchComponent { handleHowToUpdateClick (e) { e.preventDefault() - shell.openExternal('https://flight-manual.atom.io/getting-started/sections/installing-atom/') + shell.openExternal( + 'https://flight-manual.atom.io/getting-started/sections/installing-atom/' + ) } handleShowMoreClick (e) { @@ -66,39 +72,87 @@ class AboutView extends EtchComponent { } render () { - return $.div({className: 'pane-item native-key-bindings about'}, - $.div({className: 'about-container'}, - $.header({className: 'about-header'}, - $.a({className: 'about-atom-io', href: 'https://atom.io'}, + return $.div( + { className: 'pane-item native-key-bindings about' }, + $.div( + { className: 'about-container' }, + $.header( + { className: 'about-header' }, + $.a( + { className: 'about-atom-io', href: 'https://atom.io' }, $(AtomLogo) ), - $.div({className: 'about-header-info'}, - $.span({className: 'about-version-container inline-block atom', onclick: this.handleAtomVersionClick.bind(this)}, - $.span({className: 'about-version'}, `${this.props.currentAtomVersion} ${process.arch}`), - $.span({className: 'icon icon-clippy about-copy-version'}) + $.div( + { className: 'about-header-info' }, + $.span( + { + className: 'about-version-container inline-block atom', + onclick: this.handleAtomVersionClick.bind(this) + }, + $.span( + { className: 'about-version' }, + `${this.props.currentAtomVersion} ${process.arch}` + ), + $.span({ className: 'icon icon-clippy about-copy-version' }) ), - $.a({className: 'about-header-release-notes', onclick: this.handleReleaseNotesClick.bind(this)}, 'Release Notes') + $.a( + { + className: 'about-header-release-notes', + onclick: this.handleReleaseNotesClick.bind(this) + }, + 'Release Notes' + ) ), - $.span({className: 'about-version-container inline-block show-more-expand', onclick: this.handleShowMoreClick.bind(this)}, - $.span({className: 'about-more-expand'}, 'Show more') + $.span( + { + className: + 'about-version-container inline-block show-more-expand', + onclick: this.handleShowMoreClick.bind(this) + }, + $.span({ className: 'about-more-expand' }, 'Show more') ), - $.div({className: 'show-more hidden about-more-info'}, - $.div({className: 'about-more-info'}, - $.span({className: 'about-version-container inline-block electron', onclick: this.handleElectronVersionClick.bind(this)}, - $.span({className: 'about-more-version'}, `Electron: ${this.props.currentElectronVersion} `), - $.span({className: 'icon icon-clippy about-copy-version'}) + $.div( + { className: 'show-more hidden about-more-info' }, + $.div( + { className: 'about-more-info' }, + $.span( + { + className: 'about-version-container inline-block electron', + onclick: this.handleElectronVersionClick.bind(this) + }, + $.span( + { className: 'about-more-version' }, + `Electron: ${this.props.currentElectronVersion} ` + ), + $.span({ className: 'icon icon-clippy about-copy-version' }) ) ), - $.div({className: 'about-more-info'}, - $.span({className: 'about-version-container inline-block chrome', onclick: this.handleChromeVersionClick.bind(this)}, - $.span({className: 'about-more-version'}, `Chrome: ${this.props.currentChromeVersion} `), - $.span({className: 'icon icon-clippy about-copy-version'}) + $.div( + { className: 'about-more-info' }, + $.span( + { + className: 'about-version-container inline-block chrome', + onclick: this.handleChromeVersionClick.bind(this) + }, + $.span( + { className: 'about-more-version' }, + `Chrome: ${this.props.currentChromeVersion} ` + ), + $.span({ className: 'icon icon-clippy about-copy-version' }) ) ), - $.div({className: 'about-more-info'}, - $.span({className: 'about-version-container inline-block node', onclick: this.handleNodeVersionClick.bind(this)}, - $.span({className: 'about-more-version'}, `Node: ${this.props.currentNodeVersion} `), - $.span({className: 'icon icon-clippy about-copy-version'}) + $.div( + { className: 'about-more-info' }, + $.span( + { + className: 'about-version-container inline-block node', + onclick: this.handleNodeVersionClick.bind(this) + }, + $.span( + { className: 'about-more-version' }, + `Node: ${this.props.currentNodeVersion} ` + ), + $.span({ className: 'icon icon-clippy about-copy-version' }) ) ) ) @@ -112,24 +166,43 @@ class AboutView extends EtchComponent { viewUpdateInstructions: this.handleHowToUpdateClick.bind(this) }), - $.div({className: 'about-actions group-item'}, - $.div({className: 'btn-group'}, - $.button({className: 'btn view-license', onclick: this.handleLicenseClick.bind(this)}, 'License'), - $.button({className: 'btn terms-of-use', onclick: this.handleTermsOfUseClick.bind(this)}, 'Terms of Use') + $.div( + { className: 'about-actions group-item' }, + $.div( + { className: 'btn-group' }, + $.button( + { + className: 'btn view-license', + onclick: this.handleLicenseClick.bind(this) + }, + 'License' + ), + $.button( + { + className: 'btn terms-of-use', + onclick: this.handleTermsOfUseClick.bind(this) + }, + 'Terms of Use' + ) ) ), - $.div({className: 'about-love group-start'}, - $.span({className: 'icon icon-code'}), - $.span({className: 'inline'}, ' with '), - $.span({className: 'icon icon-heart'}), - $.span({className: 'inline'}, ' by '), - $.a({className: 'icon icon-logo-github', href: 'https://github.com'}) + $.div( + { className: 'about-love group-start' }, + $.span({ className: 'icon icon-code' }), + $.span({ className: 'inline' }, ' with '), + $.span({ className: 'icon icon-heart' }), + $.span({ className: 'inline' }, ' by '), + $.a({ className: 'icon icon-logo-github', href: 'https://github.com' }) ), - $.div({className: 'about-credits group-item'}, - $.span({className: 'inline'}, 'And the awesome '), - $.a({href: 'https://github.com/atom/atom/contributors'}, 'Atom Community') + $.div( + { className: 'about-credits group-item' }, + $.span({ className: 'inline' }, 'And the awesome '), + $.a( + { href: 'https://github.com/atom/atom/contributors' }, + 'Atom Community' + ) ) ) } diff --git a/packages/about/lib/components/atom-logo.js b/packages/about/lib/components/atom-logo.js index f8b620ce1..bd50fc7a2 100644 --- a/packages/about/lib/components/atom-logo.js +++ b/packages/about/lib/components/atom-logo.js @@ -3,23 +3,74 @@ const EtchComponent = require('../etch-component') const $ = etch.dom -module.exports = -class AtomLogo extends EtchComponent { +module.exports = class AtomLogo extends EtchComponent { render () { - return $.svg({className: 'about-logo', width: '330px', height: '68px', viewBox: '0 0 330 68'}, - $.g({stroke: 'none', 'stroke-width': '1', fill: 'none', 'fill-rule': 'evenodd'}, - $.g({transform: 'translate(2.000000, 1.000000)'}, - $.g({transform: 'translate(96.000000, 8.000000)', fill: 'currentColor'}, - $.path({d: 'M185.498,3.399 C185.498,2.417 186.34,1.573 187.324,1.573 L187.674,1.573 C188.447,1.573 189.01,1.995 189.5,2.628 L208.676,30.862 L227.852,2.628 C228.272,1.995 228.905,1.573 229.676,1.573 L230.028,1.573 C231.01,1.573 231.854,2.417 231.854,3.399 L231.854,49.403 C231.854,50.387 231.01,51.231 230.028,51.231 C229.044,51.231 228.202,50.387 228.202,49.403 L228.202,8.246 L210.151,34.515 C209.729,35.148 209.237,35.428 208.606,35.428 C207.973,35.428 207.481,35.148 207.061,34.515 L189.01,8.246 L189.01,49.475 C189.01,50.457 188.237,51.231 187.254,51.231 C186.27,51.231 185.498,50.458 185.498,49.475 L185.498,3.399 L185.498,3.399 Z'}), - $.path({d: 'M113.086,26.507 L113.086,26.367 C113.086,12.952 122.99,0.941 137.881,0.941 C152.77,0.941 162.533,12.811 162.533,26.225 L162.533,26.367 C162.533,39.782 152.629,51.792 137.74,51.792 C122.85,51.792 113.086,39.923 113.086,26.507 M158.74,26.507 L158.74,26.367 C158.74,14.216 149.89,4.242 137.74,4.242 C125.588,4.242 116.879,14.075 116.879,26.225 L116.879,26.367 C116.879,38.518 125.729,48.491 137.881,48.491 C150.031,48.491 158.74,38.658 158.74,26.507'}), - $.path({d: 'M76.705,5.155 L60.972,5.155 C60.06,5.155 59.287,4.384 59.287,3.469 C59.287,2.556 60.059,1.783 60.972,1.783 L96.092,1.783 C97.004,1.783 97.778,2.555 97.778,3.469 C97.778,4.383 97.005,5.155 96.092,5.155 L80.358,5.155 L80.358,49.405 C80.358,50.387 79.516,51.231 78.532,51.231 C77.55,51.231 76.706,50.387 76.706,49.405 L76.706,5.155 L76.705,5.155 Z'}), - $.path({d: 'M0.291,48.562 L21.291,3.05 C21.783,1.995 22.485,1.292 23.75,1.292 L23.891,1.292 C25.155,1.292 25.858,1.995 26.348,3.05 L47.279,48.421 C47.49,48.843 47.56,49.194 47.56,49.546 C47.56,50.458 46.788,51.231 45.803,51.231 C44.961,51.231 44.329,50.599 43.978,49.826 L38.219,37.183 L9.21,37.183 L3.45,49.897 C3.099,50.739 2.538,51.231 1.694,51.231 C0.781,51.231 0.008,50.529 0.008,49.685 C0.009,49.404 0.08,48.983 0.291,48.562 L0.291,48.562 Z M36.673,33.882 L23.749,5.437 L10.755,33.882 L36.673,33.882 L36.673,33.882 Z'}) + return $.svg( + { + className: 'about-logo', + width: '330px', + height: '68px', + viewBox: '0 0 330 68' + }, + $.g( + { + stroke: 'none', + 'stroke-width': '1', + fill: 'none', + 'fill-rule': 'evenodd' + }, + $.g( + { transform: 'translate(2.000000, 1.000000)' }, + $.g( + { + transform: 'translate(96.000000, 8.000000)', + fill: 'currentColor' + }, + $.path({ + d: + 'M185.498,3.399 C185.498,2.417 186.34,1.573 187.324,1.573 L187.674,1.573 C188.447,1.573 189.01,1.995 189.5,2.628 L208.676,30.862 L227.852,2.628 C228.272,1.995 228.905,1.573 229.676,1.573 L230.028,1.573 C231.01,1.573 231.854,2.417 231.854,3.399 L231.854,49.403 C231.854,50.387 231.01,51.231 230.028,51.231 C229.044,51.231 228.202,50.387 228.202,49.403 L228.202,8.246 L210.151,34.515 C209.729,35.148 209.237,35.428 208.606,35.428 C207.973,35.428 207.481,35.148 207.061,34.515 L189.01,8.246 L189.01,49.475 C189.01,50.457 188.237,51.231 187.254,51.231 C186.27,51.231 185.498,50.458 185.498,49.475 L185.498,3.399 L185.498,3.399 Z' + }), + $.path({ + d: + 'M113.086,26.507 L113.086,26.367 C113.086,12.952 122.99,0.941 137.881,0.941 C152.77,0.941 162.533,12.811 162.533,26.225 L162.533,26.367 C162.533,39.782 152.629,51.792 137.74,51.792 C122.85,51.792 113.086,39.923 113.086,26.507 M158.74,26.507 L158.74,26.367 C158.74,14.216 149.89,4.242 137.74,4.242 C125.588,4.242 116.879,14.075 116.879,26.225 L116.879,26.367 C116.879,38.518 125.729,48.491 137.881,48.491 C150.031,48.491 158.74,38.658 158.74,26.507' + }), + $.path({ + d: + 'M76.705,5.155 L60.972,5.155 C60.06,5.155 59.287,4.384 59.287,3.469 C59.287,2.556 60.059,1.783 60.972,1.783 L96.092,1.783 C97.004,1.783 97.778,2.555 97.778,3.469 C97.778,4.383 97.005,5.155 96.092,5.155 L80.358,5.155 L80.358,49.405 C80.358,50.387 79.516,51.231 78.532,51.231 C77.55,51.231 76.706,50.387 76.706,49.405 L76.706,5.155 L76.705,5.155 Z' + }), + $.path({ + d: + 'M0.291,48.562 L21.291,3.05 C21.783,1.995 22.485,1.292 23.75,1.292 L23.891,1.292 C25.155,1.292 25.858,1.995 26.348,3.05 L47.279,48.421 C47.49,48.843 47.56,49.194 47.56,49.546 C47.56,50.458 46.788,51.231 45.803,51.231 C44.961,51.231 44.329,50.599 43.978,49.826 L38.219,37.183 L9.21,37.183 L3.45,49.897 C3.099,50.739 2.538,51.231 1.694,51.231 C0.781,51.231 0.008,50.529 0.008,49.685 C0.009,49.404 0.08,48.983 0.291,48.562 L0.291,48.562 Z M36.673,33.882 L23.749,5.437 L10.755,33.882 L36.673,33.882 L36.673,33.882 Z' + }) ), - $.g({}, - $.path({d: 'M40.363,32.075 C40.874,34.44 39.371,36.77 37.006,37.282 C34.641,37.793 32.311,36.29 31.799,33.925 C31.289,31.56 32.791,29.23 35.156,28.718 C37.521,28.207 39.851,29.71 40.363,32.075', fill: 'currentColor'}), - $.path({d: 'M48.578,28.615 C56.851,45.587 58.558,61.581 52.288,64.778 C45.822,68.076 33.326,56.521 24.375,38.969 C15.424,21.418 13.409,4.518 19.874,1.221 C22.689,-0.216 26.648,1.166 30.959,4.629', stroke: 'currentColor', 'stroke-width': '3.08', 'stroke-linecap': 'round'}), - $.path({d: 'M7.64,39.45 C2.806,36.94 -0.009,33.915 0.154,30.79 C0.531,23.542 16.787,18.497 36.462,19.52 C56.137,20.544 71.781,27.249 71.404,34.497 C71.241,37.622 68.127,40.338 63.06,42.333', stroke: 'currentColor', 'stroke-width': '3.08', 'stroke-linecap': 'round'}), - $.path({d: 'M28.828,59.354 C23.545,63.168 18.843,64.561 15.902,62.653 C9.814,58.702 13.572,42.102 24.296,25.575 C35.02,9.048 48.649,-1.149 54.736,2.803 C57.566,4.639 58.269,9.208 57.133,15.232', stroke: 'currentColor', 'stroke-width': '3.08', 'stroke-linecap': 'round'}) + $.g( + {}, + $.path({ + d: + 'M40.363,32.075 C40.874,34.44 39.371,36.77 37.006,37.282 C34.641,37.793 32.311,36.29 31.799,33.925 C31.289,31.56 32.791,29.23 35.156,28.718 C37.521,28.207 39.851,29.71 40.363,32.075', + fill: 'currentColor' + }), + $.path({ + d: + 'M48.578,28.615 C56.851,45.587 58.558,61.581 52.288,64.778 C45.822,68.076 33.326,56.521 24.375,38.969 C15.424,21.418 13.409,4.518 19.874,1.221 C22.689,-0.216 26.648,1.166 30.959,4.629', + stroke: 'currentColor', + 'stroke-width': '3.08', + 'stroke-linecap': 'round' + }), + $.path({ + d: + 'M7.64,39.45 C2.806,36.94 -0.009,33.915 0.154,30.79 C0.531,23.542 16.787,18.497 36.462,19.52 C56.137,20.544 71.781,27.249 71.404,34.497 C71.241,37.622 68.127,40.338 63.06,42.333', + stroke: 'currentColor', + 'stroke-width': '3.08', + 'stroke-linecap': 'round' + }), + $.path({ + d: + 'M28.828,59.354 C23.545,63.168 18.843,64.561 15.902,62.653 C9.814,58.702 13.572,42.102 24.296,25.575 C35.02,9.048 48.649,-1.149 54.736,2.803 C57.566,4.639 58.269,9.208 57.133,15.232', + stroke: 'currentColor', + 'stroke-width': '3.08', + 'stroke-linecap': 'round' + }) ) ) ) diff --git a/packages/about/lib/components/update-view.js b/packages/about/lib/components/update-view.js index a4e97e74d..4399b58b4 100644 --- a/packages/about/lib/components/update-view.js +++ b/packages/about/lib/components/update-view.js @@ -4,12 +4,14 @@ const UpdateManager = require('../update-manager') const $ = etch.dom -module.exports = -class UpdateView extends EtchComponent { +module.exports = class UpdateView extends EtchComponent { constructor (props) { super(props) - if (this.props.updateManager.getAutoUpdatesEnabled() && this.props.updateManager.getState() === UpdateManager.State.Idle) { + if ( + this.props.updateManager.getAutoUpdatesEnabled() && + this.props.updateManager.getState() === UpdateManager.State.Idle + ) { this.props.updateManager.checkForUpdate() } } @@ -19,12 +21,18 @@ class UpdateView extends EtchComponent { } shouldUpdateActionButtonBeDisabled () { - let {state} = this.props.updateManager - return state === UpdateManager.State.CheckingForUpdate || state === UpdateManager.State.DownloadingUpdate + let { state } = this.props.updateManager + return ( + state === UpdateManager.State.CheckingForUpdate || + state === UpdateManager.State.DownloadingUpdate + ) } executeUpdateAction () { - if (this.props.updateManager.state === UpdateManager.State.UpdateAvailableToInstall) { + if ( + this.props.updateManager.state === + UpdateManager.State.UpdateAvailableToInstall + ) { this.props.updateManager.restartAndInstallUpdate() } else { this.props.updateManager.checkForUpdate() @@ -36,44 +44,86 @@ class UpdateView extends EtchComponent { switch (this.props.updateManager.state) { case UpdateManager.State.Idle: - updateStatus = $.div({className: 'about-updates-item is-shown about-default-update-message'}, - this.props.updateManager.getAutoUpdatesEnabled() ? 'Atom will check for updates automatically' : 'Automatic updates are disabled please check manually' + updateStatus = $.div( + { + className: + 'about-updates-item is-shown about-default-update-message' + }, + this.props.updateManager.getAutoUpdatesEnabled() + ? 'Atom will check for updates automatically' + : 'Automatic updates are disabled please check manually' ) break case UpdateManager.State.CheckingForUpdate: - updateStatus = $.div({className: 'about-updates-item app-checking-for-updates'}, - $.span({className: 'about-updates-label icon icon-search'}, 'Checking for updates...') + updateStatus = $.div( + { className: 'about-updates-item app-checking-for-updates' }, + $.span( + { className: 'about-updates-label icon icon-search' }, + 'Checking for updates...' + ) ) break case UpdateManager.State.DownloadingUpdate: - updateStatus = $.div({className: 'about-updates-item app-downloading-update'}, - $.span({className: 'loading loading-spinner-tiny inline-block'}), - $.span({className: 'about-updates-label'}, 'Downloading update') + updateStatus = $.div( + { className: 'about-updates-item app-downloading-update' }, + $.span({ className: 'loading loading-spinner-tiny inline-block' }), + $.span({ className: 'about-updates-label' }, 'Downloading update') ) break case UpdateManager.State.UpdateAvailableToInstall: - updateStatus = $.div({className: 'about-updates-item app-update-available-to-install'}, - $.span({className: 'about-updates-label icon icon-squirrel'}, 'New update'), - $.span({className: 'about-updates-version'}, this.props.availableVersion), - $.a({className: 'about-updates-release-notes', onclick: this.props.viewUpdateReleaseNotes}, 'Release Notes') + updateStatus = $.div( + { className: 'about-updates-item app-update-available-to-install' }, + $.span( + { className: 'about-updates-label icon icon-squirrel' }, + 'New update' + ), + $.span( + { className: 'about-updates-version' }, + this.props.availableVersion + ), + $.a( + { + className: 'about-updates-release-notes', + onclick: this.props.viewUpdateReleaseNotes + }, + 'Release Notes' + ) ) break case UpdateManager.State.UpToDate: - updateStatus = $.div({className: 'about-updates-item app-up-to-date'}, - $.span({className: 'icon icon-check'}), - $.span({className: 'about-updates-label is-strong'}, 'Atom is up to date!') + updateStatus = $.div( + { className: 'about-updates-item app-up-to-date' }, + $.span({ className: 'icon icon-check' }), + $.span( + { className: 'about-updates-label is-strong' }, + 'Atom is up to date!' + ) ) break case UpdateManager.State.Unsupported: - updateStatus = $.div({className: 'about-updates-item app-unsupported'}, - $.span({className: 'about-updates-label is-strong'}, 'Your system does not support automatic updates'), - $.a({className: 'about-updates-instructions', onclick: this.props.viewUpdateInstructions}, 'How to update') + updateStatus = $.div( + { className: 'about-updates-item app-unsupported' }, + $.span( + { className: 'about-updates-label is-strong' }, + 'Your system does not support automatic updates' + ), + $.a( + { + className: 'about-updates-instructions', + onclick: this.props.viewUpdateInstructions + }, + 'How to update' + ) ) break case UpdateManager.State.Error: - updateStatus = $.div({className: 'about-updates-item app-update-error'}, - $.span({className: 'icon icon-x'}), - $.span({className: 'about-updates-label app-error-message is-strong'}, this.props.updateManager.getErrorMessage()) + updateStatus = $.div( + { className: 'about-updates-item app-update-error' }, + $.span({ className: 'icon icon-x' }), + $.span( + { className: 'about-updates-label app-error-message is-strong' }, + this.props.updateManager.getErrorMessage() + ) ) break } @@ -82,37 +132,47 @@ class UpdateView extends EtchComponent { } render () { - return $.div({className: 'about-updates group-start'}, - $.div({className: 'about-updates-box'}, - $.div({className: 'about-updates-status'}, this.renderUpdateStatus()), + return $.div( + { className: 'about-updates group-start' }, + $.div( + { className: 'about-updates-box' }, + $.div({ className: 'about-updates-status' }, this.renderUpdateStatus()), $.button( { className: 'btn about-update-action-button', disabled: this.shouldUpdateActionButtonBeDisabled(), onclick: this.executeUpdateAction.bind(this), style: { - display: this.props.updateManager.state === UpdateManager.State.Unsupported ? 'none' : 'block' + display: + this.props.updateManager.state === + UpdateManager.State.Unsupported + ? 'none' + : 'block' } }, - this.props.updateManager.state === 'update-available' ? 'Restart and install' : 'Check now' + this.props.updateManager.state === 'update-available' + ? 'Restart and install' + : 'Check now' ) ), $.div( { className: 'about-auto-updates', style: { - display: this.props.updateManager.state === UpdateManager.State.Unsupported ? 'none' : 'block' + display: + this.props.updateManager.state === UpdateManager.State.Unsupported + ? 'none' + : 'block' } }, - $.label({}, - $.input( - { - className: 'input-checkbox', - type: 'checkbox', - checked: this.props.updateManager.getAutoUpdatesEnabled(), - onchange: this.handleAutoUpdateCheckbox.bind(this) - } - ), + $.label( + {}, + $.input({ + className: 'input-checkbox', + type: 'checkbox', + checked: this.props.updateManager.getAutoUpdatesEnabled(), + onchange: this.handleAutoUpdateCheckbox.bind(this) + }), $.span({}, 'Automatically download updates') ) ) diff --git a/packages/about/lib/etch-component.js b/packages/about/lib/etch-component.js index f75edce94..71ea85c88 100644 --- a/packages/about/lib/etch-component.js +++ b/packages/about/lib/etch-component.js @@ -4,8 +4,7 @@ const etch = require('etch') Public: Abstract class for handling the initialization boilerplate of an Etch component. */ -module.exports = -class EtchComponent { +module.exports = class EtchComponent { constructor (props) { this.props = props diff --git a/packages/about/lib/main.js b/packages/about/lib/main.js index f0b855649..ec1420e7f 100644 --- a/packages/about/lib/main.js +++ b/packages/about/lib/main.js @@ -1,4 +1,4 @@ -const {CompositeDisposable} = require('atom') +const { CompositeDisposable } = require('atom') const semver = require('semver') const UpdateManager = require('./update-manager') const About = require('./about') @@ -16,20 +16,33 @@ module.exports = { this.createModel() let availableVersion = window.localStorage.getItem(AvailableUpdateVersion) - if (atom.getReleaseChannel() === 'dev' || (availableVersion && semver.lte(availableVersion, atom.getVersion()))) { + if ( + atom.getReleaseChannel() === 'dev' || + (availableVersion && semver.lte(availableVersion, atom.getVersion())) + ) { this.clearUpdateState() } - this.subscriptions.add(updateManager.onDidChange(() => { - if (updateManager.getState() === UpdateManager.State.UpdateAvailableToInstall) { - window.localStorage.setItem(AvailableUpdateVersion, updateManager.getAvailableVersion()) - this.showStatusBarIfNeeded() - } - })) + this.subscriptions.add( + updateManager.onDidChange(() => { + if ( + updateManager.getState() === + UpdateManager.State.UpdateAvailableToInstall + ) { + window.localStorage.setItem( + AvailableUpdateVersion, + updateManager.getAvailableVersion() + ) + this.showStatusBarIfNeeded() + } + }) + ) - this.subscriptions.add(atom.commands.add('atom-workspace', 'about:clear-update-state', () => { - this.clearUpdateState() - })) + this.subscriptions.add( + atom.commands.add('atom-workspace', 'about:clear-update-state', () => { + this.clearUpdateState() + }) + ) }, deactivate () { diff --git a/packages/about/lib/update-manager.js b/packages/about/lib/update-manager.js index 0db55f08d..bae72753d 100644 --- a/packages/about/lib/update-manager.js +++ b/packages/about/lib/update-manager.js @@ -1,4 +1,4 @@ -const {Emitter, CompositeDisposable} = require('atom') +const { Emitter, CompositeDisposable } = require('atom') const Unsupported = 'unsupported' const Idle = 'idle' @@ -27,7 +27,7 @@ let UpdateManager = class UpdateManager { atom.autoUpdater.onDidBeginDownloadingUpdate(() => { this.setState(DownloadingUpdate) }), - atom.autoUpdater.onDidCompleteDownloadingUpdate(({releaseVersion}) => { + atom.autoUpdater.onDidCompleteDownloadingUpdate(({ releaseVersion }) => { this.setAvailableVersion(releaseVersion) }), atom.autoUpdater.onUpdateNotAvailable(() => { @@ -36,7 +36,7 @@ let UpdateManager = class UpdateManager { atom.autoUpdater.onUpdateError(() => { this.setState(ErrorState) }), - atom.config.observe('core.automaticallyUpdate', (value) => { + atom.config.observe('core.automaticallyUpdate', value => { this.autoUpdatesEnabled = value this.emitDidChange() }) @@ -61,7 +61,9 @@ let UpdateManager = class UpdateManager { } getAutoUpdatesEnabled () { - return this.autoUpdatesEnabled && this.state !== UpdateManager.State.Unsupported + return ( + this.autoUpdatesEnabled && this.state !== UpdateManager.State.Unsupported + ) } setAutoUpdatesEnabled (enabled) { @@ -82,7 +84,9 @@ let UpdateManager = class UpdateManager { } resetState () { - this.state = atom.autoUpdater.platformSupportsUpdates() ? atom.autoUpdater.getState() : Unsupported + this.state = atom.autoUpdater.platformSupportsUpdates() + ? atom.autoUpdater.getState() + : Unsupported this.emitDidChange() } @@ -128,7 +132,8 @@ let UpdateManager = class UpdateManager { appVersion = `v${appVersion}` } - const releaseRepo = appVersion.indexOf('nightly') > -1 ? 'atom-nightly-releases' : 'atom' + const releaseRepo = + appVersion.indexOf('nightly') > -1 ? 'atom-nightly-releases' : 'atom' return `https://github.com/atom/${releaseRepo}/releases/tag/${appVersion}` } } diff --git a/packages/about/spec/about-spec.js b/packages/about/spec/about-spec.js index 60c4136d8..a991457ff 100644 --- a/packages/about/spec/about-spec.js +++ b/packages/about/spec/about-spec.js @@ -1,4 +1,11 @@ -const {it, fit, ffit, fffit, beforeEach, afterEach} = require('./helpers/async-spec-helpers') // eslint-disable-line no-unused-vars +const { + it, + fit, + ffit, + fffit, + beforeEach, + afterEach +} = require('./helpers/async-spec-helpers') // eslint-disable-line no-unused-vars describe('About', () => { let workspaceElement @@ -9,7 +16,7 @@ describe('About', () => { spyOn(window.localStorage, 'setItem').andCallFake((key, value) => { storage[key] = value }) - spyOn(window.localStorage, 'getItem').andCallFake((key) => { + spyOn(window.localStorage, 'getItem').andCallFake(key => { return storage[key] }) diff --git a/packages/about/spec/about-status-bar-spec.js b/packages/about/spec/about-status-bar-spec.js index a611af67a..99de30010 100644 --- a/packages/about/spec/about-status-bar-spec.js +++ b/packages/about/spec/about-status-bar-spec.js @@ -1,4 +1,12 @@ -const {it, fit, ffit, fffit, beforeEach, afterEach, conditionPromise} = require('./helpers/async-spec-helpers') // eslint-disable-line no-unused-vars +const { + it, + fit, + ffit, + fffit, + beforeEach, + afterEach, + conditionPromise +} = require('./helpers/async-spec-helpers') // eslint-disable-line no-unused-vars const MockUpdater = require('./mocks/updater') describe('the status bar', () => { @@ -11,7 +19,7 @@ describe('the status bar', () => { spyOn(window.localStorage, 'setItem').andCallFake((key, value) => { storage[key] = value }) - spyOn(window.localStorage, 'getItem').andCallFake((key) => { + spyOn(window.localStorage, 'getItem').andCallFake(key => { return storage[key] }) spyOn(atom, 'getVersion').andCallFake(() => { diff --git a/packages/about/spec/helpers/async-spec-helpers.js b/packages/about/spec/helpers/async-spec-helpers.js index 377024691..6d1d45963 100644 --- a/packages/about/spec/helpers/async-spec-helpers.js +++ b/packages/about/spec/helpers/async-spec-helpers.js @@ -1,7 +1,7 @@ /** @babel */ -const {now} = Date -const {setTimeout} = global +const { now } = Date +const { setTimeout } = global export function beforeEach (fn) { global.beforeEach(function () { @@ -21,7 +21,7 @@ export function afterEach (fn) { }) } -['it', 'fit', 'ffit', 'fffit'].forEach(function (name) { +;['it', 'fit', 'ffit', 'fffit'].forEach(function (name) { module.exports[name] = function (description, fn) { global[name](description, function () { const result = fn() diff --git a/packages/about/spec/mocks/updater.js b/packages/about/spec/mocks/updater.js index c96ea4ec1..6c5e1f19d 100644 --- a/packages/about/spec/mocks/updater.js +++ b/packages/about/spec/mocks/updater.js @@ -16,6 +16,8 @@ module.exports = { }, finishDownloadingUpdate (releaseVersion) { - atom.autoUpdater.emitter.emit('did-complete-downloading-update', {releaseVersion}) + atom.autoUpdater.emitter.emit('did-complete-downloading-update', { + releaseVersion + }) } } diff --git a/packages/about/spec/update-manager-spec.js b/packages/about/spec/update-manager-spec.js index 294e33b8b..cc395949e 100644 --- a/packages/about/spec/update-manager-spec.js +++ b/packages/about/spec/update-manager-spec.js @@ -9,14 +9,24 @@ describe('UpdateManager', () => { describe('::getReleaseNotesURLForVersion', () => { it('returns atom.io releases when dev version', () => { - expect(updateManager.getReleaseNotesURLForVersion('1.7.0-dev-e44b57d')).toContain('atom.io/releases') + expect( + updateManager.getReleaseNotesURLForVersion('1.7.0-dev-e44b57d') + ).toContain('atom.io/releases') }) it('returns the page for the release when not a dev version', () => { - expect(updateManager.getReleaseNotesURLForVersion('1.7.0')).toContain('atom/atom/releases/tag/v1.7.0') - expect(updateManager.getReleaseNotesURLForVersion('v1.7.0')).toContain('atom/atom/releases/tag/v1.7.0') - expect(updateManager.getReleaseNotesURLForVersion('1.7.0-beta10')).toContain('atom/atom/releases/tag/v1.7.0-beta10') - expect(updateManager.getReleaseNotesURLForVersion('1.7.0-nightly10')).toContain('atom/atom-nightly-releases/releases/tag/v1.7.0-nightly10') + expect(updateManager.getReleaseNotesURLForVersion('1.7.0')).toContain( + 'atom/atom/releases/tag/v1.7.0' + ) + expect(updateManager.getReleaseNotesURLForVersion('v1.7.0')).toContain( + 'atom/atom/releases/tag/v1.7.0' + ) + expect( + updateManager.getReleaseNotesURLForVersion('1.7.0-beta10') + ).toContain('atom/atom/releases/tag/v1.7.0-beta10') + expect( + updateManager.getReleaseNotesURLForVersion('1.7.0-nightly10') + ).toContain('atom/atom-nightly-releases/releases/tag/v1.7.0-nightly10') }) }) }) diff --git a/packages/about/spec/update-view-spec.js b/packages/about/spec/update-view-spec.js index 83ddf5ac1..fdb9a02b4 100644 --- a/packages/about/spec/update-view-spec.js +++ b/packages/about/spec/update-view-spec.js @@ -1,5 +1,12 @@ -const {shell} = require('electron') -const {it, fit, ffit, fffit, beforeEach, afterEach} = require('./helpers/async-spec-helpers') // eslint-disable-line no-unused-vars +const { shell } = require('electron') +const { + it, + fit, + ffit, + fffit, + beforeEach, + afterEach +} = require('./helpers/async-spec-helpers') // eslint-disable-line no-unused-vars const main = require('../lib/main') const AboutView = require('../lib/components/about-view') const UpdateView = require('../lib/components/update-view') @@ -17,7 +24,7 @@ describe('UpdateView', () => { spyOn(window.localStorage, 'setItem').andCallFake((key, value) => { storage[key] = value }) - spyOn(window.localStorage, 'getItem').andCallFake((key) => { + spyOn(window.localStorage, 'getItem').andCallFake(key => { return storage[key] }) @@ -45,13 +52,19 @@ describe('UpdateView', () => { }) it('hides the auto update UI and shows the update instructions link', async () => { - expect(aboutElement.querySelector('.about-update-action-button')).not.toBeVisible() - expect(aboutElement.querySelector('.about-auto-updates')).not.toBeVisible() + expect( + aboutElement.querySelector('.about-update-action-button') + ).not.toBeVisible() + expect( + aboutElement.querySelector('.about-auto-updates') + ).not.toBeVisible() }) it('opens the update instructions page when the instructions link is clicked', async () => { spyOn(shell, 'openExternal') - let link = aboutElement.querySelector('.app-unsupported .about-updates-instructions') + let link = aboutElement.querySelector( + '.app-unsupported .about-updates-instructions' + ) link.click() let args = shell.openExternal.mostRecentCall.args @@ -72,66 +85,116 @@ describe('UpdateView', () => { }) it('shows the correct panels when the app checks for updates and there is no update available', async () => { - expect(aboutElement.querySelector('.about-default-update-message')).toBeVisible() + expect( + aboutElement.querySelector('.about-default-update-message') + ).toBeVisible() MockUpdater.checkForUpdate() await scheduler.getNextUpdatePromise() expect(aboutElement.querySelector('.app-up-to-date')).not.toBeVisible() - expect(aboutElement.querySelector('.app-checking-for-updates')).toBeVisible() + expect( + aboutElement.querySelector('.app-checking-for-updates') + ).toBeVisible() MockUpdater.updateNotAvailable() await scheduler.getNextUpdatePromise() expect(aboutElement.querySelector('.app-up-to-date')).toBeVisible() - expect(aboutElement.querySelector('.app-checking-for-updates')).not.toBeVisible() + expect( + aboutElement.querySelector('.app-checking-for-updates') + ).not.toBeVisible() }) it('shows the correct panels when the app checks for updates and encounters an error', async () => { - expect(aboutElement.querySelector('.about-default-update-message')).toBeVisible() + expect( + aboutElement.querySelector('.about-default-update-message') + ).toBeVisible() MockUpdater.checkForUpdate() await scheduler.getNextUpdatePromise() expect(aboutElement.querySelector('.app-up-to-date')).not.toBeVisible() - expect(aboutElement.querySelector('.app-checking-for-updates')).toBeVisible() + expect( + aboutElement.querySelector('.app-checking-for-updates') + ).toBeVisible() spyOn(atom.autoUpdater, 'getErrorMessage').andReturn('an error message') MockUpdater.updateError() await scheduler.getNextUpdatePromise() expect(aboutElement.querySelector('.app-update-error')).toBeVisible() - expect(aboutElement.querySelector('.app-error-message').textContent).toBe('an error message') - expect(aboutElement.querySelector('.app-checking-for-updates')).not.toBeVisible() - expect(aboutElement.querySelector('.about-update-action-button').disabled).toBe(false) - expect(aboutElement.querySelector('.about-update-action-button').textContent).toBe('Check now') + expect( + aboutElement.querySelector('.app-error-message').textContent + ).toBe('an error message') + expect( + aboutElement.querySelector('.app-checking-for-updates') + ).not.toBeVisible() + expect( + aboutElement.querySelector('.about-update-action-button').disabled + ).toBe(false) + expect( + aboutElement.querySelector('.about-update-action-button').textContent + ).toBe('Check now') }) it('shows the correct panels and button states when the app checks for updates and an update is downloaded', async () => { - expect(aboutElement.querySelector('.about-default-update-message')).toBeVisible() - expect(aboutElement.querySelector('.about-update-action-button').disabled).toBe(false) - expect(aboutElement.querySelector('.about-update-action-button').textContent).toBe('Check now') + expect( + aboutElement.querySelector('.about-default-update-message') + ).toBeVisible() + expect( + aboutElement.querySelector('.about-update-action-button').disabled + ).toBe(false) + expect( + aboutElement.querySelector('.about-update-action-button').textContent + ).toBe('Check now') MockUpdater.checkForUpdate() await scheduler.getNextUpdatePromise() expect(aboutElement.querySelector('.app-up-to-date')).not.toBeVisible() - expect(aboutElement.querySelector('.app-checking-for-updates')).toBeVisible() - expect(aboutElement.querySelector('.about-update-action-button').disabled).toBe(true) - expect(aboutElement.querySelector('.about-update-action-button').textContent).toBe('Check now') + expect( + aboutElement.querySelector('.app-checking-for-updates') + ).toBeVisible() + expect( + aboutElement.querySelector('.about-update-action-button').disabled + ).toBe(true) + expect( + aboutElement.querySelector('.about-update-action-button').textContent + ).toBe('Check now') MockUpdater.downloadUpdate() await scheduler.getNextUpdatePromise() - expect(aboutElement.querySelector('.app-checking-for-updates')).not.toBeVisible() - expect(aboutElement.querySelector('.app-downloading-update')).toBeVisible() + expect( + aboutElement.querySelector('.app-checking-for-updates') + ).not.toBeVisible() + expect( + aboutElement.querySelector('.app-downloading-update') + ).toBeVisible() // TODO: at some point it would be nice to be able to cancel an update download, and then this would be a cancel button - expect(aboutElement.querySelector('.about-update-action-button').disabled).toBe(true) - expect(aboutElement.querySelector('.about-update-action-button').textContent).toBe('Check now') + expect( + aboutElement.querySelector('.about-update-action-button').disabled + ).toBe(true) + expect( + aboutElement.querySelector('.about-update-action-button').textContent + ).toBe('Check now') MockUpdater.finishDownloadingUpdate('42.0.0') await scheduler.getNextUpdatePromise() - expect(aboutElement.querySelector('.app-downloading-update')).not.toBeVisible() - expect(aboutElement.querySelector('.app-update-available-to-install')).toBeVisible() + expect( + aboutElement.querySelector('.app-downloading-update') + ).not.toBeVisible() + expect( + aboutElement.querySelector('.app-update-available-to-install') + ).toBeVisible() - expect(aboutElement.querySelector('.app-update-available-to-install .about-updates-version').textContent).toBe('42.0.0') - expect(aboutElement.querySelector('.about-update-action-button').disabled).toBe(false) - expect(aboutElement.querySelector('.about-update-action-button').textContent).toBe('Restart and install') + expect( + aboutElement.querySelector( + '.app-update-available-to-install .about-updates-version' + ).textContent + ).toBe('42.0.0') + expect( + aboutElement.querySelector('.about-update-action-button').disabled + ).toBe(false) + expect( + aboutElement.querySelector('.about-update-action-button').textContent + ).toBe('Restart and install') }) it('opens the release notes for the downloaded release when the release notes link are clicked', async () => { @@ -139,7 +202,9 @@ describe('UpdateView', () => { await scheduler.getNextUpdatePromise() spyOn(shell, 'openExternal') - let link = aboutElement.querySelector('.app-update-available-to-install .about-updates-release-notes') + let link = aboutElement.querySelector( + '.app-update-available-to-install .about-updates-release-notes' + ) link.click() let args = shell.openExternal.mostRecentCall.args @@ -168,10 +233,18 @@ describe('UpdateView', () => { updateManager.resetState() await scheduler.getNextUpdatePromise() - expect(aboutElement.querySelector('.app-checking-for-updates')).not.toBeVisible() - expect(aboutElement.querySelector('.app-downloading-update')).toBeVisible() - expect(aboutElement.querySelector('.about-update-action-button').disabled).toBe(true) - expect(aboutElement.querySelector('.about-update-action-button').textContent).toBe('Check now') + expect( + aboutElement.querySelector('.app-checking-for-updates') + ).not.toBeVisible() + expect( + aboutElement.querySelector('.app-downloading-update') + ).toBeVisible() + expect( + aboutElement.querySelector('.about-update-action-button').disabled + ).toBe(true) + expect( + aboutElement.querySelector('.about-update-action-button').textContent + ).toBe('Check now') }) describe('when core.automaticallyUpdate is toggled', () => { @@ -181,36 +254,66 @@ describe('UpdateView', () => { }) it('shows the auto update UI', async () => { - expect(aboutElement.querySelector('.about-auto-updates input').checked).toBe(true) - expect(aboutElement.querySelector('.about-default-update-message')).toBeVisible() - expect(aboutElement.querySelector('.about-default-update-message').textContent).toBe('Atom will check for updates automatically') + expect( + aboutElement.querySelector('.about-auto-updates input').checked + ).toBe(true) + expect( + aboutElement.querySelector('.about-default-update-message') + ).toBeVisible() + expect( + aboutElement.querySelector('.about-default-update-message') + .textContent + ).toBe('Atom will check for updates automatically') atom.config.set('core.automaticallyUpdate', false) await scheduler.getNextUpdatePromise() - expect(aboutElement.querySelector('.about-auto-updates input').checked).toBe(false) - expect(aboutElement.querySelector('.about-default-update-message')).toBeVisible() - expect(aboutElement.querySelector('.about-default-update-message').textContent).toBe('Automatic updates are disabled please check manually') + expect( + aboutElement.querySelector('.about-auto-updates input').checked + ).toBe(false) + expect( + aboutElement.querySelector('.about-default-update-message') + ).toBeVisible() + expect( + aboutElement.querySelector('.about-default-update-message') + .textContent + ).toBe('Automatic updates are disabled please check manually') }) it('updates config and the UI when the checkbox is used to toggle', async () => { - expect(aboutElement.querySelector('.about-auto-updates input').checked).toBe(true) + expect( + aboutElement.querySelector('.about-auto-updates input').checked + ).toBe(true) aboutElement.querySelector('.about-auto-updates input').click() await scheduler.getNextUpdatePromise() expect(atom.config.get('core.automaticallyUpdate')).toBe(false) - expect(aboutElement.querySelector('.about-auto-updates input').checked).toBe(false) - expect(aboutElement.querySelector('.about-default-update-message')).toBeVisible() - expect(aboutElement.querySelector('.about-default-update-message').textContent).toBe('Automatic updates are disabled please check manually') + expect( + aboutElement.querySelector('.about-auto-updates input').checked + ).toBe(false) + expect( + aboutElement.querySelector('.about-default-update-message') + ).toBeVisible() + expect( + aboutElement.querySelector('.about-default-update-message') + .textContent + ).toBe('Automatic updates are disabled please check manually') aboutElement.querySelector('.about-auto-updates input').click() await scheduler.getNextUpdatePromise() expect(atom.config.get('core.automaticallyUpdate')).toBe(true) - expect(aboutElement.querySelector('.about-auto-updates input').checked).toBe(true) - expect(aboutElement.querySelector('.about-default-update-message')).toBeVisible() - expect(aboutElement.querySelector('.about-default-update-message').textContent).toBe('Atom will check for updates automatically') + expect( + aboutElement.querySelector('.about-auto-updates input').checked + ).toBe(true) + expect( + aboutElement.querySelector('.about-default-update-message') + ).toBeVisible() + expect( + aboutElement.querySelector('.about-default-update-message') + .textContent + ).toBe('Atom will check for updates automatically') }) describe('checking for updates', function () { @@ -271,10 +374,20 @@ describe('UpdateView', () => { updateManager = main.model.state.updateManager scheduler = AboutView.getScheduler() - expect(aboutElement.querySelector('.app-update-available-to-install')).toBeVisible() - expect(aboutElement.querySelector('.app-update-available-to-install .about-updates-version').textContent).toBe('42.0.0') - expect(aboutElement.querySelector('.about-update-action-button').disabled).toBe(false) - expect(aboutElement.querySelector('.about-update-action-button').textContent).toBe('Restart and install') + expect( + aboutElement.querySelector('.app-update-available-to-install') + ).toBeVisible() + expect( + aboutElement.querySelector( + '.app-update-available-to-install .about-updates-version' + ).textContent + ).toBe('42.0.0') + expect( + aboutElement.querySelector('.about-update-action-button').disabled + ).toBe(false) + expect( + aboutElement.querySelector('.about-update-action-button').textContent + ).toBe('Restart and install') }) }) }) diff --git a/packages/dalek/lib/dalek.js b/packages/dalek/lib/dalek.js index 8d322cc03..3f1944a0c 100644 --- a/packages/dalek/lib/dalek.js +++ b/packages/dalek/lib/dalek.js @@ -13,7 +13,9 @@ module.exports = { const names = atom.packages.getAvailablePackageNames() for (let name of names) { if (atom.packages.isBundledPackage(name)) { - const isDuplicatedPackage = await this.isInstalledAsCommunityPackage(name) + const isDuplicatedPackage = await this.isInstalledAsCommunityPackage( + name + ) if (isDuplicatedPackage) { duplicatePackages.push(name) } diff --git a/packages/dalek/test/dalek.test.js b/packages/dalek/test/dalek.test.js index 8b84dd29d..ff1ba394c 100644 --- a/packages/dalek/test/dalek.test.js +++ b/packages/dalek/test/dalek.test.js @@ -17,20 +17,49 @@ describe('dalek', function () { beforeEach(function () { availablePackages = { - 'an-unduplicated-installed-package': path.join('Users', 'username', '.atom', 'packages', 'an-unduplicated-installed-package'), - 'duplicated-package': path.join('Users', 'username', '.atom', 'packages', 'duplicated-package'), - 'unduplicated-package': path.join(`${atom.getLoadSettings().resourcePath}`, 'node_modules', 'unduplicated-package') + 'an-unduplicated-installed-package': path.join( + 'Users', + 'username', + '.atom', + 'packages', + 'an-unduplicated-installed-package' + ), + 'duplicated-package': path.join( + 'Users', + 'username', + '.atom', + 'packages', + 'duplicated-package' + ), + 'unduplicated-package': path.join( + `${atom.getLoadSettings().resourcePath}`, + 'node_modules', + 'unduplicated-package' + ) } atom.devMode = false bundledPackages = ['duplicated-package', 'unduplicated-package'] packageDirPaths = [path.join('Users', 'username', '.atom', 'packages')] sandbox = sinon.sandbox.create() - sandbox.stub(dalek, 'realpath').callsFake((filePath) => Promise.resolve(realPaths[filePath] || filePath)) - sandbox.stub(atom.packages, 'isBundledPackage').callsFake((packageName) => { return bundledPackages.includes(packageName) }) - sandbox.stub(atom.packages, 'getAvailablePackageNames').callsFake(() => Object.keys(availablePackages)) - sandbox.stub(atom.packages, 'getPackageDirPaths').callsFake(() => { return packageDirPaths }) - sandbox.stub(fs, 'existsSync').callsFake((candidate) => { return Object.values(availablePackages).includes(candidate) && !candidate.includes(atom.getLoadSettings().resourcePath) }) + sandbox + .stub(dalek, 'realpath') + .callsFake(filePath => Promise.resolve(realPaths[filePath] || filePath)) + sandbox.stub(atom.packages, 'isBundledPackage').callsFake(packageName => { + return bundledPackages.includes(packageName) + }) + sandbox + .stub(atom.packages, 'getAvailablePackageNames') + .callsFake(() => Object.keys(availablePackages)) + sandbox.stub(atom.packages, 'getPackageDirPaths').callsFake(() => { + return packageDirPaths + }) + sandbox.stub(fs, 'existsSync').callsFake(candidate => { + return ( + Object.values(availablePackages).includes(candidate) && + !candidate.includes(atom.getLoadSettings().resourcePath) + ) + }) }) afterEach(function () { @@ -54,7 +83,13 @@ describe('dalek', function () { describe('when a package is symlinked into the package directory', async function () { beforeEach(function () { const realPath = path.join('Users', 'username', 'duplicated-package') - const packagePath = path.join('Users', 'username', '.atom', 'packages', 'duplicated-package') + const packagePath = path.join( + 'Users', + 'username', + '.atom', + 'packages', + 'duplicated-package' + ) realPaths[packagePath] = realPath }) diff --git a/packages/dalek/test/runner.js b/packages/dalek/test/runner.js index 5688fc9c0..7b155fa67 100644 --- a/packages/dalek/test/runner.js +++ b/packages/dalek/test/runner.js @@ -1,2 +1,2 @@ const createRunner = require('atom-mocha-test-runner').createRunner -module.exports = createRunner({testSuffixes: ['test.js']}) +module.exports = createRunner({ testSuffixes: ['test.js'] }) diff --git a/packages/deprecation-cop/lib/deprecation-cop-view.js b/packages/deprecation-cop/lib/deprecation-cop-view.js index 01d8ad736..0531a2631 100644 --- a/packages/deprecation-cop/lib/deprecation-cop-view.js +++ b/packages/deprecation-cop/lib/deprecation-cop-view.js @@ -2,7 +2,7 @@ /** @jsx etch.dom */ import _ from 'underscore-plus' -import {CompositeDisposable} from 'atom' +import { CompositeDisposable } from 'atom' import etch from 'etch' import fs from 'fs-plus' import Grim from 'grim' @@ -11,23 +11,45 @@ import path from 'path' import shell from 'shell' export default class DeprecationCopView { - constructor ({uri}) { + constructor ({ uri }) { this.uri = uri - this.subscriptions = new CompositeDisposable - this.subscriptions.add(Grim.on('updated', () => { etch.update(this) })) + this.subscriptions = new CompositeDisposable() + this.subscriptions.add( + Grim.on('updated', () => { + etch.update(this) + }) + ) // TODO: Remove conditional when the new StyleManager deprecation APIs reach stable. if (atom.styles.onDidUpdateDeprecations) { - this.subscriptions.add(atom.styles.onDidUpdateDeprecations(() => { etch.update(this) })) + this.subscriptions.add( + atom.styles.onDidUpdateDeprecations(() => { + etch.update(this) + }) + ) } etch.initialize(this) - this.subscriptions.add(atom.commands.add(this.element, { - 'core:move-up': () => { this.scrollUp() }, - 'core:move-down': () => { this.scrollDown() }, - 'core:page-up': () => { this.pageUp() }, - 'core:page-down': () => { this.pageDown() }, - 'core:move-to-top': () => { this.scrollToTop() }, - 'core:move-to-bottom': () => { this.scrollToBottom() } - })) + this.subscriptions.add( + atom.commands.add(this.element, { + 'core:move-up': () => { + this.scrollUp() + }, + 'core:move-down': () => { + this.scrollDown() + }, + 'core:page-up': () => { + this.pageUp() + }, + 'core:page-down': () => { + this.pageDown() + }, + 'core:move-to-top': () => { + this.scrollToTop() + }, + 'core:move-to-bottom': () => { + this.scrollToBottom() + } + }) + ) } serialize () { @@ -49,25 +71,35 @@ export default class DeprecationCopView { render () { return ( -
+
+ }} + > + Check for Updates +
-
Deprecated calls
+
+ Deprecated calls +
    {this.renderDeprecatedCalls()}
-
Deprecated selectors
+
+ Deprecated selectors +
    {this.renderDeprecatedSelectors()}
@@ -82,37 +114,57 @@ export default class DeprecationCopView { if (packageNames.length === 0) { return
  • No deprecated calls
  • } else { - return packageNames.sort().map((packageName) => ( + return packageNames.sort().map(packageName => (
  • -
    event.target.parentElement.classList.toggle('collapsed')}> +
    + event.target.parentElement.classList.toggle('collapsed') + } + > {packageName || 'atom core'} - {` (${_.pluralize(deprecationsByPackageName[packageName].length, 'deprecation')})`} + {` (${_.pluralize( + deprecationsByPackageName[packageName].length, + 'deprecation' + )})`}
      {this.renderPackageActionsIfNeeded(packageName)} - {deprecationsByPackageName[packageName].map(({deprecation, stack}) => ( -
    • - -
      - {this.renderIssueURLIfNeeded(packageName, deprecation, this.buildIssueURL(packageName, deprecation, stack))} -
      - {stack.map(({functionName, location}) => ( -
      - {functionName} - - - { - event.preventDefault() - this.openLocation(location) - }}>{location} + {deprecationsByPackageName[packageName].map( + ({ deprecation, stack }) => ( +
    • + +
      + {this.renderIssueURLIfNeeded( + packageName, + deprecation, + this.buildIssueURL(packageName, deprecation, stack) + )} +
      + {stack.map(({ functionName, location }) => ( + + ))}
      - ))} -
      -
    • - ))} + + ) + )}
  • )) @@ -123,41 +175,61 @@ export default class DeprecationCopView { const deprecationsByPackageName = this.getDeprecatedSelectorsByPackageName() const packageNames = Object.keys(deprecationsByPackageName) if (packageNames.length === 0) { - return ( -
  • No deprecated selectors
  • - ) + return
  • No deprecated selectors
  • } else { - return packageNames.map((packageName) => ( + return packageNames.map(packageName => (
  • -
    event.target.parentElement.classList.toggle('collapsed')}> +
    + event.target.parentElement.classList.toggle('collapsed') + } + > {packageName}
      {this.renderPackageActionsIfNeeded(packageName)} - {deprecationsByPackageName[packageName].map(({packagePath, sourcePath, deprecation}) => { - const relativeSourcePath = path.relative(packagePath, sourcePath) - const issueTitle = `Deprecated selector in \`${relativeSourcePath}\`` - const issueBody = `In \`${relativeSourcePath}\`: \n\n${deprecation.message}` - return ( -
    • - { - event.preventDefault() - this.openLocation(sourcePath) - }}>{relativeSourcePath} -
        -
      • - -
        - {this.renderSelectorIssueURLIfNeeded(packageName, issueTitle, issueBody)} -
      • -
      -
    • - ) - })} + {deprecationsByPackageName[packageName].map( + ({ packagePath, sourcePath, deprecation }) => { + const relativeSourcePath = path.relative( + packagePath, + sourcePath + ) + const issueTitle = `Deprecated selector in \`${relativeSourcePath}\`` + const issueBody = `In \`${relativeSourcePath}\`: \n\n${ + deprecation.message + }` + return ( +
    • + { + event.preventDefault() + this.openLocation(sourcePath) + }} + > + {relativeSourcePath} + +
        +
      • + +
        + {this.renderSelectorIssueURLIfNeeded( + packageName, + issueTitle, + issueBody + )} +
      • +
      +
    • + ) + } + )}
  • )) @@ -171,17 +243,23 @@ export default class DeprecationCopView {
    + }} + > + Check for Update + + }} + > + Disable Package +
    ) @@ -191,13 +269,18 @@ export default class DeprecationCopView { } encodeURI (str) { - return encodeURI(str).replace(/#/g, '%23').replace(/;/g, '%3B').replace(/%20/g, '+') + return encodeURI(str) + .replace(/#/g, '%23') + .replace(/;/g, '%3B') + .replace(/%20/g, '+') } renderSelectorIssueURLIfNeeded (packageName, issueTitle, issueBody) { const repoURL = this.getRepoURL(packageName) if (repoURL) { - const issueURL = `${repoURL}/issues/new?title=${this.encodeURI(issueTitle)}&body=${this.encodeURI(issueBody)}` + const issueURL = `${repoURL}/issues/new?title=${this.encodeURI( + issueTitle + )}&body=${this.encodeURI(issueBody)}` return (
    + }} + > + Report Issue +
    ) } else { @@ -227,10 +313,13 @@ export default class DeprecationCopView { data-issue-title={issueTitle} data-repo-url={repoURL} data-issue-url={issueURL} - onclick={(event) => { + onclick={event => { event.preventDefault() this.openIssueURL(repoURL, issueURL, issueTitle) - }}>Report Issue + }} + > + Report Issue +
    ) } else { @@ -242,9 +331,13 @@ export default class DeprecationCopView { const repoURL = this.getRepoURL(packageName) if (repoURL) { const title = `${deprecation.getOriginName()} is deprecated.` - const stacktrace = stack.map(({functionName, location}) => `${functionName} (${location})`).join("\n") + const stacktrace = stack + .map(({ functionName, location }) => `${functionName} (${location})`) + .join('\n') const body = `${deprecation.getMessage()}\n\`\`\`\n${stacktrace}\n\`\`\`` - return `${repoURL}/issues/new?title=${encodeURI(title)}&body=${encodeURI(body)}` + return `${repoURL}/issues/new?title=${encodeURI(title)}&body=${encodeURI( + body + )}` } else { return null } @@ -266,13 +359,16 @@ export default class DeprecationCopView { const url = 'https://api.github.com/search/issues' const repo = repoURL.replace(/http(s)?:\/\/(\d+\.)?github.com\//gi, '') const query = `${issueTitle} repo:${repo}` - const response = await window.fetch(`${url}?q=${encodeURI(query)}&sort=created`, { - method: 'GET', - headers: { - 'Accept': 'application/vnd.github.v3+json', - 'Content-Type': 'application/json' + const response = await window.fetch( + `${url}?q=${encodeURI(query)}&sort=created`, + { + method: 'GET', + headers: { + Accept: 'application/vnd.github.v3+json', + 'Content-Type': 'application/json' + } } - }) + ) if (response.ok) { const data = await response.json() @@ -284,21 +380,25 @@ export default class DeprecationCopView { } } - return (issues.open || issues.closed) + return issues.open || issues.closed } } } async shortenURL (url) { let encodedUrl = encodeURIComponent(url).substr(0, 5000) // is.gd has 5000 char limit - let incompletePercentEncoding = encodedUrl.indexOf('%', encodedUrl.length - 2) - if (incompletePercentEncoding >= 0) { // Handle an incomplete % encoding cut-off + let incompletePercentEncoding = encodedUrl.indexOf( + '%', + encodedUrl.length - 2 + ) + if (incompletePercentEncoding >= 0) { + // Handle an incomplete % encoding cut-off encodedUrl = encodedUrl.substr(0, incompletePercentEncoding) } let result = await fetch('https://is.gd/create.php?format=simple', { method: 'POST', - headers: {'Content-Type': 'application/x-www-form-urlencoded'}, + headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: `url=${encodedUrl}` }) @@ -307,8 +407,14 @@ export default class DeprecationCopView { getRepoURL (packageName) { const loadedPackage = atom.packages.getLoadedPackage(packageName) - if (loadedPackage && loadedPackage.metadata && loadedPackage.metadata.repository) { - const url = loadedPackage.metadata.repository.url || loadedPackage.metadata.repository + if ( + loadedPackage && + loadedPackage.metadata && + loadedPackage.metadata.repository + ) { + const url = + loadedPackage.metadata.repository.url || + loadedPackage.metadata.repository return url.replace(/\.git$/, '') } else { return null @@ -330,8 +436,9 @@ export default class DeprecationCopView { packageName = (this.getPackageName(stack) || '').toLowerCase() } - deprecatedCallsByPackageName[packageName] = deprecatedCallsByPackageName[packageName] || [] - deprecatedCallsByPackageName[packageName].push({deprecation, stack}) + deprecatedCallsByPackageName[packageName] = + deprecatedCallsByPackageName[packageName] || [] + deprecatedCallsByPackageName[packageName].push({ deprecation, stack }) } } return deprecatedCallsByPackageName @@ -352,11 +459,18 @@ export default class DeprecationCopView { packagePath = '' } else { packageName = components[packagesComponentIndex + 1] - packagePath = components.slice(0, packagesComponentIndex + 1).join(path.sep) + packagePath = components + .slice(0, packagesComponentIndex + 1) + .join(path.sep) } - deprecatedSelectorsByPackageName[packageName] = deprecatedSelectorsByPackageName[packageName] || [] - deprecatedSelectorsByPackageName[packageName].push({packagePath, sourcePath, deprecation}) + deprecatedSelectorsByPackageName[packageName] = + deprecatedSelectorsByPackageName[packageName] || [] + deprecatedSelectorsByPackageName[packageName].push({ + packagePath, + sourcePath, + deprecation + }) } } @@ -366,13 +480,16 @@ export default class DeprecationCopView { getPackageName (stack) { const packagePaths = this.getPackagePathsByPackageName() for (const [packageName, packagePath] of packagePaths) { - if (packagePath.includes('.atom/dev/packages') || packagePath.includes('.atom/packages')) { + if ( + packagePath.includes('.atom/dev/packages') || + packagePath.includes('.atom/packages') + ) { packagePaths.set(packageName, fs.absolute(packagePath)) } } for (let i = 1; i < stack.length; i++) { - const {fileName} = stack[i] + const { fileName } = stack[i] // Empty when it was run from the dev console if (!fileName) { @@ -426,7 +543,7 @@ export default class DeprecationCopView { if (process.platform === 'win32') { pathToOpen = pathToOpen.replace(/^\//, '') } - atom.open({pathsToOpen: [pathToOpen]}) + atom.open({ pathsToOpen: [pathToOpen] }) } getURI () { diff --git a/packages/deprecation-cop/lib/main.js b/packages/deprecation-cop/lib/main.js index 12da158b5..3dd94da6d 100644 --- a/packages/deprecation-cop/lib/main.js +++ b/packages/deprecation-cop/lib/main.js @@ -1,4 +1,4 @@ -const {Disposable, CompositeDisposable} = require('atom') +const { Disposable, CompositeDisposable } = require('atom') const DeprecationCopView = require('./deprecation-cop-view') const DeprecationCopStatusBarView = require('./deprecation-cop-status-bar-view') const ViewURI = 'atom://deprecation-cop' @@ -6,14 +6,18 @@ const ViewURI = 'atom://deprecation-cop' class DeprecationCopPackage { activate () { this.disposables = new CompositeDisposable() - this.disposables.add(atom.workspace.addOpener((uri) => { - if (uri === ViewURI) { - return this.deserializeDeprecationCopView({uri}) - } - })) - this.disposables.add(atom.commands.add('atom-workspace', 'deprecation-cop:view', () => { - atom.workspace.open(ViewURI) - })) + this.disposables.add( + atom.workspace.addOpener(uri => { + if (uri === ViewURI) { + return this.deserializeDeprecationCopView({ uri }) + } + }) + ) + this.disposables.add( + atom.commands.add('atom-workspace', 'deprecation-cop:view', () => { + atom.workspace.open(ViewURI) + }) + ) } deactivate () { @@ -30,9 +34,20 @@ class DeprecationCopPackage { consumeStatusBar (statusBar) { const statusBarView = new DeprecationCopStatusBarView() - const statusBarTile = statusBar.addRightTile({item: statusBarView, priority: 150}) - this.disposables.add(new Disposable(() => { statusBarView.destroy() })) - this.disposables.add(new Disposable(() => { statusBarTile.destroy() })) + const statusBarTile = statusBar.addRightTile({ + item: statusBarView, + priority: 150 + }) + this.disposables.add( + new Disposable(() => { + statusBarView.destroy() + }) + ) + this.disposables.add( + new Disposable(() => { + statusBarTile.destroy() + }) + ) } } diff --git a/packages/dev-live-reload/lib/base-theme-watcher.js b/packages/dev-live-reload/lib/base-theme-watcher.js index 8d8658a8c..e18a974f6 100644 --- a/packages/dev-live-reload/lib/base-theme-watcher.js +++ b/packages/dev-live-reload/lib/base-theme-watcher.js @@ -2,16 +2,19 @@ const fs = require('fs-plus') const path = require('path') const Watcher = require('./watcher') -module.exports = -class BaseThemeWatcher extends Watcher { +module.exports = class BaseThemeWatcher extends Watcher { constructor () { super() - this.stylesheetsPath = path.dirname(atom.themes.resolveStylesheet('../static/atom.less')) + this.stylesheetsPath = path.dirname( + atom.themes.resolveStylesheet('../static/atom.less') + ) this.watch() } watch () { - const filePaths = fs.readdirSync(this.stylesheetsPath).filter(filePath => path.extname(filePath).includes('less')) + const filePaths = fs + .readdirSync(this.stylesheetsPath) + .filter(filePath => path.extname(filePath).includes('less')) for (const filePath of filePaths) { this.watchFile(path.join(this.stylesheetsPath, filePath)) diff --git a/packages/dev-live-reload/lib/main.js b/packages/dev-live-reload/lib/main.js index 8e80de68f..a486231cf 100644 --- a/packages/dev-live-reload/lib/main.js +++ b/packages/dev-live-reload/lib/main.js @@ -5,7 +5,9 @@ module.exports = { if (atom.packages.hasActivatedInitialPackages()) { this.startWatching() } else { - this.activatedDisposable = atom.packages.onDidActivateInitialPackages(() => this.startWatching()) + this.activatedDisposable = atom.packages.onDidActivateInitialPackages( + () => this.startWatching() + ) } }, @@ -17,8 +19,12 @@ module.exports = { startWatching () { const UIWatcher = require('./ui-watcher') - this.uiWatcher = new UIWatcher({themeManager: atom.themes}) - this.commandDisposable = atom.commands.add('atom-workspace', 'dev-live-reload:reload-all', () => this.uiWatcher.reloadAll()) + this.uiWatcher = new UIWatcher({ themeManager: atom.themes }) + this.commandDisposable = atom.commands.add( + 'atom-workspace', + 'dev-live-reload:reload-all', + () => this.uiWatcher.reloadAll() + ) if (this.activatedDisposable) this.activatedDisposable.dispose() } } diff --git a/packages/dev-live-reload/lib/package-watcher.js b/packages/dev-live-reload/lib/package-watcher.js index 044b59719..a5be2337c 100644 --- a/packages/dev-live-reload/lib/package-watcher.js +++ b/packages/dev-live-reload/lib/package-watcher.js @@ -2,8 +2,7 @@ const fs = require('fs-plus') const Watcher = require('./watcher') -module.exports = -class PackageWatcher extends Watcher { +module.exports = class PackageWatcher extends Watcher { static supportsPackage (pack, type) { if (pack.getType() === type && pack.getStylesheetPaths().length) return true return false @@ -24,7 +23,8 @@ class PackageWatcher extends Watcher { const stylesheetsPath = this.pack.getStylesheetsPath() - if (fs.isDirectorySync(stylesheetsPath)) this.watchDirectory(stylesheetsPath) + if (fs.isDirectorySync(stylesheetsPath)) + this.watchDirectory(stylesheetsPath) const stylesheetPaths = new Set(this.pack.getStylesheetPaths()) const onFile = stylesheetPath => stylesheetPaths.add(stylesheetPath) diff --git a/packages/dev-live-reload/lib/ui-watcher.js b/packages/dev-live-reload/lib/ui-watcher.js index 458d31a78..9aa3eefde 100644 --- a/packages/dev-live-reload/lib/ui-watcher.js +++ b/packages/dev-live-reload/lib/ui-watcher.js @@ -1,10 +1,9 @@ -const {CompositeDisposable} = require('atom') +const { CompositeDisposable } = require('atom') const BaseThemeWatcher = require('./base-theme-watcher') const PackageWatcher = require('./package-watcher') -module.exports = -class UIWatcher { +module.exports = class UIWatcher { constructor () { this.subscriptions = new CompositeDisposable() this.reloadAll = this.reloadAll.bind(this) @@ -16,39 +15,61 @@ class UIWatcher { watchPackages () { this.watchedThemes = new Map() this.watchedPackages = new Map() - for (const theme of atom.themes.getActiveThemes()) { this.watchTheme(theme) } - for (const pack of atom.packages.getActivePackages()) { this.watchPackage(pack) } + for (const theme of atom.themes.getActiveThemes()) { + this.watchTheme(theme) + } + for (const pack of atom.packages.getActivePackages()) { + this.watchPackage(pack) + } this.watchForPackageChanges() } watchForPackageChanges () { - this.subscriptions.add(atom.themes.onDidChangeActiveThemes(() => { - // We need to destroy all theme watchers as all theme packages are destroyed - // when a theme changes. - for (const theme of this.watchedThemes.values()) { theme.destroy() } + this.subscriptions.add( + atom.themes.onDidChangeActiveThemes(() => { + // We need to destroy all theme watchers as all theme packages are destroyed + // when a theme changes. + for (const theme of this.watchedThemes.values()) { + theme.destroy() + } - this.watchedThemes.clear() + this.watchedThemes.clear() - // Rewatch everything! - for (const theme of atom.themes.getActiveThemes()) { this.watchTheme(theme) } - })) + // Rewatch everything! + for (const theme of atom.themes.getActiveThemes()) { + this.watchTheme(theme) + } + }) + ) - this.subscriptions.add(atom.packages.onDidActivatePackage(pack => this.watchPackage(pack))) + this.subscriptions.add( + atom.packages.onDidActivatePackage(pack => this.watchPackage(pack)) + ) - this.subscriptions.add(atom.packages.onDidDeactivatePackage(pack => { - // This only handles packages - onDidChangeActiveThemes handles themes - const watcher = this.watchedPackages.get(pack.name) - if (watcher) watcher.destroy() - this.watchedPackages.delete(pack.name) - })) + this.subscriptions.add( + atom.packages.onDidDeactivatePackage(pack => { + // This only handles packages - onDidChangeActiveThemes handles themes + const watcher = this.watchedPackages.get(pack.name) + if (watcher) watcher.destroy() + this.watchedPackages.delete(pack.name) + }) + ) } watchTheme (theme) { - if (PackageWatcher.supportsPackage(theme, 'theme')) this.watchedThemes.set(theme.name, this.createWatcher(new PackageWatcher(theme))) + if (PackageWatcher.supportsPackage(theme, 'theme')) + this.watchedThemes.set( + theme.name, + this.createWatcher(new PackageWatcher(theme)) + ) } watchPackage (pack) { - if (PackageWatcher.supportsPackage(pack, 'atom')) this.watchedPackages.set(pack.name, this.createWatcher(new PackageWatcher(pack))) + if (PackageWatcher.supportsPackage(pack, 'atom')) + this.watchedPackages.set( + pack.name, + this.createWatcher(new PackageWatcher(pack)) + ) } createWatcher (watcher) { @@ -56,7 +77,9 @@ class UIWatcher { console.log('Global changed, reloading all styles') this.reloadAll() }) - watcher.onDidDestroy(() => this.watchers.splice(this.watchers.indexOf(watcher), 1)) + watcher.onDidDestroy(() => + this.watchers.splice(this.watchers.indexOf(watcher), 1) + ) this.watchers.push(watcher) return watcher } @@ -68,14 +91,19 @@ class UIWatcher { } for (const theme of atom.themes.getActiveThemes()) { - if (PackageWatcher.supportsPackage(theme, 'theme')) theme.reloadStylesheets() + if (PackageWatcher.supportsPackage(theme, 'theme')) + theme.reloadStylesheets() } } destroy () { this.subscriptions.dispose() this.baseTheme.destroy() - for (const pack of this.watchedPackages.values()) { pack.destroy() } - for (const theme of this.watchedThemes.values()) { theme.destroy() } + for (const pack of this.watchedPackages.values()) { + pack.destroy() + } + for (const theme of this.watchedThemes.values()) { + theme.destroy() + } } } diff --git a/packages/dev-live-reload/lib/watcher.js b/packages/dev-live-reload/lib/watcher.js index 2ecde1eef..b1b3631a5 100644 --- a/packages/dev-live-reload/lib/watcher.js +++ b/packages/dev-live-reload/lib/watcher.js @@ -1,8 +1,7 @@ -const {CompositeDisposable, File, Directory, Emitter} = require('atom') +const { CompositeDisposable, File, Directory, Emitter } = require('atom') const path = require('path') -module.exports = -class Watcher { +module.exports = class Watcher { constructor () { this.destroy = this.destroy.bind(this) this.emitter = new Emitter() @@ -66,7 +65,10 @@ class Watcher { } isInAsarArchive (pathToCheck) { - const {resourcePath} = atom.getLoadSettings() - return pathToCheck.startsWith(`${resourcePath}${path.sep}`) && path.extname(resourcePath) === '.asar' + const { resourcePath } = atom.getLoadSettings() + return ( + pathToCheck.startsWith(`${resourcePath}${path.sep}`) && + path.extname(resourcePath) === '.asar' + ) } } diff --git a/packages/dev-live-reload/spec/async-spec-helpers.js b/packages/dev-live-reload/spec/async-spec-helpers.js index 73002c049..5a233973e 100644 --- a/packages/dev-live-reload/spec/async-spec-helpers.js +++ b/packages/dev-live-reload/spec/async-spec-helpers.js @@ -18,7 +18,7 @@ export function afterEach (fn) { }) } -['it', 'fit', 'ffit', 'fffit'].forEach(function (name) { +;['it', 'fit', 'ffit', 'fffit'].forEach(function (name) { module.exports[name] = function (description, fn) { if (fn === undefined) { global[name](description) @@ -34,7 +34,10 @@ export function afterEach (fn) { } }) -export async function conditionPromise (condition, description = 'anonymous condition') { +export async function conditionPromise ( + condition, + description = 'anonymous condition' +) { const startTime = Date.now() while (true) { diff --git a/packages/dev-live-reload/spec/dev-live-reload-spec.js b/packages/dev-live-reload/spec/dev-live-reload-spec.js index dec828b65..99b7fe261 100644 --- a/packages/dev-live-reload/spec/dev-live-reload-spec.js +++ b/packages/dev-live-reload/spec/dev-live-reload-spec.js @@ -1,4 +1,4 @@ -const {it, fit, ffit, afterEach, beforeEach} = require('./async-spec-helpers') // eslint-disable-line no-unused-vars +const { it, fit, ffit, afterEach, beforeEach } = require('./async-spec-helpers') // eslint-disable-line no-unused-vars describe('Dev Live Reload', () => { describe('package activation', () => { @@ -85,7 +85,9 @@ describe('Dev Live Reload', () => { it('stops watching all files', async () => { spyOn(atom.packages, 'hasActivatedInitialPackages').andReturn(true) - const {mainModule} = await atom.packages.activatePackage('dev-live-reload') + const { mainModule } = await atom.packages.activatePackage( + 'dev-live-reload' + ) expect(mainModule.uiWatcher).not.toBeNull() spyOn(mainModule.uiWatcher, 'destroy') @@ -95,7 +97,9 @@ describe('Dev Live Reload', () => { }) it('unsubscribes from the onDidActivateInitialPackages subscription if it is disabled before all initial packages are activated', async () => { - const {mainModule} = await atom.packages.activatePackage('dev-live-reload') + const { mainModule } = await atom.packages.activatePackage( + 'dev-live-reload' + ) expect(mainModule.activatedDisposable.disposed).toBe(false) await atom.packages.deactivatePackage('dev-live-reload') @@ -109,16 +113,18 @@ describe('Dev Live Reload', () => { it('removes its commands', async () => { spyOn(atom.packages, 'hasActivatedInitialPackages').andReturn(true) await atom.packages.activatePackage('dev-live-reload') - expect(atom.commands - .findCommands({target: atom.views.getView(atom.workspace)}) - .filter(command => command.name.startsWith('dev-live-reload')) - .length).toBeGreaterThan(0) + expect( + atom.commands + .findCommands({ target: atom.views.getView(atom.workspace) }) + .filter(command => command.name.startsWith('dev-live-reload')).length + ).toBeGreaterThan(0) await atom.packages.deactivatePackage('dev-live-reload') - expect(atom.commands - .findCommands({target: atom.views.getView(atom.workspace)}) - .filter(command => command.name.startsWith('dev-live-reload')) - .length).toBe(0) + expect( + atom.commands + .findCommands({ target: atom.views.getView(atom.workspace) }) + .filter(command => command.name.startsWith('dev-live-reload')).length + ).toBe(0) }) }) }) diff --git a/packages/dev-live-reload/spec/ui-watcher-spec.js b/packages/dev-live-reload/spec/ui-watcher-spec.js index c52ce35ab..0730619d8 100644 --- a/packages/dev-live-reload/spec/ui-watcher-spec.js +++ b/packages/dev-live-reload/spec/ui-watcher-spec.js @@ -2,25 +2,38 @@ const path = require('path') const UIWatcher = require('../lib/ui-watcher') -const {it, fit, ffit, afterEach, beforeEach, conditionPromise} = require('./async-spec-helpers') // eslint-disable-line no-unused-vars +const { + it, + fit, + ffit, + afterEach, + beforeEach, + conditionPromise +} = require('./async-spec-helpers') // eslint-disable-line no-unused-vars describe('UIWatcher', () => { let uiWatcher = null - beforeEach(() => atom.packages.packageDirPaths.push(path.join(__dirname, 'fixtures'))) + beforeEach(() => + atom.packages.packageDirPaths.push(path.join(__dirname, 'fixtures')) + ) afterEach(() => uiWatcher && uiWatcher.destroy()) describe("when a base theme's file changes", () => { beforeEach(() => { - spyOn(atom.themes, 'resolveStylesheet').andReturn(path.join(__dirname, 'fixtures', 'static', 'atom.less')) + spyOn(atom.themes, 'resolveStylesheet').andReturn( + path.join(__dirname, 'fixtures', 'static', 'atom.less') + ) uiWatcher = new UIWatcher() }) it('reloads all the base styles', () => { spyOn(atom.themes, 'reloadBaseStylesheets') - expect(uiWatcher.baseTheme.entities[0].getPath()).toContain(`${path.sep}static${path.sep}`) + expect(uiWatcher.baseTheme.entities[0].getPath()).toContain( + `${path.sep}static${path.sep}` + ) uiWatcher.baseTheme.entities[0].emitter.emit('did-change') expect(atom.themes.reloadBaseStylesheets).toHaveBeenCalled() @@ -28,7 +41,11 @@ describe('UIWatcher', () => { }) it("watches all the style sheets in the theme's styles folder", async () => { - const packagePath = path.join(__dirname, 'fixtures', 'package-with-styles-folder') + const packagePath = path.join( + __dirname, + 'fixtures', + 'package-with-styles-folder' + ) await atom.packages.activatePackage(packagePath) uiWatcher = new UIWatcher() @@ -36,15 +53,25 @@ describe('UIWatcher', () => { const lastWatcher = uiWatcher.watchers[uiWatcher.watchers.length - 1] expect(lastWatcher.entities.length).toBe(4) - expect(lastWatcher.entities[0].getPath()).toBe(path.join(packagePath, 'styles')) - expect(lastWatcher.entities[1].getPath()).toBe(path.join(packagePath, 'styles', '3.css')) - expect(lastWatcher.entities[2].getPath()).toBe(path.join(packagePath, 'styles', 'sub', '1.css')) - expect(lastWatcher.entities[3].getPath()).toBe(path.join(packagePath, 'styles', 'sub', '2.less')) + expect(lastWatcher.entities[0].getPath()).toBe( + path.join(packagePath, 'styles') + ) + expect(lastWatcher.entities[1].getPath()).toBe( + path.join(packagePath, 'styles', '3.css') + ) + expect(lastWatcher.entities[2].getPath()).toBe( + path.join(packagePath, 'styles', 'sub', '1.css') + ) + expect(lastWatcher.entities[3].getPath()).toBe( + path.join(packagePath, 'styles', 'sub', '2.less') + ) }) describe('when a package stylesheet file changes', async () => { beforeEach(async () => { - await atom.packages.activatePackage(path.join(__dirname, 'fixtures', 'package-with-styles-manifest')) + await atom.packages.activatePackage( + path.join(__dirname, 'fixtures', 'package-with-styles-manifest') + ) uiWatcher = new UIWatcher() }) @@ -52,7 +79,9 @@ describe('UIWatcher', () => { const pack = atom.packages.getActivePackages()[0] spyOn(pack, 'reloadStylesheets') - uiWatcher.watchers[uiWatcher.watchers.length - 1].entities[1].emitter.emit('did-change') + uiWatcher.watchers[ + uiWatcher.watchers.length - 1 + ].entities[1].emitter.emit('did-change') expect(pack.reloadStylesheets).toHaveBeenCalled() }) @@ -71,7 +100,10 @@ describe('UIWatcher', () => { describe('when a package global file changes', () => { beforeEach(async () => { - atom.config.set('core.themes', ['theme-with-ui-variables', 'theme-with-multiple-imported-files']) + atom.config.set('core.themes', [ + 'theme-with-ui-variables', + 'theme-with-multiple-imported-files' + ]) await atom.themes.activateThemes() uiWatcher = new UIWatcher() @@ -85,7 +117,9 @@ describe('UIWatcher', () => { spyOn(theme, 'reloadStylesheets') } - for (const entity of uiWatcher.watchedThemes.get('theme-with-multiple-imported-files').entities) { + for (const entity of uiWatcher.watchedThemes.get( + 'theme-with-multiple-imported-files' + ).entities) { if (entity.getPath().indexOf('variables') > -1) varEntity = entity } varEntity.emitter.emit('did-change') @@ -101,21 +135,31 @@ describe('UIWatcher', () => { uiWatcher = new UIWatcher() expect(uiWatcher.watchedPackages.size).toBe(0) - await atom.packages.activatePackage(path.join(__dirname, 'fixtures', 'package-with-styles-folder')) - expect(uiWatcher.watchedPackages.get('package-with-styles-folder')).not.toBeUndefined() + await atom.packages.activatePackage( + path.join(__dirname, 'fixtures', 'package-with-styles-folder') + ) + expect( + uiWatcher.watchedPackages.get('package-with-styles-folder') + ).not.toBeUndefined() }) it('unwatches a package after it is deactivated', async () => { - await atom.packages.activatePackage(path.join(__dirname, 'fixtures', 'package-with-styles-folder')) + await atom.packages.activatePackage( + path.join(__dirname, 'fixtures', 'package-with-styles-folder') + ) uiWatcher = new UIWatcher() - const watcher = uiWatcher.watchedPackages.get('package-with-styles-folder') + const watcher = uiWatcher.watchedPackages.get( + 'package-with-styles-folder' + ) expect(watcher).not.toBeUndefined() const watcherDestructionSpy = jasmine.createSpy('watcher-on-did-destroy') watcher.onDidDestroy(watcherDestructionSpy) await atom.packages.deactivatePackage('package-with-styles-folder') - expect(uiWatcher.watchedPackages.get('package-with-styles-folder')).toBeUndefined() + expect( + uiWatcher.watchedPackages.get('package-with-styles-folder') + ).toBeUndefined() expect(uiWatcher.watchedPackages.size).toBe(0) expect(watcherDestructionSpy).toHaveBeenCalled() }) @@ -124,7 +168,9 @@ describe('UIWatcher', () => { uiWatcher = new UIWatcher() uiWatcher.destroy() - await atom.packages.activatePackage(path.join(__dirname, 'fixtures', 'package-with-styles-folder')) + await atom.packages.activatePackage( + path.join(__dirname, 'fixtures', 'package-with-styles-folder') + ) expect(uiWatcher.watchedPackages.size).toBe(0) }) }) @@ -132,7 +178,10 @@ describe('UIWatcher', () => { describe('minimal theme packages', () => { let pack = null beforeEach(async () => { - atom.config.set('core.themes', ['theme-with-syntax-variables', 'theme-with-index-less']) + atom.config.set('core.themes', [ + 'theme-with-syntax-variables', + 'theme-with-index-less' + ]) await atom.themes.activateThemes() uiWatcher = new UIWatcher() pack = atom.themes.getActiveThemes()[0] @@ -157,7 +206,10 @@ describe('UIWatcher', () => { describe('theme packages', () => { let pack = null beforeEach(async () => { - atom.config.set('core.themes', ['theme-with-syntax-variables', 'theme-with-multiple-imported-files']) + atom.config.set('core.themes', [ + 'theme-with-syntax-variables', + 'theme-with-multiple-imported-files' + ]) await atom.themes.activateThemes() uiWatcher = new UIWatcher() @@ -170,7 +222,9 @@ describe('UIWatcher', () => { spyOn(pack, 'reloadStylesheets') spyOn(atom.themes, 'reloadBaseStylesheets') - const watcher = uiWatcher.watchedThemes.get('theme-with-multiple-imported-files') + const watcher = uiWatcher.watchedThemes.get( + 'theme-with-multiple-imported-files' + ) expect(watcher.entities.length).toBe(6) @@ -186,14 +240,21 @@ describe('UIWatcher', () => { jasmine.useRealClock() atom.config.set('core.themes', []) - await conditionPromise(() => !uiWatcher.watchedThemes['theme-with-multiple-imported-files']) + await conditionPromise( + () => !uiWatcher.watchedThemes['theme-with-multiple-imported-files'] + ) }) it('watches a new theme when it is deactivated', async () => { jasmine.useRealClock() - atom.config.set('core.themes', ['theme-with-syntax-variables', 'theme-with-package-file']) - await conditionPromise(() => uiWatcher.watchedThemes.get('theme-with-package-file')) + atom.config.set('core.themes', [ + 'theme-with-syntax-variables', + 'theme-with-package-file' + ]) + await conditionPromise(() => + uiWatcher.watchedThemes.get('theme-with-package-file') + ) pack = atom.themes.getActiveThemes()[0] spyOn(pack, 'reloadStylesheets') diff --git a/packages/exception-reporting/lib/main.js b/packages/exception-reporting/lib/main.js index 3909d5793..5893638f4 100644 --- a/packages/exception-reporting/lib/main.js +++ b/packages/exception-reporting/lib/main.js @@ -1,6 +1,6 @@ /** @babel */ -import {CompositeDisposable} from 'atom' +import { CompositeDisposable } from 'atom' let reporter @@ -13,36 +13,44 @@ function getReporter () { } export default { - activate() { + activate () { this.subscriptions = new CompositeDisposable() if (!atom.config.get('exception-reporting.userId')) { atom.config.set('exception-reporting.userId', require('node-uuid').v4()) } - this.subscriptions.add(atom.onDidThrowError(({message, url, line, column, originalError}) => { - try { - getReporter().reportUncaughtException(originalError) - } catch (secondaryException) { + this.subscriptions.add( + atom.onDidThrowError(({ message, url, line, column, originalError }) => { try { - console.error("Error reporting uncaught exception", secondaryException) - getReporter().reportUncaughtException(secondaryException) - } catch (error) { } - } - }) - ) - - if (atom.onDidFailAssertion != null) { - this.subscriptions.add(atom.onDidFailAssertion(error => { - try { - getReporter().reportFailedAssertion(error) + getReporter().reportUncaughtException(originalError) } catch (secondaryException) { try { - console.error("Error reporting assertion failure", secondaryException) + console.error( + 'Error reporting uncaught exception', + secondaryException + ) getReporter().reportUncaughtException(secondaryException) } catch (error) {} } }) + ) + + if (atom.onDidFailAssertion != null) { + this.subscriptions.add( + atom.onDidFailAssertion(error => { + try { + getReporter().reportFailedAssertion(error) + } catch (secondaryException) { + try { + console.error( + 'Error reporting assertion failure', + secondaryException + ) + getReporter().reportUncaughtException(secondaryException) + } catch (error) {} + } + }) ) } } diff --git a/packages/exception-reporting/lib/reporter.js b/packages/exception-reporting/lib/reporter.js index 42886c6ba..a702134a1 100644 --- a/packages/exception-reporting/lib/reporter.js +++ b/packages/exception-reporting/lib/reporter.js @@ -13,9 +13,15 @@ const StackTraceCache = new WeakMap() export default class Reporter { constructor (params = {}) { this.request = params.request || window.fetch - this.alwaysReport = params.hasOwnProperty('alwaysReport') ? params.alwaysReport : false - this.reportPreviousErrors = params.hasOwnProperty('reportPreviousErrors') ? params.reportPreviousErrors : true - this.resourcePath = this.normalizePath(params.resourcePath || process.resourcesPath) + this.alwaysReport = params.hasOwnProperty('alwaysReport') + ? params.alwaysReport + : false + this.reportPreviousErrors = params.hasOwnProperty('reportPreviousErrors') + ? params.reportPreviousErrors + : true + this.resourcePath = this.normalizePath( + params.resourcePath || process.resourcesPath + ) this.reportedErrors = [] this.reportedAssertionFailures = [] } @@ -28,22 +34,24 @@ export default class Reporter { version: LIB_VERSION, url: 'https://www.atom.io' }, - events: [{ - payloadVersion: "2", - exceptions: [this.buildExceptionJSON(error, params.projectRoot)], - severity: params.severity, - user: { - id: params.userId - }, - app: { - version: params.appVersion, - releaseStage: params.releaseStage - }, - device: { - osVersion: params.osVersion - }, - metaData: error.metadata - }] + events: [ + { + payloadVersion: '2', + exceptions: [this.buildExceptionJSON(error, params.projectRoot)], + severity: params.severity, + user: { + id: params.userId + }, + app: { + version: params.appVersion, + releaseStage: params.releaseStage + }, + device: { + osVersion: params.osVersion + }, + metaData: error.metadata + } + ] } } @@ -59,7 +67,8 @@ export default class Reporter { return this.parseStackTrace(error).map(callSite => { return { file: this.scrubPath(callSite.getFileName()), - method: callSite.getMethodName() || callSite.getFunctionName() || "none", + method: + callSite.getMethodName() || callSite.getFunctionName() || 'none', lineNumber: callSite.getLineNumber(), columnNumber: callSite.getColumnNumber(), inProject: !/node_modules/.test(callSite.getFileName()) @@ -69,8 +78,8 @@ export default class Reporter { normalizePath (pathToNormalize) { return pathToNormalize - .replace('file:///', '') // Sometimes it's a uri - .replace(/\\/g, '/') // Unify path separators across Win/macOS/Linux + .replace('file:///', '') // Sometimes it's a uri + .replace(/\\/g, '/') // Unify path separators across Win/macOS/Linux } scrubPath (pathToScrub) { @@ -96,17 +105,17 @@ export default class Reporter { } getReleaseChannel (version) { - return (version.indexOf('beta') > -1) + return version.indexOf('beta') > -1 ? 'beta' - : (version.indexOf('dev') > -1) - ? 'dev' - : 'stable' + : version.indexOf('dev') > -1 + ? 'dev' + : 'stable' } performRequest (json) { this.request.call(null, 'https://notify.bugsnag.com', { method: 'POST', - headers: new Headers({'Content-Type': 'application/json'}), + headers: new Headers({ 'Content-Type': 'application/json' }), body: JSON.stringify(json) }) } @@ -118,7 +127,10 @@ export default class Reporter { const topFrame = this.parseStackTrace(error)[0] const fileName = topFrame ? topFrame.getFileName() : null - return fileName && (this.isBundledFile(fileName) || this.isTeletypeFile(fileName)) + return ( + fileName && + (this.isBundledFile(fileName) || this.isTeletypeFile(fileName)) + ) } parseStackTrace (error) { @@ -169,21 +181,24 @@ export default class Reporter { notification = atom.notifications.addInfo(message, { detail: error.privateMetadataDescription, - description: "Are you willing to submit this information to a private server for debugging purposes?", + description: + 'Are you willing to submit this information to a private server for debugging purposes?', dismissable: true, buttons: [ { - text: "No", + text: 'No', onDidClick: reportWithoutPrivateMetadata }, { - text: "Yes, Submit for Debugging", + text: 'Yes, Submit for Debugging', onDidClick: reportWithPrivateMetadata } ] }) - dismissSubscription = notification.onDidDismiss(reportWithoutPrivateMetadata) + dismissSubscription = notification.onDidDismiss( + reportWithoutPrivateMetadata + ) } addPackageMetadata (error) { @@ -200,7 +215,9 @@ export default class Reporter { } } - if (error.metadata == null) { error.metadata = {} } + if (error.metadata == null) { + error.metadata = {} + } error.metadata.bundledPackages = bundledPackages error.metadata.userPackages = userPackages } @@ -209,8 +226,12 @@ export default class Reporter { addPreviousErrorsMetadata (error) { if (!this.reportPreviousErrors) return if (!error.metadata) error.metadata = {} - error.metadata.previousErrors = this.reportedErrors.map(error => error.message) - error.metadata.previousAssertionFailures = this.reportedAssertionFailures.map(error => error.message) + error.metadata.previousErrors = this.reportedErrors.map( + error => error.message + ) + error.metadata.previousAssertionFailures = this.reportedAssertionFailures.map( + error => error.message + ) } reportUncaughtException (error) { @@ -219,13 +240,20 @@ export default class Reporter { this.addPackageMetadata(error) this.addPreviousErrorsMetadata(error) - if ((error.privateMetadata != null) && (error.privateMetadataDescription != null)) { - this.requestPrivateMetadataConsent(error, "The Atom team would like to collect the following information to resolve this error:", error => this.reportUncaughtException(error)) + if ( + error.privateMetadata != null && + error.privateMetadataDescription != null + ) { + this.requestPrivateMetadataConsent( + error, + 'The Atom team would like to collect the following information to resolve this error:', + error => this.reportUncaughtException(error) + ) return } let params = this.getDefaultNotificationParams() - params.severity = "error" + params.severity = 'error' this.performRequest(this.buildNotificationJSON(error, params)) this.reportedErrors.push(error) } @@ -236,13 +264,20 @@ export default class Reporter { this.addPackageMetadata(error) this.addPreviousErrorsMetadata(error) - if ((error.privateMetadata != null) && (error.privateMetadataDescription != null)) { - this.requestPrivateMetadataConsent(error, "The Atom team would like to collect some information to resolve an unexpected condition:", error => this.reportFailedAssertion(error)) + if ( + error.privateMetadata != null && + error.privateMetadataDescription != null + ) { + this.requestPrivateMetadataConsent( + error, + 'The Atom team would like to collect some information to resolve an unexpected condition:', + error => this.reportFailedAssertion(error) + ) return } let params = this.getDefaultNotificationParams() - params.severity = "warning" + params.severity = 'warning' this.performRequest(this.buildNotificationJSON(error, params)) this.reportedAssertionFailures.push(error) } @@ -258,10 +293,11 @@ export default class Reporter { isTeletypeFile (fileName) { const teletypePath = atom.packages.resolvePackagePath('teletype') - return teletypePath && this.normalizePath(fileName).indexOf(teletypePath) === 0 + return ( + teletypePath && this.normalizePath(fileName).indexOf(teletypePath) === 0 + ) } } - Reporter.API_KEY = API_KEY Reporter.LIB_VERSION = LIB_VERSION diff --git a/packages/exception-reporting/spec/reporter-spec.js b/packages/exception-reporting/spec/reporter-spec.js index bcfdf8925..615868f3b 100644 --- a/packages/exception-reporting/spec/reporter-spec.js +++ b/packages/exception-reporting/spec/reporter-spec.js @@ -6,25 +6,31 @@ const fs = require('fs-plus') let osVersion = `${os.platform()}-${os.arch()}-${os.release()}` let getReleaseChannel = version => { - return (version.indexOf('beta') > -1) + return version.indexOf('beta') > -1 ? 'beta' - : (version.indexOf('dev') > -1) + : version.indexOf('dev') > -1 ? 'dev' : 'stable' } -describe("Reporter", () => { - let reporter, requests, initialStackTraceLimit, initialFsGetHomeDirectory, mockActivePackages +describe('Reporter', () => { + let reporter, + requests, + initialStackTraceLimit, + initialFsGetHomeDirectory, + mockActivePackages beforeEach(() => { reporter = new Reporter({ - request: (url, options) => requests.push(Object.assign({url}, options)), + request: (url, options) => requests.push(Object.assign({ url }, options)), alwaysReport: true, reportPreviousErrors: false }) requests = [] mockActivePackages = [] - spyOn(atom.packages, 'getActivePackages').andCallFake(() => mockActivePackages) + spyOn(atom.packages, 'getActivePackages').andCallFake( + () => mockActivePackages + ) initialStackTraceLimit = Error.stackTraceLimit Error.stackTraceLimit = 1 @@ -37,11 +43,12 @@ describe("Reporter", () => { Error.stackTraceLimit = initialStackTraceLimit }) - describe(".reportUncaughtException(error)", () => { - it("posts errors originated inside Atom Core to BugSnag", () => { + describe('.reportUncaughtException(error)', () => { + it('posts errors originated inside Atom Core to BugSnag', () => { const repositoryRootPath = path.join(__dirname, '..') reporter = new Reporter({ - request: (url, options) => requests.push(Object.assign({url}, options)), + request: (url, options) => + requests.push(Object.assign({ url }, options)), alwaysReport: true, reportPreviousErrors: false, resourcePath: repositoryRootPath @@ -50,111 +57,123 @@ describe("Reporter", () => { let error = new Error() Error.captureStackTrace(error) reporter.reportUncaughtException(error) - let [lineNumber, columnNumber] = error.stack.match(/.js:(\d+):(\d+)/).slice(1).map(s => parseInt(s)) + let [lineNumber, columnNumber] = error.stack + .match(/.js:(\d+):(\d+)/) + .slice(1) + .map(s => parseInt(s)) expect(requests.length).toBe(1) let [request] = requests - expect(request.method).toBe("POST") - expect(request.url).toBe("https://notify.bugsnag.com") - expect(request.headers.get("Content-Type")).toBe("application/json") + expect(request.method).toBe('POST') + expect(request.url).toBe('https://notify.bugsnag.com') + expect(request.headers.get('Content-Type')).toBe('application/json') let body = JSON.parse(request.body) // Delete `inProject` field because tests may fail when run as part of Atom core // (i.e. when this test file will be located under `node_modules/exception-reporting/spec`) delete body.events[0].exceptions[0].stacktrace[0].inProject expect(body).toEqual({ - "apiKey": Reporter.API_KEY, - "notifier": { - "name": "Atom", - "version": Reporter.LIB_VERSION, - "url": "https://www.atom.io" + apiKey: Reporter.API_KEY, + notifier: { + name: 'Atom', + version: Reporter.LIB_VERSION, + url: 'https://www.atom.io' }, - "events": [ + events: [ { - "payloadVersion": "2", - "exceptions": [ + payloadVersion: '2', + exceptions: [ { - "errorClass": "Error", - "message": "", - "stacktrace": [ + errorClass: 'Error', + message: '', + stacktrace: [ { - "method": semver.gt(process.versions.electron, '1.6.0') ? 'Spec.it' : 'it', - "file": "spec/reporter-spec.js", - "lineNumber": lineNumber, - "columnNumber": columnNumber + method: semver.gt(process.versions.electron, '1.6.0') + ? 'Spec.it' + : 'it', + file: 'spec/reporter-spec.js', + lineNumber: lineNumber, + columnNumber: columnNumber } ] } ], - "severity": "error", - "user": {}, - "app": { - "version": atom.getVersion(), - "releaseStage": getReleaseChannel(atom.getVersion()) + severity: 'error', + user: {}, + app: { + version: atom.getVersion(), + releaseStage: getReleaseChannel(atom.getVersion()) }, - "device": { - "osVersion": osVersion + device: { + osVersion: osVersion } } ] - });}) + }) + }) - it("posts errors originated outside Atom Core to BugSnag", () => { + it('posts errors originated outside Atom Core to BugSnag', () => { fs.getHomeDirectory = () => path.join(__dirname, '..', '..') let error = new Error() Error.captureStackTrace(error) reporter.reportUncaughtException(error) - let [lineNumber, columnNumber] = error.stack.match(/.js:(\d+):(\d+)/).slice(1).map(s => parseInt(s)) + let [lineNumber, columnNumber] = error.stack + .match(/.js:(\d+):(\d+)/) + .slice(1) + .map(s => parseInt(s)) expect(requests.length).toBe(1) let [request] = requests - expect(request.method).toBe("POST") - expect(request.url).toBe("https://notify.bugsnag.com") - expect(request.headers.get("Content-Type")).toBe("application/json") + expect(request.method).toBe('POST') + expect(request.url).toBe('https://notify.bugsnag.com') + expect(request.headers.get('Content-Type')).toBe('application/json') let body = JSON.parse(request.body) // Delete `inProject` field because tests may fail when run as part of Atom core // (i.e. when this test file will be located under `node_modules/exception-reporting/spec`) delete body.events[0].exceptions[0].stacktrace[0].inProject expect(body).toEqual({ - "apiKey": Reporter.API_KEY, - "notifier": { - "name": "Atom", - "version": Reporter.LIB_VERSION, - "url": "https://www.atom.io" + apiKey: Reporter.API_KEY, + notifier: { + name: 'Atom', + version: Reporter.LIB_VERSION, + url: 'https://www.atom.io' }, - "events": [ + events: [ { - "payloadVersion": "2", - "exceptions": [ + payloadVersion: '2', + exceptions: [ { - "errorClass": "Error", - "message": "", - "stacktrace": [ + errorClass: 'Error', + message: '', + stacktrace: [ { - "method": semver.gt(process.versions.electron, '1.6.0') ? 'Spec.it' : 'it', - "file": '~/exception-reporting/spec/reporter-spec.js', - "lineNumber": lineNumber, - "columnNumber": columnNumber + method: semver.gt(process.versions.electron, '1.6.0') + ? 'Spec.it' + : 'it', + file: '~/exception-reporting/spec/reporter-spec.js', + lineNumber: lineNumber, + columnNumber: columnNumber } ] } ], - "severity": "error", - "user": {}, - "app": { - "version": atom.getVersion(), - "releaseStage": getReleaseChannel(atom.getVersion()) + severity: 'error', + user: {}, + app: { + version: atom.getVersion(), + releaseStage: getReleaseChannel(atom.getVersion()) }, - "device": { - "osVersion": osVersion + device: { + osVersion: osVersion } } ] - });}) + }) + }) - describe("when the error object has `privateMetadata` and `privateMetadataDescription` fields", () => { + describe('when the error object has `privateMetadata` and `privateMetadataDescription` fields', () => { let [error, notification] = [] beforeEach(() => { @@ -164,17 +183,17 @@ describe("Reporter", () => { error = new Error() Error.captureStackTrace(error) - error.metadata = {foo: "bar"} - error.privateMetadata = {baz: "quux"} - error.privateMetadataDescription = "The contents of baz" + error.metadata = { foo: 'bar' } + error.privateMetadata = { baz: 'quux' } + error.privateMetadataDescription = 'The contents of baz' }) - it("posts a notification asking for consent", () => { + it('posts a notification asking for consent', () => { reporter.reportUncaughtException(error) expect(atom.notifications.addInfo).toHaveBeenCalled() }) - it("submits the error with the private metadata if the user consents", () => { + it('submits the error with the private metadata if the user consents', () => { spyOn(reporter, 'reportUncaughtException').andCallThrough() reporter.reportUncaughtException(error) reporter.reportUncaughtException.reset() @@ -189,12 +208,12 @@ describe("Reporter", () => { expect(reporter.reportUncaughtException.callCount).toBe(1) expect(error.privateMetadata).toBeUndefined() expect(error.privateMetadataDescription).toBeUndefined() - expect(error.metadata).toEqual({foo: "bar", baz: "quux"}) + expect(error.metadata).toEqual({ foo: 'bar', baz: 'quux' }) expect(notification.isDismissed()).toBe(true) }) - it("submits the error without the private metadata if the user does not consent", () => { + it('submits the error without the private metadata if the user does not consent', () => { spyOn(reporter, 'reportUncaughtException').andCallThrough() reporter.reportUncaughtException(error) reporter.reportUncaughtException.reset() @@ -209,12 +228,12 @@ describe("Reporter", () => { expect(reporter.reportUncaughtException.callCount).toBe(1) expect(error.privateMetadata).toBeUndefined() expect(error.privateMetadataDescription).toBeUndefined() - expect(error.metadata).toEqual({foo: "bar"}) + expect(error.metadata).toEqual({ foo: 'bar' }) expect(notification.isDismissed()).toBe(true) }) - it("submits the error without the private metadata if the user dismisses the notification", () => { + it('submits the error without the private metadata if the user dismisses the notification', () => { spyOn(reporter, 'reportUncaughtException').andCallThrough() reporter.reportUncaughtException(error) reporter.reportUncaughtException.reset() @@ -226,14 +245,34 @@ describe("Reporter", () => { expect(reporter.reportUncaughtException.callCount).toBe(1) expect(error.privateMetadata).toBeUndefined() expect(error.privateMetadataDescription).toBeUndefined() - expect(error.metadata).toEqual({foo: "bar"});});}) + expect(error.metadata).toEqual({ foo: 'bar' }) + }) + }) it('treats packages located in atom.packages.getPackageDirPaths as user packages', () => { mockActivePackages = [ - {name: 'user-1', path: '/Users/user/.atom/packages/user-1', metadata: {version: '1.0.0'}}, - {name: 'user-2', path: '/Users/user/.atom/packages/user-2', metadata: {version: '1.2.0'}}, - {name: 'bundled-1', path: '/Applications/Atom.app/Contents/Resources/app.asar/node_modules/bundled-1', metadata: {version: '1.0.0'}}, - {name: 'bundled-2', path: '/Applications/Atom.app/Contents/Resources/app.asar/node_modules/bundled-2', metadata: {version: '1.2.0'}}, + { + name: 'user-1', + path: '/Users/user/.atom/packages/user-1', + metadata: { version: '1.0.0' } + }, + { + name: 'user-2', + path: '/Users/user/.atom/packages/user-2', + metadata: { version: '1.2.0' } + }, + { + name: 'bundled-1', + path: + '/Applications/Atom.app/Contents/Resources/app.asar/node_modules/bundled-1', + metadata: { version: '1.0.0' } + }, + { + name: 'bundled-2', + path: + '/Applications/Atom.app/Contents/Resources/app.asar/node_modules/bundled-2', + metadata: { version: '1.2.0' } + } ] const packageDirPaths = ['/Users/user/.atom/packages'] @@ -269,69 +308,78 @@ describe("Reporter", () => { const lastRequest = requests[requests.length - 1] const body = JSON.parse(lastRequest.body) - console.log(body); + console.log(body) expect(body.events[0].metaData.previousErrors).toEqual(['A', 'B']) - expect(body.events[0].metaData.previousAssertionFailures).toEqual(['X', 'Y']) + expect(body.events[0].metaData.previousAssertionFailures).toEqual([ + 'X', + 'Y' + ]) }) }) - describe(".reportFailedAssertion(error)", () => { - it("posts warnings to bugsnag", () => { + describe('.reportFailedAssertion(error)', () => { + it('posts warnings to bugsnag', () => { fs.getHomeDirectory = () => path.join(__dirname, '..', '..') let error = new Error() Error.captureStackTrace(error) reporter.reportFailedAssertion(error) - let [lineNumber, columnNumber] = error.stack.match(/.js:(\d+):(\d+)/).slice(1).map(s => parseInt(s)) + let [lineNumber, columnNumber] = error.stack + .match(/.js:(\d+):(\d+)/) + .slice(1) + .map(s => parseInt(s)) expect(requests.length).toBe(1) let [request] = requests - expect(request.method).toBe("POST") - expect(request.url).toBe("https://notify.bugsnag.com") - expect(request.headers.get("Content-Type")).toBe("application/json") + expect(request.method).toBe('POST') + expect(request.url).toBe('https://notify.bugsnag.com') + expect(request.headers.get('Content-Type')).toBe('application/json') let body = JSON.parse(request.body) // Delete `inProject` field because tests may fail when run as part of Atom core // (i.e. when this test file will be located under `node_modules/exception-reporting/spec`) delete body.events[0].exceptions[0].stacktrace[0].inProject expect(body).toEqual({ - "apiKey": Reporter.API_KEY, - "notifier": { - "name": "Atom", - "version": Reporter.LIB_VERSION, - "url": "https://www.atom.io" + apiKey: Reporter.API_KEY, + notifier: { + name: 'Atom', + version: Reporter.LIB_VERSION, + url: 'https://www.atom.io' }, - "events": [ + events: [ { - "payloadVersion": "2", - "exceptions": [ + payloadVersion: '2', + exceptions: [ { - "errorClass": "Error", - "message": "", - "stacktrace": [ + errorClass: 'Error', + message: '', + stacktrace: [ { - "method": semver.gt(process.versions.electron, '1.6.0') ? 'Spec.it' : 'it', - "file": '~/exception-reporting/spec/reporter-spec.js', - "lineNumber": lineNumber, - "columnNumber": columnNumber + method: semver.gt(process.versions.electron, '1.6.0') + ? 'Spec.it' + : 'it', + file: '~/exception-reporting/spec/reporter-spec.js', + lineNumber: lineNumber, + columnNumber: columnNumber } ] } ], - "severity": "warning", - "user": {}, - "app": { - "version": atom.getVersion(), - "releaseStage": getReleaseChannel(atom.getVersion()) + severity: 'warning', + user: {}, + app: { + version: atom.getVersion(), + releaseStage: getReleaseChannel(atom.getVersion()) }, - "device": { - "osVersion": osVersion + device: { + osVersion: osVersion } } ] - });}) + }) + }) - describe("when the error object has `privateMetadata` and `privateMetadataDescription` fields", () => { + describe('when the error object has `privateMetadata` and `privateMetadataDescription` fields', () => { let [error, notification] = [] beforeEach(() => { @@ -341,17 +389,17 @@ describe("Reporter", () => { error = new Error() Error.captureStackTrace(error) - error.metadata = {foo: "bar"} - error.privateMetadata = {baz: "quux"} - error.privateMetadataDescription = "The contents of baz" + error.metadata = { foo: 'bar' } + error.privateMetadata = { baz: 'quux' } + error.privateMetadataDescription = 'The contents of baz' }) - it("posts a notification asking for consent", () => { + it('posts a notification asking for consent', () => { reporter.reportFailedAssertion(error) expect(atom.notifications.addInfo).toHaveBeenCalled() }) - it("submits the error with the private metadata if the user consents", () => { + it('submits the error with the private metadata if the user consents', () => { spyOn(reporter, 'reportFailedAssertion').andCallThrough() reporter.reportFailedAssertion(error) reporter.reportFailedAssertion.reset() @@ -366,12 +414,12 @@ describe("Reporter", () => { expect(reporter.reportFailedAssertion.callCount).toBe(1) expect(error.privateMetadata).toBeUndefined() expect(error.privateMetadataDescription).toBeUndefined() - expect(error.metadata).toEqual({foo: "bar", baz: "quux"}) + expect(error.metadata).toEqual({ foo: 'bar', baz: 'quux' }) expect(notification.isDismissed()).toBe(true) }) - it("submits the error without the private metadata if the user does not consent", () => { + it('submits the error without the private metadata if the user does not consent', () => { spyOn(reporter, 'reportFailedAssertion').andCallThrough() reporter.reportFailedAssertion(error) reporter.reportFailedAssertion.reset() @@ -386,12 +434,12 @@ describe("Reporter", () => { expect(reporter.reportFailedAssertion.callCount).toBe(1) expect(error.privateMetadata).toBeUndefined() expect(error.privateMetadataDescription).toBeUndefined() - expect(error.metadata).toEqual({foo: "bar"}) + expect(error.metadata).toEqual({ foo: 'bar' }) expect(notification.isDismissed()).toBe(true) }) - it("submits the error without the private metadata if the user dismisses the notification", () => { + it('submits the error without the private metadata if the user dismisses the notification', () => { spyOn(reporter, 'reportFailedAssertion').andCallThrough() reporter.reportFailedAssertion(error) reporter.reportFailedAssertion.reset() @@ -403,13 +451,17 @@ describe("Reporter", () => { expect(reporter.reportFailedAssertion.callCount).toBe(1) expect(error.privateMetadata).toBeUndefined() expect(error.privateMetadataDescription).toBeUndefined() - expect(error.metadata).toEqual({foo: "bar"}) + expect(error.metadata).toEqual({ foo: 'bar' }) }) it("only notifies the user once for a given 'privateMetadataRequestName'", () => { let fakeStorage = {} - spyOn(global.localStorage, 'setItem').andCallFake((key, value) => fakeStorage[key] = value) - spyOn(global.localStorage, 'getItem').andCallFake(key => fakeStorage[key]) + spyOn(global.localStorage, 'setItem').andCallFake( + (key, value) => (fakeStorage[key] = value) + ) + spyOn(global.localStorage, 'getItem').andCallFake( + key => fakeStorage[key] + ) error.privateMetadataRequestName = 'foo' @@ -423,7 +475,7 @@ describe("Reporter", () => { let error2 = new Error() Error.captureStackTrace(error2) error2.privateMetadataDescription = 'Something about you' - error2.privateMetadata = {baz: 'quux'} + error2.privateMetadata = { baz: 'quux' } error2.privateMetadataRequestName = 'bar' reporter.reportFailedAssertion(error2) @@ -433,10 +485,28 @@ describe("Reporter", () => { it('treats packages located in atom.packages.getPackageDirPaths as user packages', () => { mockActivePackages = [ - {name: 'user-1', path: '/Users/user/.atom/packages/user-1', metadata: {version: '1.0.0'}}, - {name: 'user-2', path: '/Users/user/.atom/packages/user-2', metadata: {version: '1.2.0'}}, - {name: 'bundled-1', path: '/Applications/Atom.app/Contents/Resources/app.asar/node_modules/bundled-1', metadata: {version: '1.0.0'}}, - {name: 'bundled-2', path: '/Applications/Atom.app/Contents/Resources/app.asar/node_modules/bundled-2', metadata: {version: '1.2.0'}}, + { + name: 'user-1', + path: '/Users/user/.atom/packages/user-1', + metadata: { version: '1.0.0' } + }, + { + name: 'user-2', + path: '/Users/user/.atom/packages/user-2', + metadata: { version: '1.2.0' } + }, + { + name: 'bundled-1', + path: + '/Applications/Atom.app/Contents/Resources/app.asar/node_modules/bundled-1', + metadata: { version: '1.0.0' } + }, + { + name: 'bundled-2', + path: + '/Applications/Atom.app/Contents/Resources/app.asar/node_modules/bundled-2', + metadata: { version: '1.2.0' } + } ] const packageDirPaths = ['/Users/user/.atom/packages'] @@ -473,7 +543,10 @@ describe("Reporter", () => { const body = JSON.parse(lastRequest.body) expect(body.events[0].metaData.previousErrors).toEqual(['A', 'B']) - expect(body.events[0].metaData.previousAssertionFailures).toEqual(['X', 'Y']) + expect(body.events[0].metaData.previousAssertionFailures).toEqual([ + 'X', + 'Y' + ]) }) }) }) diff --git a/packages/git-diff/lib/diff-list-view.js b/packages/git-diff/lib/diff-list-view.js index 38e50880f..22f7c7d23 100644 --- a/packages/git-diff/lib/diff-list-view.js +++ b/packages/git-diff/lib/diff-list-view.js @@ -1,14 +1,13 @@ const SelectListView = require('atom-select-list') -const {repositoryForPath} = require('./helpers') +const { repositoryForPath } = require('./helpers') -module.exports = -class DiffListView { +module.exports = class DiffListView { constructor () { this.selectListView = new SelectListView({ emptyMessage: 'No diffs in file', items: [], - filterKeyForItem: (diff) => diff.lineText, - elementForItem: (diff) => { + filterKeyForItem: diff => diff.lineText, + elementForItem: diff => { const li = document.createElement('li') li.classList.add('two-lines') @@ -19,15 +18,19 @@ class DiffListView { const secondaryLine = document.createElement('div') secondaryLine.classList.add('secondary-line') - secondaryLine.textContent = `-${diff.oldStart},${diff.oldLines} +${diff.newStart},${diff.newLines}` + secondaryLine.textContent = `-${diff.oldStart},${diff.oldLines} +${ + diff.newStart + },${diff.newLines}` li.appendChild(secondaryLine) return li }, - didConfirmSelection: (diff) => { + didConfirmSelection: diff => { this.cancel() const bufferRow = diff.newStart > 0 ? diff.newStart - 1 : diff.newStart - this.editor.setCursorBufferPosition([bufferRow, 0], {autoscroll: true}) + this.editor.setCursorBufferPosition([bufferRow, 0], { + autoscroll: true + }) this.editor.moveToFirstCharacterOfLine() }, didCancelSelection: () => { @@ -35,7 +38,10 @@ class DiffListView { } }) this.selectListView.element.classList.add('diff-list-view') - this.panel = atom.workspace.addModalPanel({item: this.selectListView, visible: false}) + this.panel = atom.workspace.addModalPanel({ + item: this.selectListView, + visible: false + }) } attach () { @@ -66,7 +72,9 @@ class DiffListView { } else if (editor) { this.editor = editor const repository = repositoryForPath(this.editor.getPath()) - let diffs = repository ? repository.getLineDiffs(this.editor.getPath(), this.editor.getText()) : [] + let diffs = repository + ? repository.getLineDiffs(this.editor.getPath(), this.editor.getText()) + : [] if (!diffs) diffs = [] for (let diff of diffs) { const bufferRow = diff.newStart > 0 ? diff.newStart - 1 : diff.newStart @@ -74,7 +82,7 @@ class DiffListView { diff.lineText = lineText ? lineText.trim() : '' } - await this.selectListView.update({items: diffs}) + await this.selectListView.update({ items: diffs }) this.attach() } } diff --git a/packages/git-diff/lib/git-diff-view.js b/packages/git-diff/lib/git-diff-view.js index 1f1913eab..99d57b483 100644 --- a/packages/git-diff/lib/git-diff-view.js +++ b/packages/git-diff/lib/git-diff-view.js @@ -1,10 +1,9 @@ -const {CompositeDisposable} = require('atom') -const {repositoryForPath} = require('./helpers') +const { CompositeDisposable } = require('atom') +const { repositoryForPath } = require('./helpers') const MAX_BUFFER_LENGTH_TO_DIFF = 2 * 1024 * 1024 -module.exports = -class GitDiffView { +module.exports = class GitDiffView { constructor (editor) { this.updateDiffs = this.updateDiffs.bind(this) this.editor = editor @@ -22,10 +21,18 @@ class GitDiffView { this.editor.onDidStopChanging(this.updateDiffs), this.editor.onDidChangePath(this.updateDiffs), atom.project.onDidChangePaths(() => this.subscribeToRepository()), - atom.commands.add(editorElement, 'git-diff:move-to-next-diff', () => this.moveToNextDiff()), - atom.commands.add(editorElement, 'git-diff:move-to-previous-diff', () => this.moveToPreviousDiff()), - atom.config.onDidChange('git-diff.showIconsInEditorGutter', () => this.updateIconDecoration()), - atom.config.onDidChange('editor.showLineNumbers', () => this.updateIconDecoration()), + atom.commands.add(editorElement, 'git-diff:move-to-next-diff', () => + this.moveToNextDiff() + ), + atom.commands.add(editorElement, 'git-diff:move-to-previous-diff', () => + this.moveToPreviousDiff() + ), + atom.config.onDidChange('git-diff.showIconsInEditorGutter', () => + this.updateIconDecoration() + ), + atom.config.onDidChange('editor.showLineNumbers', () => + this.updateIconDecoration() + ), editorElement.onDidAttach(() => this.updateIconDecoration()), this.editor.onDidDestroy(() => { this.cancelUpdate() @@ -43,7 +50,7 @@ class GitDiffView { let nextDiffLineNumber = null let firstDiffLineNumber = null if (this.diffs) { - for (const {newStart} of this.diffs) { + for (const { newStart } of this.diffs) { if (newStart > cursorLineNumber) { if (nextDiffLineNumber == null) nextDiffLineNumber = newStart - 1 nextDiffLineNumber = Math.min(newStart - 1, nextDiffLineNumber) @@ -55,7 +62,10 @@ class GitDiffView { } // Wrap around to the first diff in the file - if (atom.config.get('git-diff.wrapAroundOnMoveToDiff') && nextDiffLineNumber == null) { + if ( + atom.config.get('git-diff.wrapAroundOnMoveToDiff') && + nextDiffLineNumber == null + ) { nextDiffLineNumber = firstDiffLineNumber } @@ -65,7 +75,10 @@ class GitDiffView { updateIconDecoration () { const gutter = this.editor.getElement().querySelector('.gutter') if (gutter) { - if (atom.config.get('editor.showLineNumbers') && atom.config.get('git-diff.showIconsInEditorGutter')) { + if ( + atom.config.get('editor.showLineNumbers') && + atom.config.get('git-diff.showIconsInEditorGutter') + ) { gutter.classList.add('git-diff-icon') } else { gutter.classList.remove('git-diff-icon') @@ -78,16 +91,22 @@ class GitDiffView { let previousDiffLineNumber = -1 let lastDiffLineNumber = -1 if (this.diffs) { - for (const {newStart} of this.diffs) { + for (const { newStart } of this.diffs) { if (newStart < cursorLineNumber) { - previousDiffLineNumber = Math.max(newStart - 1, previousDiffLineNumber) + previousDiffLineNumber = Math.max( + newStart - 1, + previousDiffLineNumber + ) } lastDiffLineNumber = Math.max(newStart - 1, lastDiffLineNumber) } } // Wrap around to the last diff in the file - if (atom.config.get('git-diff.wrapAroundOnMoveToDiff') && previousDiffLineNumber === -1) { + if ( + atom.config.get('git-diff.wrapAroundOnMoveToDiff') && + previousDiffLineNumber === -1 + ) { previousDiffLineNumber = lastDiffLineNumber } @@ -104,12 +123,16 @@ class GitDiffView { subscribeToRepository () { this.repository = repositoryForPath(this.editor.getPath()) if (this.repository) { - this.subscriptions.add(this.repository.onDidChangeStatuses(() => { - this.scheduleUpdate() - })) - this.subscriptions.add(this.repository.onDidChangeStatus(changedPath => { - if (changedPath === this.editor.getPath()) this.scheduleUpdate() - })) + this.subscriptions.add( + this.repository.onDidChangeStatuses(() => { + this.scheduleUpdate() + }) + ) + this.subscriptions.add( + this.repository.onDidChangeStatus(changedPath => { + if (changedPath === this.editor.getPath()) this.scheduleUpdate() + }) + ) } } @@ -126,16 +149,21 @@ class GitDiffView { if (this.editor.isDestroyed()) return this.removeDecorations() const path = this.editor && this.editor.getPath() - if (path && this.editor.getBuffer().getLength() < MAX_BUFFER_LENGTH_TO_DIFF) { - this.diffs = this.repository && this.repository.getLineDiffs(path, this.editor.getText()) + if ( + path && + this.editor.getBuffer().getLength() < MAX_BUFFER_LENGTH_TO_DIFF + ) { + this.diffs = + this.repository && + this.repository.getLineDiffs(path, this.editor.getText()) if (this.diffs) this.addDecorations(this.diffs) } } addDecorations (diffs) { - for (const {newStart, oldLines, newLines} of diffs) { + for (const { newStart, oldLines, newLines } of diffs) { const startRow = newStart - 1 - const endRow = (newStart + newLines) - 1 + const endRow = newStart + newLines - 1 if (oldLines === 0 && newLines > 0) { this.markRange(startRow, endRow, 'git-line-added') } else if (newLines === 0 && oldLines > 0) { @@ -156,8 +184,10 @@ class GitDiffView { } markRange (startRow, endRow, klass) { - const marker = this.editor.markBufferRange([[startRow, 0], [endRow, 0]], {invalidate: 'never'}) - this.editor.decorateMarker(marker, {type: 'line-number', class: klass}) + const marker = this.editor.markBufferRange([[startRow, 0], [endRow, 0]], { + invalidate: 'never' + }) + this.editor.decorateMarker(marker, { type: 'line-number', class: klass }) this.markers.push(marker) } } diff --git a/packages/git-diff/lib/main.js b/packages/git-diff/lib/main.js index d5162139b..72597b93c 100644 --- a/packages/git-diff/lib/main.js +++ b/packages/git-diff/lib/main.js @@ -11,10 +11,14 @@ module.exports = { if (watchedEditors.has(editor)) return new GitDiffView(editor).start() - atom.commands.add(atom.views.getView(editor), 'git-diff:toggle-diff-list', () => { - if (diffListView == null) diffListView = new DiffListView() - diffListView.toggle() - }) + atom.commands.add( + atom.views.getView(editor), + 'git-diff:toggle-diff-list', + () => { + if (diffListView == null) diffListView = new DiffListView() + diffListView.toggle() + } + ) watchedEditors.add(editor) editor.onDidDestroy(() => watchedEditors.delete(editor)) diff --git a/packages/git-diff/spec/diff-list-view-spec.js b/packages/git-diff/spec/diff-list-view-spec.js index 36ca97b05..5fba8eba1 100644 --- a/packages/git-diff/spec/diff-list-view-spec.js +++ b/packages/git-diff/spec/diff-list-view-spec.js @@ -8,7 +8,10 @@ describe('git-diff:toggle-diff-list', () => { beforeEach(() => { const projectPath = temp.mkdirSync('git-diff-spec-') fs.copySync(path.join(__dirname, 'fixtures', 'working-dir'), projectPath) - fs.moveSync(path.join(projectPath, 'git.git'), path.join(projectPath, '.git')) + fs.moveSync( + path.join(projectPath, 'git.git'), + path.join(projectPath, '.git') + ) atom.project.setPaths([projectPath]) jasmine.attachToDOM(atom.workspace.getElement()) @@ -37,7 +40,10 @@ describe('git-diff:toggle-diff-list', () => { it('moves the cursor to the selected hunk', () => { editor.setCursorBufferPosition([0, 0]) - atom.commands.dispatch(document.querySelector('.diff-list-view'), 'core:confirm') + atom.commands.dispatch( + document.querySelector('.diff-list-view'), + 'core:confirm' + ) expect(editor.getCursorBufferPosition()).toEqual([4, 4]) }) }) diff --git a/packages/git-diff/spec/git-diff-spec.js b/packages/git-diff/spec/git-diff-spec.js index 397693c89..badb15f76 100644 --- a/packages/git-diff/spec/git-diff-spec.js +++ b/packages/git-diff/spec/git-diff-spec.js @@ -12,12 +12,17 @@ describe('GitDiff package', () => { const otherPath = temp.mkdirSync('some-other-path-') fs.copySync(path.join(__dirname, 'fixtures', 'working-dir'), projectPath) - fs.moveSync(path.join(projectPath, 'git.git'), path.join(projectPath, '.git')) + fs.moveSync( + path.join(projectPath, 'git.git'), + path.join(projectPath, '.git') + ) atom.project.setPaths([otherPath, projectPath]) jasmine.attachToDOM(atom.workspace.getElement()) - waitsForPromise(() => atom.workspace.open(path.join(projectPath, 'sample.js'))) + waitsForPromise(() => + atom.workspace.open(path.join(projectPath, 'sample.js')) + ) runs(() => { editor = atom.workspace.getActiveTextEditor() @@ -29,11 +34,18 @@ describe('GitDiff package', () => { describe('when the editor has modified lines', () => { it('highlights the modified lines', () => { - expect(editorElement.querySelectorAll('.git-line-modified').length).toBe(0) + expect(editorElement.querySelectorAll('.git-line-modified').length).toBe( + 0 + ) editor.insertText('a') advanceClock(editor.getBuffer().stoppedChangingDelay) - expect(editorElement.querySelectorAll('.git-line-modified').length).toBe(1) - expect(editorElement.querySelector('.git-line-modified')).toHaveData('buffer-row', 0) + expect(editorElement.querySelectorAll('.git-line-modified').length).toBe( + 1 + ) + expect(editorElement.querySelector('.git-line-modified')).toHaveData( + 'buffer-row', + 0 + ) }) }) @@ -45,7 +57,10 @@ describe('GitDiff package', () => { editor.insertText('a') advanceClock(editor.getBuffer().stoppedChangingDelay) expect(editorElement.querySelectorAll('.git-line-added').length).toBe(1) - expect(editorElement.querySelector('.git-line-added')).toHaveData('buffer-row', 1) + expect(editorElement.querySelector('.git-line-added')).toHaveData( + 'buffer-row', + 1 + ) }) }) @@ -56,7 +71,10 @@ describe('GitDiff package', () => { editor.deleteLine() advanceClock(editor.getBuffer().stoppedChangingDelay) expect(editorElement.querySelectorAll('.git-line-removed').length).toBe(1) - expect(editorElement.querySelector('.git-line-removed')).toHaveData('buffer-row', 4) + expect(editorElement.querySelector('.git-line-removed')).toHaveData( + 'buffer-row', + 4 + ) }) }) @@ -66,29 +84,44 @@ describe('GitDiff package', () => { editor.setCursorBufferPosition([0, 0]) editor.deleteLine() advanceClock(editor.getBuffer().stoppedChangingDelay) - expect(editorElement.querySelectorAll('.git-previous-line-removed').length).toBe(1) - expect(editorElement.querySelector('.git-previous-line-removed')).toHaveData('buffer-row', 0) + expect( + editorElement.querySelectorAll('.git-previous-line-removed').length + ).toBe(1) + expect( + editorElement.querySelector('.git-previous-line-removed') + ).toHaveData('buffer-row', 0) }) }) describe('when a modified line is restored to the HEAD version contents', () => { it('removes the diff highlight', () => { - expect(editorElement.querySelectorAll('.git-line-modified').length).toBe(0) + expect(editorElement.querySelectorAll('.git-line-modified').length).toBe( + 0 + ) editor.insertText('a') advanceClock(editor.getBuffer().stoppedChangingDelay) - expect(editorElement.querySelectorAll('.git-line-modified').length).toBe(1) + expect(editorElement.querySelectorAll('.git-line-modified').length).toBe( + 1 + ) editor.backspace() advanceClock(editor.getBuffer().stoppedChangingDelay) - expect(editorElement.querySelectorAll('.git-line-modified').length).toBe(0) + expect(editorElement.querySelectorAll('.git-line-modified').length).toBe( + 0 + ) }) }) describe('when a modified file is opened', () => { it('highlights the changed lines', () => { - fs.writeFileSync(path.join(projectPath, 'sample.txt'), 'Some different text.') + fs.writeFileSync( + path.join(projectPath, 'sample.txt'), + 'Some different text.' + ) let nextTick = false - waitsForPromise(() => atom.workspace.open(path.join(projectPath, 'sample.txt'))) + waitsForPromise(() => + atom.workspace.open(path.join(projectPath, 'sample.txt')) + ) runs(() => { editorElement = atom.workspace.getActiveTextEditor().getElement() @@ -101,8 +134,13 @@ describe('GitDiff package', () => { waitsFor(() => nextTick) runs(() => { - expect(editorElement.querySelectorAll('.git-line-modified').length).toBe(1) - expect(editorElement.querySelector('.git-line-modified')).toHaveData('buffer-row', 0) + expect( + editorElement.querySelectorAll('.git-line-modified').length + ).toBe(1) + expect(editorElement.querySelector('.git-line-modified')).toHaveData( + 'buffer-row', + 0 + ) }) }) }) @@ -148,7 +186,9 @@ describe('GitDiff package', () => { }) describe('when the wrapAroundOnMoveToDiff config option is false', () => { - beforeEach(() => atom.config.set('git-diff.wrapAroundOnMoveToDiff', false)) + beforeEach(() => + atom.config.set('git-diff.wrapAroundOnMoveToDiff', false) + ) it('does not wraps around to the first/last diff in the file', () => { editor.insertText('a') @@ -177,19 +217,28 @@ describe('GitDiff package', () => { atom.config.set('git-diff.showIconsInEditorGutter', true) }) - it('the gutter has a git-diff-icon class', () => expect(editorElement.querySelector('.gutter')).toHaveClass('git-diff-icon')) + it('the gutter has a git-diff-icon class', () => + expect(editorElement.querySelector('.gutter')).toHaveClass( + 'git-diff-icon' + )) it('keeps the git-diff-icon class when editor.showLineNumbers is toggled', () => { atom.config.set('editor.showLineNumbers', false) - expect(editorElement.querySelector('.gutter')).not.toHaveClass('git-diff-icon') + expect(editorElement.querySelector('.gutter')).not.toHaveClass( + 'git-diff-icon' + ) atom.config.set('editor.showLineNumbers', true) - expect(editorElement.querySelector('.gutter')).toHaveClass('git-diff-icon') + expect(editorElement.querySelector('.gutter')).toHaveClass( + 'git-diff-icon' + ) }) it('removes the git-diff-icon class when the showIconsInEditorGutter config option set to false', () => { atom.config.set('git-diff.showIconsInEditorGutter', false) - expect(editorElement.querySelector('.gutter')).not.toHaveClass('git-diff-icon') + expect(editorElement.querySelector('.gutter')).not.toHaveClass( + 'git-diff-icon' + ) }) }) }) diff --git a/packages/go-to-line/lib/go-to-line-view.js b/packages/go-to-line/lib/go-to-line-view.js index 66759f9d9..93d174dbc 100644 --- a/packages/go-to-line/lib/go-to-line-view.js +++ b/packages/go-to-line/lib/go-to-line-view.js @@ -29,13 +29,13 @@ class GoToLineView { atom.commands.add(this.miniEditor.element, 'core:cancel', () => { this.close() }) - this.miniEditor.onWillInsertText((arg) => { + this.miniEditor.onWillInsertText(arg => { if (arg.text.match(/[^0-9:]/)) { arg.cancel() } }) this.miniEditor.onDidChange(() => { - this.navigate({keepOpen: true}) + this.navigate({ keepOpen: true }) }) } @@ -62,9 +62,11 @@ class GoToLineView { const currentRow = editor.getCursorBufferPosition().row const rowLineNumber = lineNumber.split(/:+/)[0] || '' - const row = rowLineNumber.length > 0 ? parseInt(rowLineNumber) - 1 : currentRow + const row = + rowLineNumber.length > 0 ? parseInt(rowLineNumber) - 1 : currentRow const columnLineNumber = lineNumber.split(/:+/)[1] || '' - const column = columnLineNumber.length > 0 ? parseInt(columnLineNumber) - 1 : -1 + const column = + columnLineNumber.length > 0 ? parseInt(columnLineNumber) - 1 : -1 const position = new Point(row, column) editor.setCursorBufferPosition(position) @@ -83,7 +85,10 @@ class GoToLineView { } restoreFocus () { - if (this.previouslyFocusedElement && this.previouslyFocusedElement.parentElement) { + if ( + this.previouslyFocusedElement && + this.previouslyFocusedElement.parentElement + ) { return this.previouslyFocusedElement.focus() } atom.views.getView(atom.workspace).focus() @@ -93,7 +98,8 @@ class GoToLineView { if (this.panel.isVisible() || !atom.workspace.getActiveTextEditor()) return this.storeFocusedElement() this.panel.show() - this.message.textContent = 'Enter a or : to go there. Examples: "3" for row 3 or "2:7" for row 2 and column 7' + this.message.textContent = + 'Enter a or : to go there. Examples: "3" for row 3 or "2:7" for row 2 and column 7' this.miniEditor.element.focus() } } diff --git a/packages/go-to-line/spec/go-to-line-spec.js b/packages/go-to-line/spec/go-to-line-spec.js index 8b9f3ba92..62551825e 100644 --- a/packages/go-to-line/spec/go-to-line-spec.js +++ b/packages/go-to-line/spec/go-to-line-spec.js @@ -76,8 +76,12 @@ describe('GoToLine', () => { atom.commands.dispatch(goToLine.miniEditor.element, 'core:confirm') const rowsPerPage = editor.getRowsPerPage() const currentRow = editor.getCursorBufferPosition().row - 1 - expect(editor.getFirstVisibleScreenRow()).toBe(currentRow - Math.ceil(rowsPerPage / 2)) - expect(editor.getLastVisibleScreenRow()).toBe(currentRow + Math.floor(rowsPerPage / 2)) + expect(editor.getFirstVisibleScreenRow()).toBe( + currentRow - Math.ceil(rowsPerPage / 2) + ) + expect(editor.getLastVisibleScreenRow()).toBe( + currentRow + Math.floor(rowsPerPage / 2) + ) }) }) diff --git a/packages/grammar-selector/lib/grammar-list-view.js b/packages/grammar-selector/lib/grammar-list-view.js index 557036af5..d6812fcfc 100644 --- a/packages/grammar-selector/lib/grammar-list-view.js +++ b/packages/grammar-selector/lib/grammar-list-view.js @@ -1,14 +1,13 @@ const SelectListView = require('atom-select-list') -module.exports = -class GrammarListView { +module.exports = class GrammarListView { constructor () { - this.autoDetect = {name: 'Auto Detect'} + this.autoDetect = { name: 'Auto Detect' } this.selectListView = new SelectListView({ itemsClassList: ['mark-active'], items: [], - filterKeyForItem: (grammar) => grammar.name, - elementForItem: (grammar) => { + filterKeyForItem: grammar => grammar.name, + elementForItem: grammar => { const grammarName = grammar.name || grammar.scopeName const element = document.createElement('li') if (grammar === this.currentGrammar) { @@ -29,7 +28,7 @@ class GrammarListView { return element }, - didConfirmSelection: (grammar) => { + didConfirmSelection: grammar => { this.cancel() if (grammar === this.autoDetect) { atom.textEditors.clearGrammarOverride(this.editor) @@ -64,7 +63,7 @@ class GrammarListView { attach () { this.previouslyFocusedElement = document.activeElement if (this.panel == null) { - this.panel = atom.workspace.addModalPanel({item: this.selectListView}) + this.panel = atom.workspace.addModalPanel({ item: this.selectListView }) } this.selectListView.focus() this.selectListView.reset() @@ -80,7 +79,7 @@ class GrammarListView { this.currentGrammar = this.autoDetect } - const grammars = atom.grammars.getGrammars().filter((grammar) => { + const grammars = atom.grammars.getGrammars().filter(grammar => { return grammar !== atom.grammars.nullGrammar && grammar.name }) grammars.sort((a, b) => { @@ -97,7 +96,7 @@ class GrammarListView { } }) grammars.unshift(this.autoDetect) - await this.selectListView.update({items: grammars}) + await this.selectListView.update({ items: grammars }) this.attach() } } diff --git a/packages/grammar-selector/lib/grammar-status-view.js b/packages/grammar-selector/lib/grammar-status-view.js index 45dab6cd1..d7f13930b 100644 --- a/packages/grammar-selector/lib/grammar-status-view.js +++ b/packages/grammar-selector/lib/grammar-status-view.js @@ -1,7 +1,6 @@ -const {Disposable} = require('atom') +const { Disposable } = require('atom') -module.exports = -class GrammarStatusView { +module.exports = class GrammarStatusView { constructor (statusBar) { this.statusBar = statusBar this.element = document.createElement('grammar-selector-status') @@ -10,15 +9,25 @@ class GrammarStatusView { this.grammarLink.classList.add('inline-block') this.element.appendChild(this.grammarLink) - this.activeItemSubscription = atom.workspace.observeActiveTextEditor(this.subscribeToActiveTextEditor.bind(this)) + this.activeItemSubscription = atom.workspace.observeActiveTextEditor( + this.subscribeToActiveTextEditor.bind(this) + ) - this.configSubscription = atom.config.observe('grammar-selector.showOnRightSideOfStatusBar', this.attach.bind(this)) - const clickHandler = (event) => { + this.configSubscription = atom.config.observe( + 'grammar-selector.showOnRightSideOfStatusBar', + this.attach.bind(this) + ) + const clickHandler = event => { event.preventDefault() - atom.commands.dispatch(atom.views.getView(atom.workspace.getActiveTextEditor()), 'grammar-selector:show') + atom.commands.dispatch( + atom.views.getView(atom.workspace.getActiveTextEditor()), + 'grammar-selector:show' + ) } this.element.addEventListener('click', clickHandler) - this.clickSubscription = new Disposable(() => { this.element.removeEventListener('click', clickHandler) }) + this.clickSubscription = new Disposable(() => { + this.element.removeEventListener('click', clickHandler) + }) } attach () { @@ -27,8 +36,8 @@ class GrammarStatusView { } this.tile = atom.config.get('grammar-selector.showOnRightSideOfStatusBar') - ? this.statusBar.addRightTile({item: this.element, priority: 10}) - : this.statusBar.addLeftTile({item: this.element, priority: 10}) + ? this.statusBar.addRightTile({ item: this.element, priority: 10 }) + : this.statusBar.addLeftTile({ item: this.element, priority: 10 }) } destroy () { @@ -65,7 +74,9 @@ class GrammarStatusView { const editor = atom.workspace.getActiveTextEditor() if (editor) { - this.grammarSubscription = editor.onDidChangeGrammar(this.updateGrammarText.bind(this)) + this.grammarSubscription = editor.onDidChangeGrammar( + this.updateGrammarText.bind(this) + ) } this.updateGrammarText() } @@ -92,7 +103,9 @@ class GrammarStatusView { this.grammarLink.dataset.grammar = grammarName this.element.style.display = '' - this.tooltip = atom.tooltips.add(this.element, {title: `File uses the ${grammarName} grammar`}) + this.tooltip = atom.tooltips.add(this.element, { + title: `File uses the ${grammarName} grammar` + }) } else { this.element.style.display = 'none' } diff --git a/packages/grammar-selector/lib/main.js b/packages/grammar-selector/lib/main.js index 6f95a44e6..428108dd4 100644 --- a/packages/grammar-selector/lib/main.js +++ b/packages/grammar-selector/lib/main.js @@ -7,10 +7,14 @@ let grammarStatusView = null module.exports = { activate () { - commandDisposable = atom.commands.add('atom-text-editor', 'grammar-selector:show', () => { - if (!grammarListView) grammarListView = new GrammarListView() - grammarListView.toggle() - }) + commandDisposable = atom.commands.add( + 'atom-text-editor', + 'grammar-selector:show', + () => { + if (!grammarListView) grammarListView = new GrammarListView() + grammarListView.toggle() + } + ) }, deactivate () { diff --git a/packages/grammar-selector/spec/async-spec-helpers.js b/packages/grammar-selector/spec/async-spec-helpers.js index 61eeaab39..5fe94e859 100644 --- a/packages/grammar-selector/spec/async-spec-helpers.js +++ b/packages/grammar-selector/spec/async-spec-helpers.js @@ -15,7 +15,6 @@ exports.afterEach = function afterEach (fn) { } }) } - ;['it', 'fit', 'ffit', 'fffit'].forEach(function (name) { exports[name] = function (description, fn) { if (fn === undefined) { @@ -33,8 +32,8 @@ exports.afterEach = function afterEach (fn) { }) function waitsForPromise (message, promise) { - global.waitsFor(message, (done) => { - promise.then(done, (error) => { + global.waitsFor(message, done => { + promise.then(done, error => { jasmine.getEnv().currentSpec.fail(error) done() }) diff --git a/packages/grammar-selector/spec/grammar-selector-spec.js b/packages/grammar-selector/spec/grammar-selector-spec.js index 21ea63d38..1c27d95a5 100644 --- a/packages/grammar-selector/spec/grammar-selector-spec.js +++ b/packages/grammar-selector/spec/grammar-selector-spec.js @@ -1,6 +1,6 @@ const path = require('path') const SelectListView = require('atom-select-list') -const {it, fit, ffit, beforeEach, afterEach} = require('./async-spec-helpers') // eslint-disable-line +const { it, fit, ffit, beforeEach, afterEach } = require('./async-spec-helpers') // eslint-disable-line describe('GrammarSelector', () => { let [editor, textGrammar, jsGrammar] = [] @@ -13,7 +13,9 @@ describe('GrammarSelector', () => { await atom.packages.activatePackage('grammar-selector') await atom.packages.activatePackage('language-text') await atom.packages.activatePackage('language-javascript') - await atom.packages.activatePackage(path.join(__dirname, 'fixtures', 'language-with-no-name')) + await atom.packages.activatePackage( + path.join(__dirname, 'fixtures', 'language-with-no-name') + ) editor = await atom.workspace.open('sample.js') @@ -33,15 +35,24 @@ describe('GrammarSelector', () => { // TODO: Remove once Atom 1.23 reaches stable if (parseFloat(atom.getVersion()) >= 1.23) { // Do not take into account the two JS regex grammars or language-with-no-name - expect(grammarView.querySelectorAll('li').length).toBe(atom.grammars.grammars.length - 3) + expect(grammarView.querySelectorAll('li').length).toBe( + atom.grammars.grammars.length - 3 + ) } else { - expect(grammarView.querySelectorAll('li').length).toBe(atom.grammars.grammars.length - 1) + expect(grammarView.querySelectorAll('li').length).toBe( + atom.grammars.grammars.length - 1 + ) } - expect(grammarView.querySelectorAll('li')[0].textContent).toBe('Auto Detect') + expect(grammarView.querySelectorAll('li')[0].textContent).toBe( + 'Auto Detect' + ) expect(grammarView.textContent.includes('source.a')).toBe(false) - grammarView.querySelectorAll('li').forEach(li => expect(li.textContent).not.toBe(atom.grammars.nullGrammar.name)) - }) - ) + grammarView + .querySelectorAll('li') + .forEach(li => + expect(li.textContent).not.toBe(atom.grammars.nullGrammar.name) + ) + })) describe('when a grammar is selected', () => it('sets the new grammar on the editor', async () => { @@ -51,8 +62,7 @@ describe('GrammarSelector', () => { const grammarView = atom.workspace.getModalPanels()[0].getItem() grammarView.props.didConfirmSelection(textGrammar) expect(editor.getGrammar()).toBe(textGrammar) - }) - ) + })) describe('when auto-detect is selected', () => it('restores the auto-detected grammar on the editor', async () => { @@ -69,8 +79,7 @@ describe('GrammarSelector', () => { grammarView = atom.workspace.getModalPanels()[0].getItem() grammarView.props.didConfirmSelection(grammarView.items[0]) expect(editor.getGrammar()).toBe(jsGrammar) - }) - ) + })) describe("when the editor's current grammar is the null grammar", () => it('displays Auto Detect as the selected grammar', async () => { @@ -79,9 +88,10 @@ describe('GrammarSelector', () => { await SelectListView.getScheduler().getNextUpdatePromise() const grammarView = atom.workspace.getModalPanels()[0].getItem().element - expect(grammarView.querySelector('li.active').textContent).toBe('Auto Detect') - }) - ) + expect(grammarView.querySelector('li.active').textContent).toBe( + 'Auto Detect' + ) + })) describe('when editor is untitled', () => it('sets the new grammar on the editor', async () => { @@ -94,8 +104,7 @@ describe('GrammarSelector', () => { const grammarView = atom.workspace.getModalPanels()[0].getItem() grammarView.props.didConfirmSelection(jsGrammar) expect(editor.getGrammar()).toBe(jsGrammar) - }) - ) + })) describe('Status bar grammar label', () => { let [grammarStatus, grammarTile, statusBar] = [] @@ -114,7 +123,9 @@ describe('GrammarSelector', () => { it('displays the name of the current grammar', () => { expect(grammarStatus.querySelector('a').textContent).toBe('JavaScript') - expect(getTooltipText(grammarStatus)).toBe('File uses the JavaScript grammar') + expect(getTooltipText(grammarStatus)).toBe( + 'File uses the JavaScript grammar' + ) }) it('displays Plain Text when the current grammar is the null grammar', async () => { @@ -123,7 +134,9 @@ describe('GrammarSelector', () => { expect(grammarStatus.querySelector('a').textContent).toBe('Plain Text') expect(grammarStatus).toBeVisible() - expect(getTooltipText(grammarStatus)).toBe('File uses the Plain Text grammar') + expect(getTooltipText(grammarStatus)).toBe( + 'File uses the Plain Text grammar' + ) editor.setGrammar(atom.grammars.grammarForScopeName('source.js')) await atom.views.getNextUpdatePromise() @@ -142,20 +155,31 @@ describe('GrammarSelector', () => { describe('when the grammar-selector.showOnRightSideOfStatusBar setting changes', () => it('moves the item to the preferred side of the status bar', () => { - expect(statusBar.getLeftTiles().map(tile => tile.getItem())).toContain(grammarStatus) - expect(statusBar.getRightTiles().map(tile => tile.getItem())).not.toContain(grammarStatus) + expect(statusBar.getLeftTiles().map(tile => tile.getItem())).toContain( + grammarStatus + ) + expect( + statusBar.getRightTiles().map(tile => tile.getItem()) + ).not.toContain(grammarStatus) atom.config.set('grammar-selector.showOnRightSideOfStatusBar', true) - expect(statusBar.getLeftTiles().map(tile => tile.getItem())).not.toContain(grammarStatus) - expect(statusBar.getRightTiles().map(tile => tile.getItem())).toContain(grammarStatus) + expect( + statusBar.getLeftTiles().map(tile => tile.getItem()) + ).not.toContain(grammarStatus) + expect(statusBar.getRightTiles().map(tile => tile.getItem())).toContain( + grammarStatus + ) atom.config.set('grammar-selector.showOnRightSideOfStatusBar', false) - expect(statusBar.getLeftTiles().map(tile => tile.getItem())).toContain(grammarStatus) - expect(statusBar.getRightTiles().map(tile => tile.getItem())).not.toContain(grammarStatus) - }) - ) + expect(statusBar.getLeftTiles().map(tile => tile.getItem())).toContain( + grammarStatus + ) + expect( + statusBar.getRightTiles().map(tile => tile.getItem()) + ).not.toContain(grammarStatus) + })) describe("when the editor's grammar changes", () => it('displays the new grammar of the editor', async () => { @@ -163,32 +187,37 @@ describe('GrammarSelector', () => { await atom.views.getNextUpdatePromise() expect(grammarStatus.querySelector('a').textContent).toBe('Plain Text') - expect(getTooltipText(grammarStatus)).toBe('File uses the Plain Text grammar') + expect(getTooltipText(grammarStatus)).toBe( + 'File uses the Plain Text grammar' + ) editor.setGrammar(atom.grammars.grammarForScopeName('source.a')) await atom.views.getNextUpdatePromise() expect(grammarStatus.querySelector('a').textContent).toBe('source.a') - expect(getTooltipText(grammarStatus)).toBe('File uses the source.a grammar') - }) - ) + expect(getTooltipText(grammarStatus)).toBe( + 'File uses the source.a grammar' + ) + })) describe('when clicked', () => it('shows the grammar selector modal', () => { const eventHandler = jasmine.createSpy('eventHandler') - atom.commands.add(editor.getElement(), 'grammar-selector:show', eventHandler) + atom.commands.add( + editor.getElement(), + 'grammar-selector:show', + eventHandler + ) grammarStatus.click() expect(eventHandler).toHaveBeenCalled() - }) - ) + })) describe('when the package is deactivated', () => it('removes the view', () => { spyOn(grammarTile, 'destroy') atom.packages.deactivatePackage('grammar-selector') expect(grammarTile.destroy).toHaveBeenCalled() - }) - ) + })) }) }) diff --git a/packages/incompatible-packages/lib/incompatible-packages-component.js b/packages/incompatible-packages/lib/incompatible-packages-component.js index 8eb6c62c6..0f7bd263c 100644 --- a/packages/incompatible-packages/lib/incompatible-packages-component.js +++ b/packages/incompatible-packages/lib/incompatible-packages-component.js @@ -1,7 +1,7 @@ /** @babel */ /** @jsx etch.dom */ -import {BufferedProcess} from 'atom' +import { BufferedProcess } from 'atom' import etch from 'etch' import VIEW_URI from './view-uri' @@ -11,8 +11,8 @@ const REBUILD_SUCCEEDED = 'rebuild-succeeded' export default class IncompatiblePackagesComponent { constructor (packageManager) { - this.rebuildStatuses = new Map - this.rebuildFailureOutputs = new Map + this.rebuildStatuses = new Map() + this.rebuildFailureOutputs = new Map() this.rebuildInProgress = false this.rebuiltPackageCount = 0 this.packageManager = packageManager @@ -25,13 +25,15 @@ export default class IncompatiblePackagesComponent { global.setImmediate(this.populateIncompatiblePackages.bind(this)) } - this.element.addEventListener('click', (event) => { + this.element.addEventListener('click', event => { if (event.target === this.refs.rebuildButton) { this.rebuildIncompatiblePackages() } else if (event.target === this.refs.reloadButton) { atom.reload() } else if (event.target.classList.contains('view-settings')) { - atom.workspace.open(`atom://config/packages/${event.target.package.name}`) + atom.workspace.open( + `atom://config/packages/${event.target.package.name}` + ) } }) } @@ -44,7 +46,10 @@ export default class IncompatiblePackagesComponent { } return ( -
    +
    {this.renderHeading()} {this.renderIncompatiblePackageList()}
    @@ -55,15 +60,14 @@ export default class IncompatiblePackagesComponent { if (this.incompatiblePackages.length > 0) { if (this.rebuiltPackageCount > 0) { let alertClass = - (this.rebuiltPackageCount === this.incompatiblePackages.length) + this.rebuiltPackageCount === this.incompatiblePackages.length ? 'alert-success icon-check' : 'alert-warning icon-bug' return (
    - {this.rebuiltPackageCount} of {this.incompatiblePackages.length} packages - were rebuilt successfully. Reload Atom to activate them. - + {this.rebuiltPackageCount} of {this.incompatiblePackages.length}{' '} + packages were rebuilt successfully. Reload Atom to activate them. @@ -72,10 +76,13 @@ export default class IncompatiblePackagesComponent { } else { return (
    - Some installed packages could not be loaded because they contain native - modules that were compiled for an earlier version of Atom. - -
    @@ -92,9 +99,11 @@ export default class IncompatiblePackagesComponent { renderIncompatiblePackageList () { return ( -
    { - this.incompatiblePackages.map(this.renderIncompatiblePackage.bind(this)) - }
    +
    + {this.incompatiblePackages.map( + this.renderIncompatiblePackage.bind(this) + )} +
    ) } @@ -104,15 +113,18 @@ export default class IncompatiblePackagesComponent { return (
    {this.renderRebuildStatusIndicator(rebuildStatus)} - +

    {pack.name} {pack.metadata.version}

    - { - rebuildStatus + {rebuildStatus ? this.renderRebuildOutput(pack) - : this.renderIncompatibleModules(pack) - } + : this.renderIncompatibleModules(pack)}
    ) } @@ -151,23 +163,23 @@ export default class IncompatiblePackagesComponent { renderIncompatibleModules (pack) { return ( -
      { - pack.incompatibleModules.map((nativeModule) => +
        + {pack.incompatibleModules.map(nativeModule => (
      • - {nativeModule.name}@{nativeModule.version || 'unknown'} – {nativeModule.error} + {nativeModule.name}@{nativeModule.version || 'unknown'} –{' '} + {nativeModule.error}
      • - ) - }
      + ))} +
    ) } populateIncompatiblePackages () { - this.incompatiblePackages = - this.packageManager - .getLoadedPackages() - .filter(pack => !pack.isCompatible()) + this.incompatiblePackages = this.packageManager + .getLoadedPackages() + .filter(pack => !pack.isCompatible()) for (let pack of this.incompatiblePackages) { let buildFailureOutput = pack.getBuildFailureOutput() @@ -186,7 +198,7 @@ export default class IncompatiblePackagesComponent { let rebuiltPackageCount = 0 for (let pack of this.incompatiblePackages) { this.setPackageStatus(pack, REBUILDING) - let {code, stderr} = await pack.rebuild() + let { code, stderr } = await pack.rebuild() if (code === 0) { this.setPackageStatus(pack, REBUILD_SUCCEEDED) rebuiltPackageCount++ @@ -223,6 +235,6 @@ export default class IncompatiblePackagesComponent { } serialize () { - return {deserializer: 'IncompatiblePackagesComponent'} + return { deserializer: 'IncompatiblePackagesComponent' } } } diff --git a/packages/incompatible-packages/lib/main.js b/packages/incompatible-packages/lib/main.js index b936cb880..f66549a7c 100644 --- a/packages/incompatible-packages/lib/main.js +++ b/packages/incompatible-packages/lib/main.js @@ -1,6 +1,6 @@ /** @babel */ -import {Disposable, CompositeDisposable} from 'atom' +import { Disposable, CompositeDisposable } from 'atom' import VIEW_URI from './view-uri' let disposables = null @@ -8,17 +8,21 @@ let disposables = null export function activate () { disposables = new CompositeDisposable() - disposables.add(atom.workspace.addOpener((uri) => { - if (uri === VIEW_URI) { - return deserializeIncompatiblePackagesComponent() - } - })) + disposables.add( + atom.workspace.addOpener(uri => { + if (uri === VIEW_URI) { + return deserializeIncompatiblePackagesComponent() + } + }) + ) - disposables.add(atom.commands.add('atom-workspace', { - 'incompatible-packages:view': () => { - atom.workspace.open(VIEW_URI) - } - })) + disposables.add( + atom.commands.add('atom-workspace', { + 'incompatible-packages:view': () => { + atom.workspace.open(VIEW_URI) + } + }) + ) } export function deactivate () { @@ -33,7 +37,7 @@ export function consumeStatusBar (statusBar) { if (incompatibleCount > 0) { let icon = createIcon(incompatibleCount) - let tile = statusBar.addRightTile({item: icon, priority: 200}) + let tile = statusBar.addRightTile({ item: icon, priority: 200 }) icon.element.addEventListener('click', () => { atom.commands.dispatch(icon.element, 'incompatible-packages:view') }) @@ -48,5 +52,5 @@ export function deserializeIncompatiblePackagesComponent () { function createIcon (count) { const StatusIconComponent = require('./status-icon-component') - return new StatusIconComponent({count}) + return new StatusIconComponent({ count }) } diff --git a/packages/incompatible-packages/lib/status-icon-component.js b/packages/incompatible-packages/lib/status-icon-component.js index 72653ca9b..21cc2a742 100644 --- a/packages/incompatible-packages/lib/status-icon-component.js +++ b/packages/incompatible-packages/lib/status-icon-component.js @@ -4,7 +4,7 @@ import etch from 'etch' export default class StatusIconComponent { - constructor ({count}) { + constructor ({ count }) { this.count = count etch.initialize(this) } @@ -14,7 +14,7 @@ export default class StatusIconComponent { render () { return (
    - + {this.count}
    ) diff --git a/packages/incompatible-packages/spec/incompatible-packages-component-spec.js b/packages/incompatible-packages/spec/incompatible-packages-component-spec.js index 88d46677e..1039cabe5 100644 --- a/packages/incompatible-packages/spec/incompatible-packages-component-spec.js +++ b/packages/incompatible-packages/spec/incompatible-packages-component-spec.js @@ -16,7 +16,7 @@ describe('IncompatiblePackagesComponent', () => { return false }, rebuild: function () { - return new Promise((resolve) => this.resolveRebuild = resolve) + return new Promise(resolve => (this.resolveRebuild = resolve)) }, getBuildFailureOutput () { return null @@ -27,8 +27,8 @@ describe('IncompatiblePackagesComponent', () => { version: '1.0.0' }, incompatibleModules: [ - {name: 'x', version: '1.0.0', error: 'Expected version X, got Y'}, - {name: 'y', version: '1.0.0', error: 'Expected version X, got Z'} + { name: 'x', version: '1.0.0', error: 'Expected version X, got Y' }, + { name: 'y', version: '1.0.0', error: 'Expected version X, got Z' } ] }, { @@ -37,7 +37,7 @@ describe('IncompatiblePackagesComponent', () => { return false }, rebuild () { - return new Promise((resolve) => this.resolveRebuild = resolve) + return new Promise(resolve => (this.resolveRebuild = resolve)) }, getBuildFailureOutput () { return null @@ -48,7 +48,7 @@ describe('IncompatiblePackagesComponent', () => { version: '1.0.0' }, incompatibleModules: [ - {name: 'z', version: '1.0.0', error: 'Expected version X, got Y'} + { name: 'z', version: '1.0.0', error: 'Expected version X, got Y' } ] }, { @@ -67,7 +67,7 @@ describe('IncompatiblePackagesComponent', () => { repository: 'https://github.com/atom/b', version: '1.0.0' }, - incompatibleModules: [], + incompatibleModules: [] } ] }) @@ -75,18 +75,21 @@ describe('IncompatiblePackagesComponent', () => { describe('when packages have not finished loading', () => { it('delays rendering incompatible packages until the end of the tick', () => { waitsForPromise(async () => { - let component = - new IncompatiblePackagesComponent({ - getActivePackages: () => [], - getLoadedPackages: () => packages - }) - let {element} = component + let component = new IncompatiblePackagesComponent({ + getActivePackages: () => [], + getLoadedPackages: () => packages + }) + let { element } = component - expect(element.querySelectorAll('.incompatible-package').length).toEqual(0) + expect( + element.querySelectorAll('.incompatible-package').length + ).toEqual(0) await etchScheduler.getNextUpdatePromise() - expect(element.querySelectorAll('.incompatible-package').length).toBeGreaterThan(0) + expect( + element.querySelectorAll('.incompatible-package').length + ).toBeGreaterThan(0) }) }) }) @@ -97,12 +100,11 @@ describe('IncompatiblePackagesComponent', () => { expect(packages[2].isCompatible()).toBe(true) let compatiblePackages = [packages[2]] - let component = - new IncompatiblePackagesComponent({ - getActivePackages: () => compatiblePackages, - getLoadedPackages: () => compatiblePackages - }) - let {element} = component + let component = new IncompatiblePackagesComponent({ + getActivePackages: () => compatiblePackages, + getLoadedPackages: () => compatiblePackages + }) + let { element } = component await etchScheduler.getNextUpdatePromise() @@ -119,18 +121,23 @@ describe('IncompatiblePackagesComponent', () => { return 'The build failed' } - let component = - new IncompatiblePackagesComponent({ - getActivePackages: () => packages, - getLoadedPackages: () => packages - }) - let {element} = component + let component = new IncompatiblePackagesComponent({ + getActivePackages: () => packages, + getLoadedPackages: () => packages + }) + let { element } = component await etchScheduler.getNextUpdatePromise() - let packageElement = element.querySelector('.incompatible-package:nth-child(2)') + let packageElement = element.querySelector( + '.incompatible-package:nth-child(2)' + ) - expect(packageElement.querySelector('.badge').textContent).toBe('Rebuild Failed') - expect(packageElement.querySelector('pre').textContent).toBe('The build failed') + expect(packageElement.querySelector('.badge').textContent).toBe( + 'Rebuild Failed' + ) + expect(packageElement.querySelector('pre').textContent).toBe( + 'The build failed' + ) }) }) }) @@ -138,75 +145,101 @@ describe('IncompatiblePackagesComponent', () => { describe('when there are incompatible packages', () => { it('renders incompatible packages and the rebuild button', () => { waitsForPromise(async () => { - let component = - new IncompatiblePackagesComponent({ - getActivePackages: () => packages, - getLoadedPackages: () => packages - }) - let {element} = component + let component = new IncompatiblePackagesComponent({ + getActivePackages: () => packages, + getLoadedPackages: () => packages + }) + let { element } = component await etchScheduler.getNextUpdatePromise() - expect(element.querySelectorAll('.incompatible-package').length).toEqual(2) + expect( + element.querySelectorAll('.incompatible-package').length + ).toEqual(2) expect(element.querySelector('button')).not.toBeNull() }) }) describe('when the "Rebuild All" button is clicked', () => { - it('rebuilds every incompatible package, updating each package\'s view with status', () => { + it("rebuilds every incompatible package, updating each package's view with status", () => { waitsForPromise(async () => { - let component = - new IncompatiblePackagesComponent({ - getActivePackages: () => packages, - getLoadedPackages: () => packages - }) - let {element} = component + let component = new IncompatiblePackagesComponent({ + getActivePackages: () => packages, + getLoadedPackages: () => packages + }) + let { element } = component jasmine.attachToDOM(element) await etchScheduler.getNextUpdatePromise() - component.refs.rebuildButton.dispatchEvent(new CustomEvent('click', {bubbles: true})) + component.refs.rebuildButton.dispatchEvent( + new CustomEvent('click', { bubbles: true }) + ) await etchScheduler.getNextUpdatePromise() // view update expect(component.refs.rebuildButton.disabled).toBe(true) expect(packages[0].resolveRebuild).toBeDefined() - expect(element.querySelector('.incompatible-package:nth-child(1) .badge').textContent).toBe('Rebuilding') - expect(element.querySelector('.incompatible-package:nth-child(2) .badge')).toBeNull() + expect( + element.querySelector('.incompatible-package:nth-child(1) .badge') + .textContent + ).toBe('Rebuilding') + expect( + element.querySelector('.incompatible-package:nth-child(2) .badge') + ).toBeNull() - packages[0].resolveRebuild({code: 0}) // simulate rebuild success + packages[0].resolveRebuild({ code: 0 }) // simulate rebuild success await etchScheduler.getNextUpdatePromise() // view update expect(packages[1].resolveRebuild).toBeDefined() - expect(element.querySelector('.incompatible-package:nth-child(1) .badge').textContent).toBe('Rebuild Succeeded') - expect(element.querySelector('.incompatible-package:nth-child(2) .badge').textContent).toBe('Rebuilding') + expect( + element.querySelector('.incompatible-package:nth-child(1) .badge') + .textContent + ).toBe('Rebuild Succeeded') + expect( + element.querySelector('.incompatible-package:nth-child(2) .badge') + .textContent + ).toBe('Rebuilding') - packages[1].resolveRebuild({code: 12, stderr: 'This is an error from the test!'}) // simulate rebuild failure + packages[1].resolveRebuild({ + code: 12, + stderr: 'This is an error from the test!' + }) // simulate rebuild failure await etchScheduler.getNextUpdatePromise() // view update - expect(element.querySelector('.incompatible-package:nth-child(1) .badge').textContent).toBe('Rebuild Succeeded') - expect(element.querySelector('.incompatible-package:nth-child(2) .badge').textContent).toBe('Rebuild Failed') - expect(element.querySelector('.incompatible-package:nth-child(2) pre').textContent).toBe('This is an error from the test!') + expect( + element.querySelector('.incompatible-package:nth-child(1) .badge') + .textContent + ).toBe('Rebuild Succeeded') + expect( + element.querySelector('.incompatible-package:nth-child(2) .badge') + .textContent + ).toBe('Rebuild Failed') + expect( + element.querySelector('.incompatible-package:nth-child(2) pre') + .textContent + ).toBe('This is an error from the test!') }) }) it('displays a prompt to reload Atom when the packages finish rebuilding', () => { waitsForPromise(async () => { - let component = - new IncompatiblePackagesComponent({ - getActivePackages: () => packages, - getLoadedPackages: () => packages - }) - let {element} = component + let component = new IncompatiblePackagesComponent({ + getActivePackages: () => packages, + getLoadedPackages: () => packages + }) + let { element } = component jasmine.attachToDOM(element) await etchScheduler.getNextUpdatePromise() // view update - component.refs.rebuildButton.dispatchEvent(new CustomEvent('click', {bubbles: true})) - expect(packages[0].resolveRebuild({code: 0})) + component.refs.rebuildButton.dispatchEvent( + new CustomEvent('click', { bubbles: true }) + ) + expect(packages[0].resolveRebuild({ code: 0 })) await new Promise(global.setImmediate) - expect(packages[1].resolveRebuild({code: 0})) + expect(packages[1].resolveRebuild({ code: 0 })) await etchScheduler.getNextUpdatePromise() // view update @@ -214,7 +247,9 @@ describe('IncompatiblePackagesComponent', () => { expect(element.querySelector('.alert').textContent).toMatch(/2 of 2/) spyOn(atom, 'reload') - component.refs.reloadButton.dispatchEvent(new CustomEvent('click', {bubbles: true})) + component.refs.reloadButton.dispatchEvent( + new CustomEvent('click', { bubbles: true }) + ) expect(atom.reload).toHaveBeenCalled() }) }) @@ -223,19 +258,22 @@ describe('IncompatiblePackagesComponent', () => { describe('when the "Package Settings" button is clicked', () => { it('opens the settings panel for the package', () => { waitsForPromise(async () => { - let component = - new IncompatiblePackagesComponent({ - getActivePackages: () => packages, - getLoadedPackages: () => packages - }) - let {element} = component + let component = new IncompatiblePackagesComponent({ + getActivePackages: () => packages, + getLoadedPackages: () => packages + }) + let { element } = component jasmine.attachToDOM(element) await etchScheduler.getNextUpdatePromise() spyOn(atom.workspace, 'open') - element.querySelector('.incompatible-package:nth-child(2) button').dispatchEvent(new CustomEvent('click', {bubbles: true})) - expect(atom.workspace.open).toHaveBeenCalledWith('atom://config/packages/incompatible-2') + element + .querySelector('.incompatible-package:nth-child(2) button') + .dispatchEvent(new CustomEvent('click', { bubbles: true })) + expect(atom.workspace.open).toHaveBeenCalledWith( + 'atom://config/packages/incompatible-2' + ) }) }) }) diff --git a/packages/incompatible-packages/spec/incompatible-packages-spec.js b/packages/incompatible-packages/spec/incompatible-packages-spec.js index fa6e7e76a..c4e3587d8 100644 --- a/packages/incompatible-packages/spec/incompatible-packages-spec.js +++ b/packages/incompatible-packages/spec/incompatible-packages-spec.js @@ -36,7 +36,9 @@ describe('Incompatible packages', () => { ) spyOn(incompatiblePackage, 'isCompatible').andReturn(false) incompatiblePackage.incompatibleModules = [] - waitsForPromise(() => atom.packages.activatePackage("incompatible-packages")) + waitsForPromise(() => + atom.packages.activatePackage('incompatible-packages') + ) waits(1) }) @@ -63,13 +65,15 @@ describe('Incompatible packages', () => { describe('when there are no packages with incompatible native modules', () => { beforeEach(() => { - waitsForPromise(() => atom.packages.activatePackage("incompatible-packages")) + waitsForPromise(() => + atom.packages.activatePackage('incompatible-packages') + ) }) it('does not add an icon to the status bar', () => { let statusBarItemClasses = statusBar .getRightTiles() - .map((tile) => tile.getItem().className) + .map(tile => tile.getItem().className) expect(statusBarItemClasses).not.toContain('incompatible-packages') }) diff --git a/packages/line-ending-selector/lib/main.js b/packages/line-ending-selector/lib/main.js index 5945ed24f..74b1d44c0 100644 --- a/packages/line-ending-selector/lib/main.js +++ b/packages/line-ending-selector/lib/main.js @@ -1,7 +1,7 @@ 'use babel' import _ from 'underscore-plus' -import {CompositeDisposable, Disposable} from 'atom' +import { CompositeDisposable, Disposable } from 'atom' import SelectListView from 'atom-select-list' import StatusBarItem from './status-bar-item' import helpers from './helpers' @@ -17,48 +17,60 @@ let lineEndingListView = null export function activate () { disposables = new CompositeDisposable() - disposables.add(atom.commands.add('atom-text-editor', { - 'line-ending-selector:show': (event) => { - if (!modalPanel) { - lineEndingListView = new SelectListView({ - items: [{name: 'LF', value: '\n'}, {name: 'CRLF', value: '\r\n'}], - filterKeyForItem: (lineEnding) => lineEnding.name, - didConfirmSelection: (lineEnding) => { - setLineEnding(atom.workspace.getActiveTextEditor(), lineEnding.value) - modalPanel.hide() - }, - didCancelSelection: () => { - modalPanel.hide() - }, - elementForItem: (lineEnding) => { - const element = document.createElement('li') - element.textContent = lineEnding.name - return element - } - }) - modalPanel = atom.workspace.addModalPanel({item: lineEndingListView}) - disposables.add(new Disposable(() => { - lineEndingListView.destroy() - modalPanel.destroy() - modalPanel = null - })) + disposables.add( + atom.commands.add('atom-text-editor', { + 'line-ending-selector:show': event => { + if (!modalPanel) { + lineEndingListView = new SelectListView({ + items: [ + { name: 'LF', value: '\n' }, + { name: 'CRLF', value: '\r\n' } + ], + filterKeyForItem: lineEnding => lineEnding.name, + didConfirmSelection: lineEnding => { + setLineEnding( + atom.workspace.getActiveTextEditor(), + lineEnding.value + ) + modalPanel.hide() + }, + didCancelSelection: () => { + modalPanel.hide() + }, + elementForItem: lineEnding => { + const element = document.createElement('li') + element.textContent = lineEnding.name + return element + } + }) + modalPanel = atom.workspace.addModalPanel({ + item: lineEndingListView + }) + disposables.add( + new Disposable(() => { + lineEndingListView.destroy() + modalPanel.destroy() + modalPanel = null + }) + ) + } + + lineEndingListView.reset() + modalPanel.show() + lineEndingListView.focus() + }, + + 'line-ending-selector:convert-to-LF': event => { + const editorElement = event.target.closest('atom-text-editor') + setLineEnding(editorElement.getModel(), '\n') + }, + + 'line-ending-selector:convert-to-CRLF': event => { + const editorElement = event.target.closest('atom-text-editor') + setLineEnding(editorElement.getModel(), '\r\n') } - - lineEndingListView.reset() - modalPanel.show() - lineEndingListView.focus() - }, - - 'line-ending-selector:convert-to-LF': (event) => { - const editorElement = event.target.closest('atom-text-editor') - setLineEnding(editorElement.getModel(), '\n') - }, - - 'line-ending-selector:convert-to-CRLF': (event) => { - const editorElement = event.target.closest('atom-text-editor') - setLineEnding(editorElement.getModel(), '\r\n') - } - })) + }) + ) } export function deactivate () { @@ -70,8 +82,8 @@ export function consumeStatusBar (statusBar) { let currentBufferDisposable = null let tooltipDisposable = null - const updateTile = _.debounce((buffer) => { - getLineEndings(buffer).then((lineEndings) => { + const updateTile = _.debounce(buffer => { + getLineEndings(buffer).then(lineEndings => { if (lineEndings.size === 0) { let defaultLineEnding = getDefaultLineEnding() buffer.setPreferredLineEnding(defaultLineEnding) @@ -81,45 +93,49 @@ export function consumeStatusBar (statusBar) { }) }, 0) - disposables.add(atom.workspace.observeActiveTextEditor((editor) => { - if (currentBufferDisposable) currentBufferDisposable.dispose() + disposables.add( + atom.workspace.observeActiveTextEditor(editor => { + if (currentBufferDisposable) currentBufferDisposable.dispose() - if (editor && editor.getBuffer) { - let buffer = editor.getBuffer() - updateTile(buffer) - currentBufferDisposable = buffer.onDidChange(({oldText, newText}) => { - if (!statusBarItem.hasLineEnding('\n')) { - if (newText.indexOf('\n') >= 0) { + if (editor && editor.getBuffer) { + let buffer = editor.getBuffer() + updateTile(buffer) + currentBufferDisposable = buffer.onDidChange(({ oldText, newText }) => { + if (!statusBarItem.hasLineEnding('\n')) { + if (newText.indexOf('\n') >= 0) { + updateTile(buffer) + } + } else if (!statusBarItem.hasLineEnding('\r\n')) { + if (newText.indexOf('\r\n') >= 0) { + updateTile(buffer) + } + } else if (oldText.indexOf('\n')) { updateTile(buffer) } - } else if (!statusBarItem.hasLineEnding('\r\n')) { - if (newText.indexOf('\r\n') >= 0) { - updateTile(buffer) - } - } else if (oldText.indexOf('\n')) { - updateTile(buffer) + }) + } else { + statusBarItem.setLineEndings(new Set()) + currentBufferDisposable = null + } + + if (tooltipDisposable) { + disposables.remove(tooltipDisposable) + tooltipDisposable.dispose() + } + tooltipDisposable = atom.tooltips.add(statusBarItem.element, { + title () { + return `File uses ${statusBarItem.description()} line endings` } }) - } else { - statusBarItem.setLineEndings(new Set()) - currentBufferDisposable = null - } - - if (tooltipDisposable) { - disposables.remove(tooltipDisposable) - tooltipDisposable.dispose() - } - tooltipDisposable = atom.tooltips.add(statusBarItem.element, { - title () { - return `File uses ${statusBarItem.description()} line endings` - } + disposables.add(tooltipDisposable) }) - disposables.add(tooltipDisposable) - })) + ) - disposables.add(new Disposable(() => { - if (currentBufferDisposable) currentBufferDisposable.dispose() - })) + disposables.add( + new Disposable(() => { + if (currentBufferDisposable) currentBufferDisposable.dispose() + }) + ) statusBarItem.onClick(() => { const editor = atom.workspace.getActiveTextEditor() @@ -129,7 +145,7 @@ export function consumeStatusBar (statusBar) { ) }) - let tile = statusBar.addRightTile({item: statusBarItem, priority: 200}) + let tile = statusBar.addRightTile({ item: statusBarItem, priority: 200 }) disposables.add(new Disposable(() => tile.destroy())) } @@ -141,23 +157,22 @@ function getDefaultLineEnding () { return '\r\n' case 'OS Default': default: - return (helpers.getProcessPlatform() === 'win32') ? '\r\n' : '\n' + return helpers.getProcessPlatform() === 'win32' ? '\r\n' : '\n' } } function getLineEndings (buffer) { if (typeof buffer.find === 'function') { - return Promise.all([ - buffer.find(LFRegExp), - buffer.find(CRLFRegExp) - ]).then(([hasLF, hasCRLF]) => { - const result = new Set() - if (hasLF) result.add('\n') - if (hasCRLF) result.add('\r\n') - return result - }) + return Promise.all([buffer.find(LFRegExp), buffer.find(CRLFRegExp)]).then( + ([hasLF, hasCRLF]) => { + const result = new Set() + if (hasLF) result.add('\n') + if (hasCRLF) result.add('\r\n') + return result + } + ) } else { - return new Promise((resolve) => { + return new Promise(resolve => { const result = new Set() for (let i = 0; i < buffer.getLineCount() - 1; i++) { result.add(buffer.lineEndingForRow(i)) diff --git a/packages/line-ending-selector/lib/status-bar-item.js b/packages/line-ending-selector/lib/status-bar-item.js index da2f033c9..1684bc370 100644 --- a/packages/line-ending-selector/lib/status-bar-item.js +++ b/packages/line-ending-selector/lib/status-bar-item.js @@ -1,7 +1,6 @@ -const {Emitter} = require('atom') +const { Emitter } = require('atom') -module.exports = -class StatusBarItem { +module.exports = class StatusBarItem { constructor () { this.element = document.createElement('a') this.element.className = 'line-ending-tile inline-block' @@ -46,9 +45,13 @@ function lineEndingName (lineEndings) { function lineEndingDescription (lineEndings) { switch (lineEndingName(lineEndings)) { - case 'Mixed': return 'mixed' - case 'LF': return 'LF (Unix)' - case 'CRLF': return 'CRLF (Windows)' - default: return 'unknown' + case 'Mixed': + return 'mixed' + case 'LF': + return 'LF (Unix)' + case 'CRLF': + return 'CRLF (Windows)' + default: + return 'unknown' } } diff --git a/packages/line-ending-selector/spec/line-ending-selector-spec.js b/packages/line-ending-selector/spec/line-ending-selector-spec.js index 263f43c62..afc8f9db0 100644 --- a/packages/line-ending-selector/spec/line-ending-selector-spec.js +++ b/packages/line-ending-selector/spec/line-ending-selector-spec.js @@ -1,5 +1,5 @@ const helpers = require('../lib/helpers') -const {TextEditor} = require('atom') +const { TextEditor } = require('atom') describe('line ending selector', () => { let lineEndingTile @@ -30,7 +30,7 @@ describe('line ending selector', () => { beforeEach(() => { waitsForPromise(() => { - return atom.workspace.open('mixed-endings.md').then((e) => { + return atom.workspace.open('mixed-endings.md').then(e => { editor = e editorElement = atom.views.getView(editor) jasmine.attachToDOM(editorElement) @@ -41,7 +41,10 @@ describe('line ending selector', () => { describe('When "line-ending-selector:convert-to-LF" is run', () => { it('converts the file to LF line endings', () => { editorElement.focus() - atom.commands.dispatch(document.activeElement, 'line-ending-selector:convert-to-LF') + atom.commands.dispatch( + document.activeElement, + 'line-ending-selector:convert-to-LF' + ) expect(editor.getText()).toBe('Hello\nGoodbye\nMixed\n') }) }) @@ -49,7 +52,10 @@ describe('line ending selector', () => { describe('When "line-ending-selector:convert-to-LF" is run', () => { it('converts the file to CRLF line endings', () => { editorElement.focus() - atom.commands.dispatch(document.activeElement, 'line-ending-selector:convert-to-CRLF') + atom.commands.dispatch( + document.activeElement, + 'line-ending-selector:convert-to-CRLF' + ) expect(editor.getText()).toBe('Hello\r\nGoodbye\r\nMixed\r\n') }) }) @@ -58,30 +64,34 @@ describe('line ending selector', () => { describe('Status bar tile', () => { describe('when an empty file is opened', () => { it('uses the default line endings for the platform', () => { - waitsFor((done) => { + waitsFor(done => { spyOn(helpers, 'getProcessPlatform').andReturn('win32') - atom.workspace.open('').then((editor) => { + atom.workspace.open('').then(editor => { const subscription = lineEndingTile.onDidChange(() => { subscription.dispose() expect(lineEndingTile.element.textContent).toBe('CRLF') expect(editor.getBuffer().getPreferredLineEnding()).toBe('\r\n') - expect(getTooltipText(lineEndingTile.element)).toBe('File uses CRLF (Windows) line endings') + expect(getTooltipText(lineEndingTile.element)).toBe( + 'File uses CRLF (Windows) line endings' + ) done() }) }) }) - waitsFor((done) => { + waitsFor(done => { helpers.getProcessPlatform.andReturn('darwin') - atom.workspace.open('').then((editor) => { + atom.workspace.open('').then(editor => { const subscription = lineEndingTile.onDidChange(() => { subscription.dispose() expect(lineEndingTile.element.textContent).toBe('LF') expect(editor.getBuffer().getPreferredLineEnding()).toBe('\n') - expect(getTooltipText(lineEndingTile.element)).toBe('File uses LF (Unix) line endings') + expect(getTooltipText(lineEndingTile.element)).toBe( + 'File uses LF (Unix) line endings' + ) done() }) @@ -95,10 +105,10 @@ describe('line ending selector', () => { }) it('uses LF line endings, regardless of the platform', () => { - waitsFor((done) => { + waitsFor(done => { spyOn(helpers, 'getProcessPlatform').andReturn('win32') - atom.workspace.open('').then((editor) => { + atom.workspace.open('').then(editor => { lineEndingTile.onDidChange(() => { expect(lineEndingTile.element.textContent).toBe('LF') expect(editor.getBuffer().getPreferredLineEnding()).toBe('\n') @@ -115,8 +125,8 @@ describe('line ending selector', () => { }) it('uses CRLF line endings, regardless of the platform', () => { - waitsFor((done) => { - atom.workspace.open('').then((editor) => { + waitsFor(done => { + atom.workspace.open('').then(editor => { lineEndingTile.onDidChange(() => { expect(lineEndingTile.element.textContent).toBe('CRLF') expect(editor.getBuffer().getPreferredLineEnding()).toBe('\r\n') @@ -130,7 +140,7 @@ describe('line ending selector', () => { describe('when a file is opened that contains only CRLF line endings', () => { it('displays "CRLF" as the line ending', () => { - waitsFor((done) => { + waitsFor(done => { atom.workspace.open('windows-endings.md').then(() => { lineEndingTile.onDidChange(() => { expect(lineEndingTile.element.textContent).toBe('CRLF') @@ -143,8 +153,8 @@ describe('line ending selector', () => { describe('when a file is opened that contains only LF line endings', () => { it('displays "LF" as the line ending', () => { - waitsFor((done) => { - atom.workspace.open('unix-endings.md').then((editor) => { + waitsFor(done => { + atom.workspace.open('unix-endings.md').then(editor => { lineEndingTile.onDidChange(() => { expect(lineEndingTile.element.textContent).toBe('LF') expect(editor.getBuffer().getPreferredLineEnding()).toBe(null) @@ -157,7 +167,7 @@ describe('line ending selector', () => { describe('when a file is opened that contains mixed line endings', () => { it('displays "Mixed" as the line ending', () => { - waitsFor((done) => { + waitsFor(done => { atom.workspace.open('mixed-endings.md').then(() => { lineEndingTile.onDidChange(() => { expect(lineEndingTile.element.textContent).toBe('Mixed') @@ -174,10 +184,10 @@ describe('line ending selector', () => { beforeEach(() => { jasmine.attachToDOM(atom.views.getView(atom.workspace)) - waitsFor((done) => - atom.workspace.open('unix-endings.md').then(() => - lineEndingTile.onDidChange(done) - ) + waitsFor(done => + atom.workspace + .open('unix-endings.md') + .then(() => lineEndingTile.onDidChange(done)) ) }) @@ -192,7 +202,9 @@ describe('line ending selector', () => { lineEndingSelector = lineEndingModal.getItem() expect(lineEndingModal.isVisible()).toBe(true) - expect(lineEndingSelector.element.contains(document.activeElement)).toBe(true) + expect( + lineEndingSelector.element.contains(document.activeElement) + ).toBe(true) let listItems = lineEndingSelector.element.querySelectorAll('li') expect(listItems[0].textContent).toBe('LF') expect(listItems[1].textContent).toBe('CRLF') @@ -210,7 +222,9 @@ describe('line ending selector', () => { lineEndingSelector = lineEndingModal.getItem() expect(lineEndingModal.isVisible()).toBe(true) - expect(lineEndingSelector.element.contains(document.activeElement)).toBe(true) + expect( + lineEndingSelector.element.contains(document.activeElement) + ).toBe(true) let listItems = lineEndingSelector.element.querySelectorAll('li') expect(listItems[0].textContent).toBe('LF') expect(listItems[1].textContent).toBe('CRLF') @@ -264,12 +278,12 @@ describe('line ending selector', () => { }) }) - describe('when the buffer\'s line endings change', () => { + describe("when the buffer's line endings change", () => { let editor beforeEach(() => { - waitsFor((done) => { - atom.workspace.open('unix-endings.md').then((e) => { + waitsFor(done => { + atom.workspace.open('unix-endings.md').then(e => { editor = e lineEndingTile.onDidChange(done) }) @@ -291,33 +305,47 @@ describe('line ending selector', () => { }) expect(lineEndingTile.element.textContent).toBe('LF') - expect(getTooltipText(lineEndingTile.element)).toBe('File uses LF (Unix) line endings') + expect(getTooltipText(lineEndingTile.element)).toBe( + 'File uses LF (Unix) line endings' + ) - waitsFor((done) => { + waitsFor(done => { editor.setTextInBufferRange([[0, 0], [0, 0]], '... ') - editor.setTextInBufferRange([[0, Infinity], [1, 0]], '\r\n', {normalizeLineEndings: false}) + editor.setTextInBufferRange([[0, Infinity], [1, 0]], '\r\n', { + normalizeLineEndings: false + }) lineEndingTile.onDidChange(done) }) runs(() => { expect(tileUpdateCount).toBe(1) expect(lineEndingTile.element.textContent).toBe('Mixed') - expect(getTooltipText(lineEndingTile.element)).toBe('File uses mixed line endings') + expect(getTooltipText(lineEndingTile.element)).toBe( + 'File uses mixed line endings' + ) }) - waitsFor((done) => { - atom.commands.dispatch(editor.getElement(), 'line-ending-selector:convert-to-CRLF') + waitsFor(done => { + atom.commands.dispatch( + editor.getElement(), + 'line-ending-selector:convert-to-CRLF' + ) lineEndingTile.onDidChange(done) }) runs(() => { expect(tileUpdateCount).toBe(2) expect(lineEndingTile.element.textContent).toBe('CRLF') - expect(getTooltipText(lineEndingTile.element)).toBe('File uses CRLF (Windows) line endings') + expect(getTooltipText(lineEndingTile.element)).toBe( + 'File uses CRLF (Windows) line endings' + ) }) - waitsFor((done) => { - atom.commands.dispatch(editor.getElement(), 'line-ending-selector:convert-to-LF') + waitsFor(done => { + atom.commands.dispatch( + editor.getElement(), + 'line-ending-selector:convert-to-LF' + ) lineEndingTile.onDidChange(done) }) diff --git a/packages/link/lib/link.js b/packages/link/lib/link.js index 4b2443cfb..c7add2f63 100644 --- a/packages/link/lib/link.js +++ b/packages/link/lib/link.js @@ -1,12 +1,16 @@ const url = require('url') -const {shell} = require('electron') +const { shell } = require('electron') const _ = require('underscore-plus') const LINK_SCOPE_REGEX = /markup\.underline\.link/ module.exports = { activate () { - this.commandDisposable = atom.commands.add('atom-text-editor', 'link:open', () => this.openLink()) + this.commandDisposable = atom.commands.add( + 'atom-text-editor', + 'link:open', + () => this.openLink() + ) }, deactivate () { @@ -24,8 +28,9 @@ module.exports = { link = this.linkForName(editor, link) } - const {protocol} = url.parse(link) - if (protocol === 'http:' || protocol === 'https:' || protocol === 'atom:') shell.openExternal(link) + const { protocol } = url.parse(link) + if (protocol === 'http:' || protocol === 'https:' || protocol === 'atom:') + shell.openExternal(link) }, // Get the link under the cursor in the editor @@ -47,7 +52,11 @@ module.exports = { // Returns a {String} link or undefined if no link found. linkAtPosition (editor, bufferPosition) { const token = editor.tokenForBufferPosition(bufferPosition) - if (token && token.value && token.scopes.some(scope => LINK_SCOPE_REGEX.test(scope))) { + if ( + token && + token.value && + token.scopes.some(scope => LINK_SCOPE_REGEX.test(scope)) + ) { return token.value } }, @@ -65,11 +74,18 @@ module.exports = { // Returns a {String} link linkForName (editor, linkName) { let link = linkName - const regex = new RegExp(`^\\s*\\[${_.escapeRegExp(linkName)}\\]\\s*:\\s*(.+)$`, 'g') - editor.backwardsScanInBufferRange(regex, [[0, 0], [Infinity, Infinity]], ({match, stop}) => { - link = match[1] - stop() - }) + const regex = new RegExp( + `^\\s*\\[${_.escapeRegExp(linkName)}\\]\\s*:\\s*(.+)$`, + 'g' + ) + editor.backwardsScanInBufferRange( + regex, + [[0, 0], [Infinity, Infinity]], + ({ match, stop }) => { + link = match[1] + stop() + } + ) return link } } diff --git a/packages/link/spec/async-spec-helpers.js b/packages/link/spec/async-spec-helpers.js index 73002c049..5a233973e 100644 --- a/packages/link/spec/async-spec-helpers.js +++ b/packages/link/spec/async-spec-helpers.js @@ -18,7 +18,7 @@ export function afterEach (fn) { }) } -['it', 'fit', 'ffit', 'fffit'].forEach(function (name) { +;['it', 'fit', 'ffit', 'fffit'].forEach(function (name) { module.exports[name] = function (description, fn) { if (fn === undefined) { global[name](description) @@ -34,7 +34,10 @@ export function afterEach (fn) { } }) -export async function conditionPromise (condition, description = 'anonymous condition') { +export async function conditionPromise ( + condition, + description = 'anonymous condition' +) { const startTime = Date.now() while (true) { diff --git a/packages/link/spec/link-spec.js b/packages/link/spec/link-spec.js index 976261cd4..0c0b817a2 100644 --- a/packages/link/spec/link-spec.js +++ b/packages/link/spec/link-spec.js @@ -1,6 +1,6 @@ -const {shell} = require('electron') +const { shell } = require('electron') -const {it, fit, ffit, afterEach, beforeEach} = require('./async-spec-helpers') // eslint-disable-line no-unused-vars +const { it, fit, ffit, afterEach, beforeEach } = require('./async-spec-helpers') // eslint-disable-line no-unused-vars describe('link package', () => { beforeEach(async () => { @@ -47,13 +47,15 @@ describe('link package', () => { // only works in Atom >= 1.33.0 // https://github.com/atom/link/pull/33#issuecomment-419643655 const atomVersion = atom.getVersion().split('.') - console.error("atomVersion", atomVersion) + console.error('atomVersion', atomVersion) if (+atomVersion[0] > 1 || +atomVersion[1] >= 33) { it("opens an 'atom:' link", async () => { await atom.workspace.open('sample.md') const editor = atom.workspace.getActiveTextEditor() - editor.setText('// "atom://core/open/file?filename=sample.js&line=1&column=2"') + editor.setText( + '// "atom://core/open/file?filename=sample.js&line=1&column=2"' + ) spyOn(shell, 'openExternal') atom.commands.dispatch(atom.views.getView(editor), 'link:open') @@ -63,21 +65,27 @@ describe('link package', () => { atom.commands.dispatch(atom.views.getView(editor), 'link:open') expect(shell.openExternal).toHaveBeenCalled() - expect(shell.openExternal.argsForCall[0][0]).toBe('atom://core/open/file?filename=sample.js&line=1&column=2') + expect(shell.openExternal.argsForCall[0][0]).toBe( + 'atom://core/open/file?filename=sample.js&line=1&column=2' + ) shell.openExternal.reset() editor.setCursorBufferPosition([0, 8]) atom.commands.dispatch(atom.views.getView(editor), 'link:open') expect(shell.openExternal).toHaveBeenCalled() - expect(shell.openExternal.argsForCall[0][0]).toBe('atom://core/open/file?filename=sample.js&line=1&column=2') + expect(shell.openExternal.argsForCall[0][0]).toBe( + 'atom://core/open/file?filename=sample.js&line=1&column=2' + ) shell.openExternal.reset() editor.setCursorBufferPosition([0, 60]) atom.commands.dispatch(atom.views.getView(editor), 'link:open') expect(shell.openExternal).toHaveBeenCalled() - expect(shell.openExternal.argsForCall[0][0]).toBe('atom://core/open/file?filename=sample.js&line=1&column=2') + expect(shell.openExternal.argsForCall[0][0]).toBe( + 'atom://core/open/file?filename=sample.js&line=1&column=2' + ) }) } @@ -91,8 +99,7 @@ you should [click][here] you should not [click][her] [here]: http://github.com\ -` - ) +`) spyOn(shell, 'openExternal') editor.setCursorBufferPosition([0, 0]) @@ -110,8 +117,7 @@ you should not [click][her] atom.commands.dispatch(atom.views.getView(editor), 'link:open') expect(shell.openExternal).not.toHaveBeenCalled() - }) - ) + })) it('does not open non http/https/atom links', async () => { await atom.workspace.open('sample.md') diff --git a/packages/one-dark-ui/spec/theme-spec.js b/packages/one-dark-ui/spec/theme-spec.js index 5ff5aa3db..a43ea4f7c 100644 --- a/packages/one-dark-ui/spec/theme-spec.js +++ b/packages/one-dark-ui/spec/theme-spec.js @@ -14,31 +14,45 @@ describe(`${themeName} theme`, () => { it('allows the tab sizing to be set via config', () => { atom.config.set(`${themeName}.tabSizing`, 'Maximum') - expect(document.documentElement.getAttribute(`theme-${themeName}-tabsizing`)).toBe('maximum') + expect( + document.documentElement.getAttribute(`theme-${themeName}-tabsizing`) + ).toBe('maximum') }) it('allows the tab sizing to be set via config', () => { atom.config.set(`${themeName}.tabSizing`, 'Minimum') - expect(document.documentElement.getAttribute(`theme-${themeName}-tabsizing`)).toBe('minimum') + expect( + document.documentElement.getAttribute(`theme-${themeName}-tabsizing`) + ).toBe('minimum') }) it('allows the tab close button to be shown on the left via config', () => { atom.config.set(`${themeName}.tabCloseButton`, 'Left') - expect(document.documentElement.getAttribute(`theme-${themeName}-tab-close-button`)).toBe('left') + expect( + document.documentElement.getAttribute( + `theme-${themeName}-tab-close-button` + ) + ).toBe('left') }) it('allows the dock toggle buttons to be hidden via config', () => { atom.config.set(`${themeName}.hideDockButtons`, true) - expect(document.documentElement.getAttribute(`theme-${themeName}-dock-buttons`)).toBe('hidden') + expect( + document.documentElement.getAttribute(`theme-${themeName}-dock-buttons`) + ).toBe('hidden') }) it('allows the tree-view headers to be sticky via config', () => { atom.config.set(`${themeName}.stickyHeaders`, true) - expect(document.documentElement.getAttribute(`theme-${themeName}-sticky-headers`)).toBe('sticky') + expect( + document.documentElement.getAttribute(`theme-${themeName}-sticky-headers`) + ).toBe('sticky') }) it('allows the tree-view headers to not be sticky via config', () => { atom.config.set(`${themeName}.stickyHeaders`, false) - expect(document.documentElement.getAttribute(`theme-${themeName}-sticky-headers`)).toBe(null) + expect( + document.documentElement.getAttribute(`theme-${themeName}-sticky-headers`) + ).toBe(null) }) }) diff --git a/packages/one-light-ui/spec/theme-spec.js b/packages/one-light-ui/spec/theme-spec.js index a0e72875b..862d2ef5e 100644 --- a/packages/one-light-ui/spec/theme-spec.js +++ b/packages/one-light-ui/spec/theme-spec.js @@ -14,31 +14,45 @@ describe(`${themeName} theme`, () => { it('allows the tab sizing to be set via config', () => { atom.config.set(`${themeName}.tabSizing`, 'Maximum') - expect(document.documentElement.getAttribute(`theme-${themeName}-tabsizing`)).toBe('maximum') + expect( + document.documentElement.getAttribute(`theme-${themeName}-tabsizing`) + ).toBe('maximum') }) it('allows the tab sizing to be set via config', () => { atom.config.set(`${themeName}.tabSizing`, 'Minimum') - expect(document.documentElement.getAttribute(`theme-${themeName}-tabsizing`)).toBe('minimum') + expect( + document.documentElement.getAttribute(`theme-${themeName}-tabsizing`) + ).toBe('minimum') }) it('allows the tab close button to be shown on the left via config', () => { atom.config.set(`${themeName}.tabCloseButton`, 'Left') - expect(document.documentElement.getAttribute(`theme-${themeName}-tab-close-button`)).toBe('left') + expect( + document.documentElement.getAttribute( + `theme-${themeName}-tab-close-button` + ) + ).toBe('left') }) it('allows the dock toggle buttons to be hidden via config', () => { atom.config.set(`${themeName}.hideDockButtons`, true) - expect(document.documentElement.getAttribute(`theme-${themeName}-dock-buttons`)).toBe('hidden') + expect( + document.documentElement.getAttribute(`theme-${themeName}-dock-buttons`) + ).toBe('hidden') }) it('allows the tree-view headers to be sticky via config', () => { atom.config.set(`${themeName}.stickyHeaders`, true) - expect(document.documentElement.getAttribute(`theme-${themeName}-sticky-headers`)).toBe('sticky') + expect( + document.documentElement.getAttribute(`theme-${themeName}-sticky-headers`) + ).toBe('sticky') }) it('allows the tree-view headers to not be sticky via config', () => { atom.config.set(`${themeName}.stickyHeaders`, false) - expect(document.documentElement.getAttribute(`theme-${themeName}-sticky-headers`)).toBe(null) + expect( + document.documentElement.getAttribute(`theme-${themeName}-sticky-headers`) + ).toBe(null) }) }) From f6db819485e53a18df11be38c08286aa70d26932 Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Thu, 21 Feb 2019 15:05:44 +0100 Subject: [PATCH 3/9] Remove unused variables from specs --- packages/about/spec/about-spec.js | 9 +-------- packages/about/spec/about-status-bar-spec.js | 5 +---- packages/about/spec/update-view-spec.js | 9 +-------- packages/dev-live-reload/spec/ui-watcher-spec.js | 4 +--- 4 files changed, 4 insertions(+), 23 deletions(-) diff --git a/packages/about/spec/about-spec.js b/packages/about/spec/about-spec.js index a991457ff..f3352e806 100644 --- a/packages/about/spec/about-spec.js +++ b/packages/about/spec/about-spec.js @@ -1,11 +1,4 @@ -const { - it, - fit, - ffit, - fffit, - beforeEach, - afterEach -} = require('./helpers/async-spec-helpers') // eslint-disable-line no-unused-vars +const { it, beforeEach } = require('./helpers/async-spec-helpers') describe('About', () => { let workspaceElement diff --git a/packages/about/spec/about-status-bar-spec.js b/packages/about/spec/about-status-bar-spec.js index 99de30010..4190674df 100644 --- a/packages/about/spec/about-status-bar-spec.js +++ b/packages/about/spec/about-status-bar-spec.js @@ -1,12 +1,9 @@ const { it, - fit, - ffit, - fffit, beforeEach, afterEach, conditionPromise -} = require('./helpers/async-spec-helpers') // eslint-disable-line no-unused-vars +} = require('./helpers/async-spec-helpers') const MockUpdater = require('./mocks/updater') describe('the status bar', () => { diff --git a/packages/about/spec/update-view-spec.js b/packages/about/spec/update-view-spec.js index fdb9a02b4..2f593b5bd 100644 --- a/packages/about/spec/update-view-spec.js +++ b/packages/about/spec/update-view-spec.js @@ -1,12 +1,5 @@ const { shell } = require('electron') -const { - it, - fit, - ffit, - fffit, - beforeEach, - afterEach -} = require('./helpers/async-spec-helpers') // eslint-disable-line no-unused-vars +const { it, beforeEach, afterEach } = require('./helpers/async-spec-helpers') const main = require('../lib/main') const AboutView = require('../lib/components/about-view') const UpdateView = require('../lib/components/update-view') diff --git a/packages/dev-live-reload/spec/ui-watcher-spec.js b/packages/dev-live-reload/spec/ui-watcher-spec.js index 0730619d8..a8dd6e86d 100644 --- a/packages/dev-live-reload/spec/ui-watcher-spec.js +++ b/packages/dev-live-reload/spec/ui-watcher-spec.js @@ -4,12 +4,10 @@ const UIWatcher = require('../lib/ui-watcher') const { it, - fit, - ffit, afterEach, beforeEach, conditionPromise -} = require('./async-spec-helpers') // eslint-disable-line no-unused-vars +} = require('./async-spec-helpers') describe('UIWatcher', () => { let uiWatcher = null From 11206eca7659fb865c81e69c6510468461cf808d Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Thu, 21 Feb 2019 15:08:30 +0100 Subject: [PATCH 4/9] Add curly braces around if statements --- packages/dev-live-reload/lib/package-watcher.js | 3 ++- packages/dev-live-reload/lib/ui-watcher.js | 13 +++++++++---- packages/dev-live-reload/spec/ui-watcher-spec.js | 4 +--- packages/link/lib/link.js | 3 ++- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/dev-live-reload/lib/package-watcher.js b/packages/dev-live-reload/lib/package-watcher.js index a5be2337c..2cb8096dd 100644 --- a/packages/dev-live-reload/lib/package-watcher.js +++ b/packages/dev-live-reload/lib/package-watcher.js @@ -23,8 +23,9 @@ module.exports = class PackageWatcher extends Watcher { const stylesheetsPath = this.pack.getStylesheetsPath() - if (fs.isDirectorySync(stylesheetsPath)) + if (fs.isDirectorySync(stylesheetsPath)) { this.watchDirectory(stylesheetsPath) + } const stylesheetPaths = new Set(this.pack.getStylesheetPaths()) const onFile = stylesheetPath => stylesheetPaths.add(stylesheetPath) diff --git a/packages/dev-live-reload/lib/ui-watcher.js b/packages/dev-live-reload/lib/ui-watcher.js index 9aa3eefde..eb5ac2635 100644 --- a/packages/dev-live-reload/lib/ui-watcher.js +++ b/packages/dev-live-reload/lib/ui-watcher.js @@ -57,19 +57,21 @@ module.exports = class UIWatcher { } watchTheme (theme) { - if (PackageWatcher.supportsPackage(theme, 'theme')) + if (PackageWatcher.supportsPackage(theme, 'theme')) { this.watchedThemes.set( theme.name, this.createWatcher(new PackageWatcher(theme)) ) + } } watchPackage (pack) { - if (PackageWatcher.supportsPackage(pack, 'atom')) + if (PackageWatcher.supportsPackage(pack, 'atom')) { this.watchedPackages.set( pack.name, this.createWatcher(new PackageWatcher(pack)) ) + } } createWatcher (watcher) { @@ -87,12 +89,15 @@ module.exports = class UIWatcher { reloadAll () { this.baseTheme.loadAllStylesheets() for (const pack of atom.packages.getActivePackages()) { - if (PackageWatcher.supportsPackage(pack, 'atom')) pack.reloadStylesheets() + if (PackageWatcher.supportsPackage(pack, 'atom')) { + pack.reloadStylesheets() + } } for (const theme of atom.themes.getActiveThemes()) { - if (PackageWatcher.supportsPackage(theme, 'theme')) + if (PackageWatcher.supportsPackage(theme, 'theme')) { theme.reloadStylesheets() + } } } diff --git a/packages/dev-live-reload/spec/ui-watcher-spec.js b/packages/dev-live-reload/spec/ui-watcher-spec.js index a8dd6e86d..ffce8034c 100644 --- a/packages/dev-live-reload/spec/ui-watcher-spec.js +++ b/packages/dev-live-reload/spec/ui-watcher-spec.js @@ -77,9 +77,7 @@ describe('UIWatcher', () => { const pack = atom.packages.getActivePackages()[0] spyOn(pack, 'reloadStylesheets') - uiWatcher.watchers[ - uiWatcher.watchers.length - 1 - ].entities[1].emitter.emit('did-change') + uiWatcher.watchers[uiWatcher.watchers.length - 1].entities[1].emitter.emit('did-change') expect(pack.reloadStylesheets).toHaveBeenCalled() }) diff --git a/packages/link/lib/link.js b/packages/link/lib/link.js index c7add2f63..005c9e614 100644 --- a/packages/link/lib/link.js +++ b/packages/link/lib/link.js @@ -29,8 +29,9 @@ module.exports = { } const { protocol } = url.parse(link) - if (protocol === 'http:' || protocol === 'https:' || protocol === 'atom:') + if (protocol === 'http:' || protocol === 'https:' || protocol === 'atom:') { shell.openExternal(link) + } }, // Get the link under the cursor in the editor From e734434811796adfc61cf1e917ee5930b456c9c8 Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Mon, 25 Feb 2019 12:48:41 +0100 Subject: [PATCH 5/9] Small linter fixes --- packages/exception-reporting/lib/reporter.js | 1 - .../incompatible-packages/lib/incompatible-packages-component.js | 1 - 2 files changed, 2 deletions(-) diff --git a/packages/exception-reporting/lib/reporter.js b/packages/exception-reporting/lib/reporter.js index a702134a1..e4becff04 100644 --- a/packages/exception-reporting/lib/reporter.js +++ b/packages/exception-reporting/lib/reporter.js @@ -1,6 +1,5 @@ /** @babel */ -import _ from 'underscore-plus' import os from 'os' import stackTrace from 'stack-trace' import fs from 'fs-plus' diff --git a/packages/incompatible-packages/lib/incompatible-packages-component.js b/packages/incompatible-packages/lib/incompatible-packages-component.js index 0f7bd263c..478e9682d 100644 --- a/packages/incompatible-packages/lib/incompatible-packages-component.js +++ b/packages/incompatible-packages/lib/incompatible-packages-component.js @@ -1,7 +1,6 @@ /** @babel */ /** @jsx etch.dom */ -import { BufferedProcess } from 'atom' import etch from 'etch' import VIEW_URI from './view-uri' From 20ec642da1779f86695f0955b16bbbfbf3f486a5 Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Mon, 25 Feb 2019 12:27:10 +0100 Subject: [PATCH 6/9] Lint fixture file from git-diff package --- packages/git-diff/spec/diff-list-view-spec.js | 6 ++-- .../working-dir/git.git/COMMIT_EDITMSG | 0 .../fixtures/working-dir/git.git/MERGE_RR | 0 .../spec/fixtures/working-dir/git.git/index | Bin 217 -> 217 bytes .../fixtures/working-dir/git.git/info/refs | 1 + .../fixtures/working-dir/git.git/logs/HEAD | 0 .../git.git/logs/refs/heads/master | 0 .../3e/715502b971d4f8282d1e05a8ccfad6f7037910 | Bin 27 -> 0 bytes .../90/820108a054b6f49c0d21031313244b6f7d69dc | 3 -- .../f1/4149b7b38a0a972c46557877caff6c9fe76476 | Bin 81 -> 0 bytes .../fb/33b0b43b20b7f9de1bca79e192fa2e30dbeb6b | Bin 227 -> 0 bytes .../working-dir/git.git/objects/info/packs | 2 ++ ...30b46ead026befe94c88f5591a6d3dfdca4e95.idx | Bin 0 -> 1380 bytes ...0b46ead026befe94c88f5591a6d3dfdca4e95.pack | Bin 0 -> 1127 bytes .../fixtures/working-dir/git.git/packed-refs | 2 ++ .../working-dir/git.git/refs/heads/master | 1 - .../spec/fixtures/working-dir/sample.js | 30 +++++++++++------- packages/git-diff/spec/git-diff-spec.js | 16 +++++----- 18 files changed, 34 insertions(+), 27 deletions(-) create mode 100644 packages/git-diff/spec/fixtures/working-dir/git.git/COMMIT_EDITMSG create mode 100644 packages/git-diff/spec/fixtures/working-dir/git.git/MERGE_RR create mode 100644 packages/git-diff/spec/fixtures/working-dir/git.git/info/refs create mode 100644 packages/git-diff/spec/fixtures/working-dir/git.git/logs/HEAD create mode 100644 packages/git-diff/spec/fixtures/working-dir/git.git/logs/refs/heads/master delete mode 100644 packages/git-diff/spec/fixtures/working-dir/git.git/objects/3e/715502b971d4f8282d1e05a8ccfad6f7037910 delete mode 100644 packages/git-diff/spec/fixtures/working-dir/git.git/objects/90/820108a054b6f49c0d21031313244b6f7d69dc delete mode 100644 packages/git-diff/spec/fixtures/working-dir/git.git/objects/f1/4149b7b38a0a972c46557877caff6c9fe76476 delete mode 100644 packages/git-diff/spec/fixtures/working-dir/git.git/objects/fb/33b0b43b20b7f9de1bca79e192fa2e30dbeb6b create mode 100644 packages/git-diff/spec/fixtures/working-dir/git.git/objects/info/packs create mode 100644 packages/git-diff/spec/fixtures/working-dir/git.git/objects/pack/pack-fb30b46ead026befe94c88f5591a6d3dfdca4e95.idx create mode 100644 packages/git-diff/spec/fixtures/working-dir/git.git/objects/pack/pack-fb30b46ead026befe94c88f5591a6d3dfdca4e95.pack create mode 100644 packages/git-diff/spec/fixtures/working-dir/git.git/packed-refs delete mode 100644 packages/git-diff/spec/fixtures/working-dir/git.git/refs/heads/master diff --git a/packages/git-diff/spec/diff-list-view-spec.js b/packages/git-diff/spec/diff-list-view-spec.js index 5fba8eba1..d78560acc 100644 --- a/packages/git-diff/spec/diff-list-view-spec.js +++ b/packages/git-diff/spec/diff-list-view-spec.js @@ -22,7 +22,7 @@ describe('git-diff:toggle-diff-list', () => { runs(() => { editor = atom.workspace.getActiveTextEditor() - editor.setCursorBufferPosition([4, 29]) + editor.setCursorBufferPosition([3, 28]) editor.insertText('a') atom.commands.dispatch(editor.getElement(), 'git-diff:toggle-diff-list') }) @@ -35,7 +35,7 @@ describe('git-diff:toggle-diff-list', () => { it('shows a list of all diff hunks', () => { diffListView = document.querySelector('.diff-list-view ol') - expect(diffListView.textContent).toBe('while(items.length > 0) {a-5,1 +5,1') + expect(diffListView.textContent).toBe('var pivot = items.shift(a)-4,1 +4,1') }) it('moves the cursor to the selected hunk', () => { @@ -44,6 +44,6 @@ describe('git-diff:toggle-diff-list', () => { document.querySelector('.diff-list-view'), 'core:confirm' ) - expect(editor.getCursorBufferPosition()).toEqual([4, 4]) + expect(editor.getCursorBufferPosition()).toEqual([3, 4]) }) }) diff --git a/packages/git-diff/spec/fixtures/working-dir/git.git/COMMIT_EDITMSG b/packages/git-diff/spec/fixtures/working-dir/git.git/COMMIT_EDITMSG new file mode 100644 index 000000000..e69de29bb diff --git a/packages/git-diff/spec/fixtures/working-dir/git.git/MERGE_RR b/packages/git-diff/spec/fixtures/working-dir/git.git/MERGE_RR new file mode 100644 index 000000000..e69de29bb diff --git a/packages/git-diff/spec/fixtures/working-dir/git.git/index b/packages/git-diff/spec/fixtures/working-dir/git.git/index index 7b94a97970cb53622608d2c0240f383c89e74d4e..17dcc2005c6d34768d09f5f9580968af969fd734 100644 GIT binary patch delta 176 zcmcb~c$2Z-#WTp6fq{Vugky@YO;A~v!VaSu85md@;>4R77#f!_Ffe`vsu2Owho1k9 zW{o|&YVz9txyh$`w;HpW3&b;U7ANKwr6>y0$}R_iss?tRs`mLt=r+F+en)Q>rRrQ4L&#tM~%e$ZpS{3Wd7fYjoE FDFA_iI(`5E delta 176 zcmcb~c$2Z-#WTp6fq{VugoDBbwShDPjAmqDU|~^GE@NP5T*AP>_!TH60;FgBHr}ws zT4DRod(x*WA5QwEXK?#AWiT`_Ff%bxC{D~R$Vt`9DrWd?ykU#A!uFr{q)$~oob*f2 n;P&fmR7E8fB@A|jp-ejqul&%^m1A9T=GV3F%#{KFDZn9!hz}*T diff --git a/packages/git-diff/spec/fixtures/working-dir/git.git/objects/fb/33b0b43b20b7f9de1bca79e192fa2e30dbeb6b b/packages/git-diff/spec/fixtures/working-dir/git.git/objects/fb/33b0b43b20b7f9de1bca79e192fa2e30dbeb6b deleted file mode 100644 index e9ffee6407bbb200388e6ccbecf97457892a94e9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 227 zcmV<90382#0bNkbP6Htnb=|KxOGqZ9OmjwG%cPIItCLU@jpTP(vxu>8wO-@v-dBxlIWm2!4c3W8{g~4?p^1@WLCCf* zb9fb*g@skT^J_EjtlV%oX`@Wvo~b2E(@oNre1Ev#@aX#W=QB?1V*lf8=Djo1`Rv@K zJ6k3{{~OI3dv?|2wf%FGPxWp!W;GXx|LEwseRCJrbRDQ4 zxZ7T-V`(Q_ws=00y!`UF@rEtd3fq6)lRj1XaMCY5gWIpOZT?98e{WFD6cP}xQoE+* zek*tO*~S&ir52h53TziV^il4`13jJIEqnz+0&{`cYc{Yr0EG_^ki8zrHUMTLcOd&W zki84YZUoA00MciF8*Is2%ar~8rBBD#NU2=gzo-1Bx@O6&*vWDE=!E@FAHr_=dGV}zx*WUY&swrE}GOGZ--2d3<%)5qLB zq8!)X+VXReqUHQW3-;PgQ_7#xsa`qvhwrBdjp8MrYuEJKmK4tP4~krUKsvqGW{W|G z+w+ZK|88$R_V~Q$^o_N5GUC+V&71v$L2|Y8{r4;lDiw38&-|DXxP6I+X{e&1uA#2w z*)vKvl{7CNu+hDFP3^2mku4dRI%t?j3>7hZF=H9@;LS!F|Jl+t|dgcU^2%lP2rYY1c&lSniV&=6~?1x;s4V zy`sk2lH0-eBc|O6dTS!(Jncjw$BSDJI87Hmh_=+%mic3QuHcD#Npj2EABq36%DrTk zpVD2)d^I99%Vo=ki7HDgu8Vko{4al`PC}u0m*2i!DGz=w|D^MXb@ytA*_&i4=HyQB z%{#0h(E8o-sE*^RfX!!WZrcB84 zYob91ChM=*X(#nY=<({+Mia|2YoqT@ebj$=mB6=Uo}t##TYf426P-8xVuIs8>B{2r z+zs2MG@bg|O#2U?p7SeuZNtWSxfefquGykruy9YX(Z;Sik?hi^pOSi0=T={^p16lg zvT5(86a%})C3gJ5C3B>Xo#mguwl~bWVh;DY^S+@Po@+HOK4xN&P-5P+nx$fnv5A3! zv0xz6rB(bhpJn>(&8m~xzn`nke|0zOOqQNNe#fE}OBS^pTxT#PGyUOI zd8u7RYqZb(+4XJi&L9Q`m1 z#6Q$-&KK|V55B$5!Rw0BLV2GToXx@@SJ*T|U9tb4OSQAx>rU39TUJ~rm%6&HtW>q) zg1g0v%XQ{UNr7#q)0qUOq^CSv;%Ae8B*S**#ETb2l_I#+x`VvEx<83@eeU)$aZt;6 zrTYB2s`|7Hk(6mql`9e|H*B0WOX2O-Ym?OtUu}vgz8b~Mux_!Q?QerEd25-n-@o+f O_!=pdYy0<<-&6o5ToB9v literal 0 HcmV?d00001 diff --git a/packages/git-diff/spec/fixtures/working-dir/git.git/packed-refs b/packages/git-diff/spec/fixtures/working-dir/git.git/packed-refs new file mode 100644 index 000000000..1a97c394d --- /dev/null +++ b/packages/git-diff/spec/fixtures/working-dir/git.git/packed-refs @@ -0,0 +1,2 @@ +# pack-refs with: peeled fully-peeled sorted +745ed7547d15a61bc4ee7e182615590f44aca201 refs/heads/master diff --git a/packages/git-diff/spec/fixtures/working-dir/git.git/refs/heads/master b/packages/git-diff/spec/fixtures/working-dir/git.git/refs/heads/master deleted file mode 100644 index 40efdd18b..000000000 --- a/packages/git-diff/spec/fixtures/working-dir/git.git/refs/heads/master +++ /dev/null @@ -1 +0,0 @@ -90820108a054b6f49c0d21031313244b6f7d69dc diff --git a/packages/git-diff/spec/fixtures/working-dir/sample.js b/packages/git-diff/spec/fixtures/working-dir/sample.js index fb33b0b43..e7fd5b055 100644 --- a/packages/git-diff/spec/fixtures/working-dir/sample.js +++ b/packages/git-diff/spec/fixtures/working-dir/sample.js @@ -1,13 +1,19 @@ -var quicksort = function () { - var sort = function(items) { - if (items.length <= 1) return items; - var pivot = items.shift(), current, left = [], right = []; - while(items.length > 0) { - current = items.shift(); - current < pivot ? left.push(current) : right.push(current); - } - return sort(left).concat(pivot).concat(sort(right)); - }; +module.exports.quicksort = function () { + var sort = function (items) { + if (items.length <= 1) return items + var pivot = items.shift() + var current + var left = [] + var right = [] - return sort(Array.apply(this, arguments)); -}; \ No newline at end of file + while (items.length > 0) { + current = items.shift() + current < pivot ? left.push(current) : right.push(current) + } + return sort(left) + .concat(pivot) + .concat(sort(right)) + } + + return sort(Array.apply(this, arguments)) +} diff --git a/packages/git-diff/spec/git-diff-spec.js b/packages/git-diff/spec/git-diff-spec.js index badb15f76..950fec71d 100644 --- a/packages/git-diff/spec/git-diff-spec.js +++ b/packages/git-diff/spec/git-diff-spec.js @@ -156,13 +156,13 @@ describe('GitDiff package', () => { describe('move-to-next-diff/move-to-previous-diff events', () => { it('moves the cursor to first character of the next/previous diff line', () => { editor.insertText('a') - editor.setCursorBufferPosition([5]) + editor.setCursorBufferPosition([9]) editor.deleteLine() advanceClock(editor.getBuffer().stoppedChangingDelay) editor.setCursorBufferPosition([0]) atom.commands.dispatch(editorElement, 'git-diff:move-to-next-diff') - expect(editor.getCursorBufferPosition()).toEqual([4, 4]) + expect(editor.getCursorBufferPosition()).toEqual([8, 4]) atom.commands.dispatch(editorElement, 'git-diff:move-to-previous-diff') expect(editor.getCursorBufferPosition()).toEqual([0, 0]) @@ -170,19 +170,19 @@ describe('GitDiff package', () => { it('wraps around to the first/last diff in the file', () => { editor.insertText('a') - editor.setCursorBufferPosition([5]) + editor.setCursorBufferPosition([9]) editor.deleteLine() advanceClock(editor.getBuffer().stoppedChangingDelay) editor.setCursorBufferPosition([0]) atom.commands.dispatch(editorElement, 'git-diff:move-to-next-diff') - expect(editor.getCursorBufferPosition()).toEqual([4, 4]) + expect(editor.getCursorBufferPosition()).toEqual([8, 4]) atom.commands.dispatch(editorElement, 'git-diff:move-to-next-diff') expect(editor.getCursorBufferPosition()).toEqual([0, 0]) atom.commands.dispatch(editorElement, 'git-diff:move-to-previous-diff') - expect(editor.getCursorBufferPosition()).toEqual([4, 4]) + expect(editor.getCursorBufferPosition()).toEqual([8, 4]) }) describe('when the wrapAroundOnMoveToDiff config option is false', () => { @@ -192,16 +192,16 @@ describe('GitDiff package', () => { it('does not wraps around to the first/last diff in the file', () => { editor.insertText('a') - editor.setCursorBufferPosition([5]) + editor.setCursorBufferPosition([9]) editor.deleteLine() advanceClock(editor.getBuffer().stoppedChangingDelay) editor.setCursorBufferPosition([0]) atom.commands.dispatch(editorElement, 'git-diff:move-to-next-diff') - expect(editor.getCursorBufferPosition()).toEqual([4, 4]) + expect(editor.getCursorBufferPosition()).toEqual([8, 4]) atom.commands.dispatch(editorElement, 'git-diff:move-to-next-diff') - expect(editor.getCursorBufferPosition()).toEqual([4, 4]) + expect(editor.getCursorBufferPosition()).toEqual([8, 4]) atom.commands.dispatch(editorElement, 'git-diff:move-to-previous-diff') expect(editor.getCursorBufferPosition()).toEqual([0, 0]) From 3f1b965343889626b32401a8b079cc5a50c2c1d6 Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Mon, 25 Feb 2019 11:51:02 +0100 Subject: [PATCH 7/9] Lint fixture file from go-to-line package The specs needed to be updated since they depended on the actual contents of the fixture. --- packages/go-to-line/spec/fixtures/sample.js | 108 +++++++++++--------- packages/go-to-line/spec/go-to-line-spec.js | 18 ++-- 2 files changed, 70 insertions(+), 56 deletions(-) diff --git a/packages/go-to-line/spec/fixtures/sample.js b/packages/go-to-line/spec/fixtures/sample.js index e09a93919..17845689a 100644 --- a/packages/go-to-line/spec/fixtures/sample.js +++ b/packages/go-to-line/spec/fixtures/sample.js @@ -1,70 +1,84 @@ var quicksort = function () { - var sort = function(items) { - if (items.length <= 1) return items; - var pivot = items.shift(), current, left = [], right = []; - while(items.length > 0) { - current = items.shift(); - current < pivot ? left.push(current) : right.push(current); - } - return sort(left).concat(pivot).concat(sort(right)); - }; + var sort = function (items) { + if (items.length <= 1) return items + var pivot = items.shift() + var current + var left = [] + var right = [] - return sort(Array.apply(this, arguments)); -}; + while (items.length > 0) { + current = items.shift() + current < pivot ? left.push(current) : right.push(current) + } + return sort(left) + .concat(pivot) + .concat(sort(right)) + } + + return sort(Array.apply(this, arguments)) +} // adapted from: // https://github.com/nzakas/computer-science-in-javascript/tree/master/algorithms/sorting/merge-sort-recursive -var mergeSort = function (items){ - var merge = function (left, right){ - var result = []; - var il = 0; - var ir = 0; +var mergeSort = function (items) { + var merge = function (left, right) { + var result = [] + var il = 0 + var ir = 0 - while (il < left.length && ir < right.length){ - if (left[il] < right[ir]){ - result.push(left[il++]); + while (il < left.length && ir < right.length) { + if (left[il] < right[ir]) { + result.push(left[il++]) } else { - result.push(right[ir++]); + result.push(right[ir++]) } } - return result.concat(left.slice(il)).concat(right.slice(ir)); - }; - - if (items.length < 2) { - return items; + return result.concat(left.slice(il)).concat(right.slice(ir)) } - var middle = Math.floor(items.length / 2), - left = items.slice(0, middle), - right = items.slice(middle), - params = merge(mergeSort(left), mergeSort(right)); + if (items.length < 2) { + return items + } + + var middle = Math.floor(items.length / 2) + var left = items.slice(0, middle) + var right = items.slice(middle) + var params = merge(mergeSort(left), mergeSort(right)) // Add the arguments to replace everything between 0 and last item in the array - params.unshift(0, items.length); - items.splice.apply(items, params); - return items; -}; + params.unshift(0, items.length) + items.splice.apply(items, params) + return items +} // adapted from: // https://github.com/nzakas/computer-science-in-javascript/blob/master/algorithms/sorting/bubble-sort/bubble-sort.js -var bubbleSort = function (items){ - var swap = function (items, firstIndex, secondIndex){ - var temp = items[firstIndex]; - items[firstIndex] = items[secondIndex]; - items[secondIndex] = temp; - }; +var bubbleSort = function (items) { + var swap = function (items, firstIndex, secondIndex) { + var temp = items[firstIndex] + items[firstIndex] = items[secondIndex] + items[secondIndex] = temp + } - var len = items.length, - i, j, stop; + var len = items.length + var i + var j + var stop - for (i=0; i < len; i++){ - for (j=0, stop=len-i; j < stop; j++){ - if (items[j] > items[j+1]){ - swap(items, j, j+1); + for (i = 0; i < len; i++) { + for (j = 0, stop = len - i; j < stop; j++) { + if (items[j] > items[j + 1]) { + swap(items, j, j + 1) } } } - return items; -}; + return items +} + +module.exports = { + bubbleSort, + mergeSort, + quicksort +} diff --git a/packages/go-to-line/spec/go-to-line-spec.js b/packages/go-to-line/spec/go-to-line-spec.js index 62551825e..b3440b00f 100644 --- a/packages/go-to-line/spec/go-to-line-spec.js +++ b/packages/go-to-line/spec/go-to-line-spec.js @@ -51,8 +51,8 @@ describe('GoToLine', () => { describe('when typing line numbers (auto-navigation)', () => { it('automatically scrolls to the desired line', () => { - goToLine.miniEditor.insertText('13') - expect(editor.getCursorBufferPosition()).toEqual([12, 0]) + goToLine.miniEditor.insertText('19') + expect(editor.getCursorBufferPosition()).toEqual([18, 0]) }) }) @@ -90,10 +90,10 @@ describe('GoToLine', () => { atom.commands.dispatch(editorView, 'go-to-line:toggle') expect(goToLine.panel.isVisible()).toBeTruthy() expect(goToLine.miniEditor.getText()).toBe('') - goToLine.miniEditor.insertText('71') + goToLine.miniEditor.insertText('78') atom.commands.dispatch(goToLine.miniEditor.element, 'core:confirm') expect(goToLine.panel.isVisible()).toBeFalsy() - expect(editor.getCursorBufferPosition()).toEqual([70, 0]) + expect(editor.getCursorBufferPosition()).toEqual([77, 0]) }) }) @@ -105,7 +105,7 @@ describe('GoToLine', () => { goToLine.miniEditor.insertText('3:43') atom.commands.dispatch(goToLine.miniEditor.element, 'core:confirm') expect(goToLine.panel.isVisible()).toBeFalsy() - expect(editor.getCursorBufferPosition()).toEqual([2, 40]) + expect(editor.getCursorBufferPosition()).toEqual([2, 39]) }) }) @@ -120,12 +120,12 @@ describe('GoToLine', () => { describe('when the line number entered is nested within foldes', () => { it('unfolds all folds containing the given row', () => { - expect(editor.indentationForBufferRow(6)).toEqual(3) + expect(editor.indentationForBufferRow(9)).toEqual(3) editor.foldAll() - expect(editor.screenRowForBufferRow(6)).toEqual(0) - goToLine.miniEditor.insertText('7') + expect(editor.screenRowForBufferRow(9)).toEqual(0) + goToLine.miniEditor.insertText('10') atom.commands.dispatch(goToLine.miniEditor.element, 'core:confirm') - expect(editor.getCursorBufferPosition()).toEqual([6, 6]) + expect(editor.getCursorBufferPosition()).toEqual([9, 6]) }) }) }) From ebf137954cbc0ea25dd10817f820de7840a92be7 Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Thu, 21 Feb 2019 15:23:07 +0100 Subject: [PATCH 8/9] Add comment and ignore rule on regular expression. --- packages/line-ending-selector/lib/main.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/line-ending-selector/lib/main.js b/packages/line-ending-selector/lib/main.js index 74b1d44c0..c3e07ff05 100644 --- a/packages/line-ending-selector/lib/main.js +++ b/packages/line-ending-selector/lib/main.js @@ -7,6 +7,11 @@ import StatusBarItem from './status-bar-item' import helpers from './helpers' const LineEndingRegExp = /\r\n|\n/g + +// the following regular expression is executed natively via the `substring` package, +// where `\A` corresponds to the beginning of the string. +// More info: https://github.com/atom/line-ending-selector/pull/56 +// eslint-disable-next-line no-useless-escape const LFRegExp = /(\A|[^\r])\n/g const CRLFRegExp = /\r\n/g From 034a05c8f48742cb6aeabbf1d3a40eb38593b1b1 Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Thu, 21 Feb 2019 15:24:07 +0100 Subject: [PATCH 9/9] Enable linter on packages/ folder --- script/lib/lint-java-script-paths.js | 1 + 1 file changed, 1 insertion(+) diff --git a/script/lib/lint-java-script-paths.js b/script/lib/lint-java-script-paths.js index 8086488dc..64ff22610 100644 --- a/script/lib/lint-java-script-paths.js +++ b/script/lib/lint-java-script-paths.js @@ -9,6 +9,7 @@ const CONFIG = require('../config') module.exports = function () { const globPathsToLint = [ path.join(CONFIG.repositoryRootPath, 'exports', '**', '*.js'), + path.join(CONFIG.repositoryRootPath, 'packages', '**', '*.js'), path.join(CONFIG.repositoryRootPath, 'script', '**', '*.js'), path.join(CONFIG.repositoryRootPath, 'src', '**', '*.js'), path.join(CONFIG.repositoryRootPath, 'static', '*.js')