From 1155bb54b19016507e3da8bec0a220558eb9242c Mon Sep 17 00:00:00 2001 From: CHaBou Date: Sun, 10 Sep 2017 15:35:10 +0200 Subject: [PATCH] Add prettier and resolve all lint errors --- app/auto-updater.js | 6 +- app/config.js | 63 +++-- app/config/import.js | 9 +- app/config/init.js | 9 +- app/config/keymaps.js | 17 +- app/config/open.js | 85 ++++--- app/config/paths.js | 22 +- app/index.js | 215 ++++++++-------- app/menus/menu.js | 5 +- app/menus/menus/darwin.js | 2 +- app/menus/menus/edit.js | 2 +- app/menus/menus/help.js | 2 +- app/menus/menus/plugins.js | 2 +- app/menus/menus/shell.js | 2 +- app/menus/menus/view.js | 2 +- app/menus/menus/window.js | 5 +- app/notifications.js | 32 +-- app/notify.js | 6 +- app/plugins.js | 84 +++---- app/plugins/extensions.js | 45 +++- app/plugins/install.js | 35 +-- app/rpc.js | 2 - app/session.js | 26 +- app/system-context-menu.js | 56 +++-- app/ui/window.js | 82 +++--- app/utils/to-electron-background-color.js | 9 +- lib/actions/header.js | 8 +- lib/actions/notifications.js | 5 +- lib/actions/sessions.js | 4 +- lib/actions/ui.js | 22 +- lib/actions/updater.js | 5 +- lib/component.js | 8 +- lib/components/header.js | 92 +++---- lib/components/notification.js | 38 +-- lib/components/notifications.js | 67 +++-- lib/components/split-pane.js | 47 ++-- lib/components/style-sheet.js | 16 +- lib/components/tab.js | 67 ++--- lib/components/tabs.js | 56 ++--- lib/components/term-group.js | 52 ++-- lib/components/term.js | 146 +++++------ lib/components/terms.js | 50 ++-- lib/containers/header.js | 21 +- lib/containers/hyper.js | 17 +- lib/containers/terms.js | 5 +- lib/hterm.js | 149 ++++++----- lib/index.js | 2 +- lib/reducers/sessions.js | 48 ++-- lib/reducers/term-groups.js | 43 ++-- lib/reducers/ui.js | 235 +++++++++--------- lib/selectors.js | 5 +- lib/store/configure-store.dev.js | 14 +- lib/store/configure-store.prod.js | 11 +- lib/utils/file.js | 6 +- lib/utils/key-code.js | 4 +- lib/utils/notify.js | 1 + lib/utils/plugins.js | 80 ++++-- lib/utils/rpc.js | 2 - lib/utils/selection.js | 6 +- lib/utils/url-command.js | 2 +- package.json | 27 +- .../unit/to-electron-background-color.test.js | 36 +-- webpack.config.js | 2 +- yarn.lock | 25 ++ 64 files changed, 1120 insertions(+), 1129 deletions(-) diff --git a/app/auto-updater.js b/app/auto-updater.js index beeb84c2..c26d1f7b 100644 --- a/app/auto-updater.js +++ b/app/auto-updater.js @@ -4,7 +4,8 @@ const ms = require('ms'); const retry = require('async-retry'); // Utilities -const notify = require('./notify'); // eslint-disable-line no-unused-vars +// eslint-disable-next-line no-unused-vars +const notify = require('./notify'); const {version} = require('./package'); const {getConfig} = require('./config'); @@ -14,6 +15,7 @@ let isInit = false; function init() { autoUpdater.on('error', (err, msg) => { + //eslint-disable-next-line no-console console.error('Error fetching updates', msg + ' (' + err.stack + ')'); }); @@ -51,7 +53,7 @@ function init() { isInit = true; } -module.exports = function (win) { +module.exports = win => { if (!isInit) { init(); } diff --git a/app/config.js b/app/config.js index dcd7ef02..43dfe0a7 100644 --- a/app/config.js +++ b/app/config.js @@ -12,7 +12,7 @@ const watchCfg = process.platform === 'win32' ? {interval: 2000} : {}; let cfg = {}; let _watcher; -const _watch = function () { +const _watch = function() { if (_watcher) { return _watcher; } @@ -23,79 +23,74 @@ const _watch = function () { cfg = _import(); notify('Configuration updated', 'Hyper configuration reloaded!'); watchers.forEach(fn => fn()); - checkDeprecatedConfig() + checkDeprecatedConfig(); }); _watcher.on('error', error => { + //eslint-disable-next-line no-console console.error('error watching config', error); }); }; -exports.subscribe = function (fn) { +exports.subscribe = fn => { watchers.push(fn); return () => { watchers.splice(watchers.indexOf(fn), 1); }; }; -exports.getConfigDir = function () { +exports.getConfigDir = () => { // expose config directory to load plugin from the right place return cfgDir; }; -exports.getConfig = function () { +exports.getConfig = () => { return cfg.config; }; -exports.openConfig = function () { +exports.openConfig = () => { return _openConfig(); }; -exports.getPlugins = function () { +exports.getPlugins = () => { return { plugins: cfg.plugins, localPlugins: cfg.localPlugins }; }; -exports.getKeymaps = function () { +exports.getKeymaps = () => { return cfg.keymaps; }; -exports.extendKeymaps = function (keymaps) { +exports.extendKeymaps = keymaps => { if (keymaps) { cfg.keymaps = keymaps; } }; -exports.setup = function () { +exports.setup = () => { cfg = _import(); _watch(); - checkDeprecatedConfig() + checkDeprecatedConfig(); }; exports.getWin = win.get; exports.winRecord = win.recordState; -const getDeprecatedCSS = function (config) { +const getDeprecatedCSS = function(config) { const deprecated = []; - const deprecatedCSS = [ - 'x-screen', - 'x-row', - 'cursor-node', - '::selection' - ]; + const deprecatedCSS = ['x-screen', 'x-row', 'cursor-node', '::selection']; deprecatedCSS.forEach(css => { - if ((config.css && config.css.indexOf(css) !== -1) || - (config.termCSS && config.termCSS.indexOf(css) !== -1)) { + if ((config.css && config.css.indexOf(css) !== -1) || (config.termCSS && config.termCSS.indexOf(css) !== -1)) { deprecated.push(css); } - }) + }); return deprecated; -} +}; exports.getDeprecatedCSS = getDeprecatedCSS; -const checkDeprecatedConfig = function () { +const checkDeprecatedConfig = function() { if (!cfg.config) { return; } @@ -104,22 +99,22 @@ const checkDeprecatedConfig = function () { return; } const deprecatedStr = deprecated.join(', '); - notify('Configuration warning', `Your configuration uses some deprecated CSS classes (${deprecatedStr})`) -} + notify('Configuration warning', `Your configuration uses some deprecated CSS classes (${deprecatedStr})`); +}; -exports.htermConfigTranslate = (config) => { +exports.htermConfigTranslate = config => { const cssReplacements = { - 'x-screen x-row([ \{\.\[])': '.xterm-rows > div$1', - '.cursor-node([ \{\.\[])': '.terminal-cursor$1', - '::selection([ \{\.\[])': '.terminal .xterm-selection div$1', - 'x-screen a([ \{\.\[])': '.terminal a$1', - 'x-row a([ \{\.\[])': '.terminal a$1' - } + 'x-screen x-row([ {.[])': '.xterm-rows > div$1', + '.cursor-node([ {.[])': '.terminal-cursor$1', + '::selection([ {.[])': '.terminal .xterm-selection div$1', + 'x-screen a([ {.[])': '.terminal a$1', + 'x-row a([ {.[])': '.terminal a$1' + }; Object.keys(cssReplacements).forEach(pattern => { const searchvalue = new RegExp(pattern, 'g'); const newvalue = cssReplacements[pattern]; config.css = config.css.replace(searchvalue, newvalue); config.termCSS = config.termCSS.replace(searchvalue, newvalue); - }) + }); return config; -} +}; diff --git a/app/config/import.js b/app/config/import.js index 8f6635f2..5f082a12 100644 --- a/app/config/import.js +++ b/app/config/import.js @@ -4,18 +4,18 @@ const {defaultCfg, cfgPath, plugs} = require('./paths'); const _init = require('./init'); const _keymaps = require('./keymaps'); -const _write = function (path, data) { +const _write = function(path, data) { // This method will take text formatted as Unix line endings and transform it // to text formatted with DOS line endings. We do this because the default // text editor on Windows (notepad) doesn't Deal with LF files. Still. In 2017. - const crlfify = function (str) { + const crlfify = function(str) { return str.replace(/\r?\n/g, '\r\n'); }; const format = process.platform === 'win32' ? crlfify(data.toString()) : data; writeFileSync(path, format, 'utf8'); }; -const _importConf = function () { +const _importConf = function() { // init plugin directories if not present mkdirpSync(plugs.base); mkdirpSync(plugs.local); @@ -30,11 +30,12 @@ const _importConf = function () { return {userCfg: {}, defaultCfg: _defaultCfg}; } } catch (err) { + //eslint-disable-next-line no-console console.log(err); } }; -const _import = function () { +const _import = function() { const cfg = _init(_importConf()); if (cfg) { diff --git a/app/config/init.js b/app/config/init.js index 8cc446f7..0de49d2e 100644 --- a/app/config/init.js +++ b/app/config/init.js @@ -2,7 +2,7 @@ const vm = require('vm'); const merge = require('lodash/merge'); const notify = require('../notify'); -const _extract = function (script) { +const _extract = function(script) { const module = {}; script.runInNewContext({module}); if (!module.exports) { @@ -11,21 +11,22 @@ const _extract = function (script) { return module.exports; }; -const _syntaxValidation = function (cfg) { +const _syntaxValidation = function(cfg) { try { return new vm.Script(cfg, {filename: '.hyper.js', displayErrors: true}); } catch (err) { notify(`Error loading config: ${err.name}, see DevTools for more info`); + //eslint-disable-next-line no-console console.error('Error loading config:', err); } }; -const _extractDefault = function (cfg) { +const _extractDefault = function(cfg) { return _extract(_syntaxValidation(cfg)); }; // init config -const _init = function (cfg) { +const _init = function(cfg) { const script = _syntaxValidation(cfg.userCfg); if (script) { const _cfg = _extract(script); diff --git a/app/config/keymaps.js b/app/config/keymaps.js index 22602c08..22a709c5 100644 --- a/app/config/keymaps.js +++ b/app/config/keymaps.js @@ -4,7 +4,7 @@ const {defaultPlatformKeyPath} = require('./paths'); const commands = {}; const keys = {}; -const _setKeysForCommands = function (keymap) { +const _setKeysForCommands = function(keymap) { for (const command in keymap) { if (command) { commands[command] = keymap[command].toLowerCase(); @@ -12,15 +12,15 @@ const _setKeysForCommands = function (keymap) { } }; -const _setCommandsForKeys = function (commands) { - for (const command in commands) { +const _setCommandsForKeys = function(commands_) { + for (const command in commands_) { if (command) { - keys[commands[command]] = command; + keys[commands_[command]] = command; } } }; -const _import = function (customsKeys) { +const _import = function(customsKeys) { try { const mapping = JSON.parse(readFileSync(defaultPlatformKeyPath())); _setKeysForCommands(mapping); @@ -28,10 +28,13 @@ const _import = function (customsKeys) { _setCommandsForKeys(commands); return {commands, keys}; - } catch (err) {} + } catch (err) { + //eslint-disable-next-line no-console + console.error(err); + } }; -const _extend = function (customsKeys) { +const _extend = function(customsKeys) { if (customsKeys) { for (const command in customsKeys) { if (command) { diff --git a/app/config/open.js b/app/config/open.js index c344390d..d0a79247 100644 --- a/app/config/open.js +++ b/app/config/open.js @@ -9,34 +9,39 @@ if (process.platform === 'win32') { // Windows opens .js files with WScript.exe by default // If the user hasn't set up an editor for .js files, we fallback to notepad. - const getFileExtKeys = () => new Promise((resolve, reject) => { - Registry({ - hive: Registry.HKCU, - key: '\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\.js' - }) - .keys((error, keys) => { - if (error) { - reject(error); - } else { - resolve(keys || []); - } + const getFileExtKeys = () => + new Promise((resolve, reject) => { + Registry({ + hive: Registry.HKCU, + key: '\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\.js' + }).keys((error, keys) => { + if (error) { + reject(error); + } else { + resolve(keys || []); + } + }); }); - }); const hasDefaultSet = async () => { const keys = await getFileExtKeys(); - const valueGroups = await Promise.all(keys.map(key => new Promise((resolve, reject) => { - key.values((error, items) => { - if (error) { - reject(error); - } - resolve(items.map(item => item.value || '') || []); - }); - }))); + const valueGroups = await Promise.all( + keys.map( + key => + new Promise((resolve, reject) => { + key.values((error, items) => { + if (error) { + reject(error); + } + resolve(items.map(item => item.value || '') || []); + }); + }) + ) + ); const values = valueGroups - .reduce((allValues, groupValues) => ([...allValues, ...groupValues]), []) + .reduce((allValues, groupValues) => [...allValues, ...groupValues], []) .filter(value => value && typeof value === 'string'); // No default app set @@ -49,29 +54,33 @@ if (process.platform === 'win32') { const userDefaults = values.filter(value => value.endsWith('.exe') && !value.includes('WScript.exe')); // WScript.exe is overidden - return (userDefaults.length > 0); + return userDefaults.length > 0; } return true; }; // This mimics shell.openItem, true if it worked, false if not. - const openNotepad = file => new Promise(resolve => { - exec(`start notepad.exe ${file}`, error => { - resolve(!error); + const openNotepad = file => + new Promise(resolve => { + exec(`start notepad.exe ${file}`, error => { + resolve(!error); + }); }); - }); - module.exports = () => hasDefaultSet() - .then(yes => { - if (yes) { - return shell.openItem(cfgPath); - } - console.warn('No default app set for .js files, using notepad.exe fallback'); - return openNotepad(cfgPath); - }) - .catch(err => { - console.error('Open config with default app error:', err); - return openNotepad(cfgPath); - }); + module.exports = () => + hasDefaultSet() + .then(yes => { + if (yes) { + return shell.openItem(cfgPath); + } + //eslint-disable-next-line no-console + console.warn('No default app set for .js files, using notepad.exe fallback'); + return openNotepad(cfgPath); + }) + .catch(err => { + //eslint-disable-next-line no-console + console.error('Open config with default app error:', err); + return openNotepad(cfgPath); + }); } diff --git a/app/config/paths.js b/app/config/paths.js index 596ecca1..2e731f17 100644 --- a/app/config/paths.js +++ b/app/config/paths.js @@ -32,10 +32,14 @@ const linuxKeys = join(keymapPath, 'linux.json'); const defaultPlatformKeyPath = () => { switch (process.platform) { - case 'darwin': return darwinKeys; - case 'win32': return win32Keys; - case 'linux': return linuxKeys; - default: return darwinKeys; + case 'darwin': + return darwinKeys; + case 'win32': + return win32Keys; + case 'linux': + return linuxKeys; + default: + return darwinKeys; } }; @@ -45,6 +49,7 @@ if (isDev) { statSync(devCfg); cfgPath = devCfg; cfgDir = devDir; + //eslint-disable-next-line no-console console.log('using config file:', cfgPath); } catch (err) { // ignore @@ -52,5 +57,12 @@ if (isDev) { } module.exports = { - cfgDir, cfgPath, cfgFile, defaultCfg, icon, defaultPlatformKeyPath, plugs, yarn + cfgDir, + cfgPath, + cfgFile, + defaultCfg, + icon, + defaultPlatformKeyPath, + plugs, + yarn }; diff --git a/app/index.js b/app/index.js index 060196fe..141cc039 100644 --- a/app/index.js +++ b/app/index.js @@ -2,8 +2,11 @@ if (['--help', '-v', '--version'].includes(process.argv[1])) { const {version} = require('./package'); const configLocation = process.platform === 'win32' ? process.env.userprofile + '\\.hyper.js' : '~/.hyper.js'; + //eslint-disable-next-line no-console console.log(`Hyper version ${version}`); + //eslint-disable-next-line no-console console.log('Hyper does not accept any command line arguments. Please modify the config file instead.'); + //eslint-disable-next-line no-console console.log(`Hyper configuration file located at: ${configLocation}`); // eslint-disable-next-line unicorn/no-process-exit process.exit(); @@ -14,6 +17,7 @@ const checkSquirrel = () => { try { squirrel = require('electron-squirrel-startup'); + //eslint-disable-next-line no-empty } catch (err) {} if (squirrel) { @@ -81,6 +85,7 @@ app.getLastFocusedWindow = () => { }; if (isDev) { + //eslint-disable-next-line no-console console.log('running in dev mode'); // Overide default appVersion which is set from package.json @@ -90,123 +95,132 @@ if (isDev) { } }); } else { + //eslint-disable-next-line no-console console.log('running in prod mode'); } -const url = 'file://' + resolve( - isDev ? __dirname : app.getAppPath(), - 'index.html' -); - +const url = 'file://' + resolve(isDev ? __dirname : app.getAppPath(), 'index.html'); +//eslint-disable-next-line no-console console.log('electron will open', url); -app.on('ready', () => installDevExtensions(isDev).then(() => { - function createWindow(fn, options = {}) { - const cfg = plugins.getDecoratedConfig(); +app.on('ready', () => + installDevExtensions(isDev) + .then(() => { + function createWindow(fn, options = {}) { + const cfg = plugins.getDecoratedConfig(); - const winSet = config.getWin(); - let [startX, startY] = winSet.position; + const winSet = config.getWin(); + let [startX, startY] = winSet.position; - const [width, height] = options.size ? options.size : (cfg.windowSize || winSet.size); - const {screen} = require('electron'); + const [width, height] = options.size ? options.size : cfg.windowSize || winSet.size; + const {screen} = require('electron'); - const winPos = options.position; + const winPos = options.position; - // Open the new window roughly the height of the header away from the - // previous window. This also ensures in multi monitor setups that the - // new terminal is on the correct screen. - const focusedWindow = BrowserWindow.getFocusedWindow() || app.getLastFocusedWindow(); - // In case of options defaults position and size, we should ignore the focusedWindow. - if (winPos !== undefined) { - [startX, startY] = winPos; - } else if (focusedWindow) { - const points = focusedWindow.getPosition(); - const currentScreen = screen.getDisplayNearestPoint({x: points[0], y: points[1]}); + // Open the new window roughly the height of the header away from the + // previous window. This also ensures in multi monitor setups that the + // new terminal is on the correct screen. + const focusedWindow = BrowserWindow.getFocusedWindow() || app.getLastFocusedWindow(); + // In case of options defaults position and size, we should ignore the focusedWindow. + if (winPos !== undefined) { + [startX, startY] = winPos; + } else if (focusedWindow) { + const points = focusedWindow.getPosition(); + const currentScreen = screen.getDisplayNearestPoint({ + x: points[0], + y: points[1] + }); - const biggestX = ((points[0] + 100 + width) - currentScreen.bounds.x); - const biggestY = ((points[1] + 100 + height) - currentScreen.bounds.y); + const biggestX = points[0] + 100 + width - currentScreen.bounds.x; + const biggestY = points[1] + 100 + height - currentScreen.bounds.y; - if (biggestX > currentScreen.size.width) { - startX = 50; - } else { - startX = points[0] + 34; + if (biggestX > currentScreen.size.width) { + startX = 50; + } else { + startX = points[0] + 34; + } + if (biggestY > currentScreen.size.height) { + startY = 50; + } else { + startY = points[1] + 34; + } + } + + const hwin = new Window({width, height, x: startX, y: startY}, cfg, fn); + windowSet.add(hwin); + hwin.loadURL(url); + + // the window can be closed by the browser process itself + hwin.on('close', () => { + hwin.clean(); + windowSet.delete(hwin); + }); + + hwin.on('closed', () => { + if (process.platform !== 'darwin' && windowSet.size === 0) { + app.quit(); + } + }); + + return hwin; } - if (biggestY > currentScreen.size.height) { - startY = 50; - } else { - startY = points[1] + 34; - } - } - const hwin = new Window({width, height, x: startX, y: startY}, cfg, fn); - windowSet.add(hwin); - hwin.loadURL(url); - - // the window can be closed by the browser process itself - hwin.on('close', () => { - hwin.clean(); - windowSet.delete(hwin); - }); - - hwin.on('closed', () => { - if (process.platform !== 'darwin' && windowSet.size === 0) { - app.quit(); - } - }); - - return hwin; - } - - // when opening create a new window - createWindow(); - - // expose to plugins - app.createWindow = createWindow; - - // mac only. when the dock icon is clicked - // and we don't have any active windows open, - // we open one - app.on('activate', () => { - if (!windowSet.size) { + // when opening create a new window createWindow(); - } - }); - const makeMenu = () => { - const menu = plugins.decorateMenu( - AppMenu(createWindow, () => { - plugins.updatePlugins({force: true}); - }, - plugins.getLoadedPluginVersions - )); + // expose to plugins + app.createWindow = createWindow; - // If we're on Mac make a Dock Menu - if (process.platform === 'darwin') { - const dockMenu = Menu.buildFromTemplate([{ - label: 'New Window', - click() { + // mac only. when the dock icon is clicked + // and we don't have any active windows open, + // we open one + app.on('activate', () => { + if (!windowSet.size) { createWindow(); } - }]); - app.dock.setMenu(dockMenu); - } + }); - Menu.setApplicationMenu( - Menu.buildFromTemplate(menu) - ); - }; + const makeMenu = () => { + const menu = plugins.decorateMenu( + AppMenu( + createWindow, + () => { + plugins.updatePlugins({force: true}); + }, + plugins.getLoadedPluginVersions + ) + ); - const load = () => { - plugins.onApp(app); - plugins.extendKeymaps(); - makeMenu(); - }; + // If we're on Mac make a Dock Menu + if (process.platform === 'darwin') { + const dockMenu = Menu.buildFromTemplate([ + { + label: 'New Window', + click() { + createWindow(); + } + } + ]); + app.dock.setMenu(dockMenu); + } - load(); - plugins.subscribe(load); -}).catch(err => { - console.error('Error while loading devtools extensions', err); -})); + Menu.setApplicationMenu(Menu.buildFromTemplate(menu)); + }; + + const load = () => { + plugins.onApp(app); + plugins.extendKeymaps(); + makeMenu(); + }; + + load(); + plugins.subscribe(load); + }) + .catch(err => { + //eslint-disable-next-line no-console + console.error('Error while loading devtools extensions', err); + }) +); app.on('open-file', (event, path) => { const lastWindow = app.getLastFocusedWindow(); @@ -222,17 +236,14 @@ app.on('open-file', (event, path) => { } }); -function installDevExtensions(isDev) { - if (!isDev) { +function installDevExtensions(isDev_) { + if (!isDev_) { return Promise.resolve(); } // eslint-disable-next-line import/no-extraneous-dependencies const installer = require('electron-devtools-installer'); - const extensions = [ - 'REACT_DEVELOPER_TOOLS', - 'REDUX_DEVTOOLS' - ]; + const extensions = ['REACT_DEVELOPER_TOOLS', 'REDUX_DEVTOOLS']; const forceDownload = Boolean(process.env.UPGRADE_EXTENSIONS); return Promise.all(extensions.map(name => installer.default(installer[name], forceDownload))); diff --git a/app/menus/menu.js b/app/menus/menu.js index fff07157..d7d11afa 100644 --- a/app/menus/menu.js +++ b/app/menus/menu.js @@ -27,9 +27,8 @@ module.exports = (createWindow, updatePlugins, getLoadedPluginVersions) => { const showAbout = () => { const loadedPlugins = getLoadedPluginVersions(); - const pluginList = loadedPlugins.length === 0 ? - 'none' : - loadedPlugins.map(plugin => `\n ${plugin.name} (${plugin.version})`); + const pluginList = + loadedPlugins.length === 0 ? 'none' : loadedPlugins.map(plugin => `\n ${plugin.name} (${plugin.version})`); dialog.showMessageBox({ title: `About ${appName}`, diff --git a/app/menus/menus/darwin.js b/app/menus/menus/darwin.js index bff2bf0d..041b7b5c 100644 --- a/app/menus/menus/darwin.js +++ b/app/menus/menus/darwin.js @@ -3,7 +3,7 @@ const {app} = require('electron'); const {openConfig} = require('../../config'); -module.exports = function (commands, showAbout) { +module.exports = (commands, showAbout) => { return { label: `${app.getName()}`, submenu: [ diff --git a/app/menus/menus/edit.js b/app/menus/menus/edit.js index aa6f5d7d..363e6fd7 100644 --- a/app/menus/menus/edit.js +++ b/app/menus/menus/edit.js @@ -1,6 +1,6 @@ const {openConfig} = require('../../config'); -module.exports = function (commands) { +module.exports = commands => { const submenu = [ { role: 'undo', diff --git a/app/menus/menus/help.js b/app/menus/menus/help.js index 6bdc8826..39a33deb 100644 --- a/app/menus/menus/help.js +++ b/app/menus/menus/help.js @@ -1,7 +1,7 @@ const os = require('os'); const {app, shell} = require('electron'); -module.exports = function (commands, showAbout) { +module.exports = (commands, showAbout) => { const submenu = [ { label: `${app.getName()} Website`, diff --git a/app/menus/menus/plugins.js b/app/menus/menus/plugins.js index d7dee3fe..4c08f93f 100644 --- a/app/menus/menus/plugins.js +++ b/app/menus/menus/plugins.js @@ -1,4 +1,4 @@ -module.exports = function (commands, update) { +module.exports = (commands, update) => { return { label: 'Plugins', submenu: [ diff --git a/app/menus/menus/shell.js b/app/menus/menus/shell.js index 56b0d7d0..7e536a6d 100644 --- a/app/menus/menus/shell.js +++ b/app/menus/menus/shell.js @@ -1,4 +1,4 @@ -module.exports = function (commands, createWindow) { +module.exports = (commands, createWindow) => { const isMac = process.platform === 'darwin'; return { diff --git a/app/menus/menus/view.js b/app/menus/menus/view.js index 3c642538..e6a4e8c6 100644 --- a/app/menus/menus/view.js +++ b/app/menus/menus/view.js @@ -1,4 +1,4 @@ -module.exports = function (commands) { +module.exports = commands => { return { label: 'View', submenu: [ diff --git a/app/menus/menus/window.js b/app/menus/menus/window.js index 42eba8f2..69c4ef59 100644 --- a/app/menus/menus/window.js +++ b/app/menus/menus/window.js @@ -1,4 +1,4 @@ -module.exports = function (commands) { +module.exports = commands => { return { role: 'window', submenu: [ @@ -9,7 +9,8 @@ module.exports = function (commands) { { type: 'separator' }, - { // It's the same thing as clicking the green traffc-light on macOS + { + // It's the same thing as clicking the green traffc-light on macOS role: 'zoom', accelerator: commands['window:zoom'] }, diff --git a/app/notifications.js b/app/notifications.js index 58a5800a..1c7b5b91 100644 --- a/app/notifications.js +++ b/app/notifications.js @@ -10,10 +10,11 @@ module.exports = function fetchNotifications(win) { const retry = err => { setTimeout(() => fetchNotifications(win), ms('30m')); if (err) { + //eslint-disable-next-line no-console console.error('Notification messages fetch error', err.stack); } }; - + //eslint-disable-next-line no-console console.log('Checking for notification messages'); fetch(NEWS_URL, { headers: { @@ -21,19 +22,20 @@ module.exports = function fetchNotifications(win) { 'X-Hyper-Platform': process.platform } }) - .then(res => res.json()) - .then(data => { - const {message} = data || {}; - if (typeof message !== 'object' && message !== '') { - throw new Error('Bad response'); - } - if (message === '') { - console.log('No matching notification messages'); - } else { - rpc.emit('add notification', message); - } + .then(res => res.json()) + .then(data => { + const {message} = data || {}; + if (typeof message !== 'object' && message !== '') { + throw new Error('Bad response'); + } + if (message === '') { + //eslint-disable-next-line no-console + console.log('No matching notification messages'); + } else { + rpc.emit('add notification', message); + } - retry(); - }) - .catch(retry); + retry(); + }) + .catch(retry); }; diff --git a/app/notify.js b/app/notify.js index 2e342fda..1d00428e 100644 --- a/app/notify.js +++ b/app/notify.js @@ -16,10 +16,7 @@ app.on('ready', () => { const win_ = new BrowserWindow({ show: false }); - const url = 'file://' + resolve( - isDev ? __dirname : app.getAppPath(), - 'notify.html' - ); + const url = 'file://' + resolve(isDev ? __dirname : app.getAppPath(), 'notify.html'); win_.loadURL(url); win_.webContents.on('dom-ready', () => { win = win_; @@ -31,6 +28,7 @@ app.on('ready', () => { }); function notify(title, body) { + //eslint-disable-next-line no-console console.log(`[Notification] ${title}: ${body}`); if (win) { win.webContents.send('notification', {title, body}); diff --git a/app/plugins.js b/app/plugins.js index 5a75f9ce..b251d192 100644 --- a/app/plugins.js +++ b/app/plugins.js @@ -56,11 +56,9 @@ function updatePlugins({force = false} = {}) { updating = false; if (err) { + //eslint-disable-next-line no-console console.error(err.stack); - notify( - 'Error updating plugins.', - err.message - ); + notify('Error updating plugins.', err.message); } else { // flag successful plugin update cache.set('hyper.plugins', id_); @@ -83,15 +81,9 @@ function updatePlugins({force = false} = {}) { // notify watchers if (force || changed) { if (changed) { - notify( - 'Plugins Updated', - 'Restart the app or hot-reload with "View" > "Reload" to enjoy the updates!' - ); + notify('Plugins Updated', 'Restart the app or hot-reload with "View" > "Reload" to enjoy the updates!'); } else { - notify( - 'Plugins Updated', - 'No changes!' - ); + notify('Plugins Updated', 'No changes!'); } watchers.forEach(fn => fn(err, {force})); } @@ -101,16 +93,14 @@ function updatePlugins({force = false} = {}) { function getPluginVersions() { const paths_ = paths.plugins.concat(paths.localPlugins); - return paths_.map(path => { + return paths_.map(path_ => { let version = null; try { - // eslint-disable-next-line import/no-dynamic-require - version = require(resolve(path, 'package.json')).version; - } catch (err) { } - return [ - basename(path), - version - ]; + //eslint-disable-next-line import/no-dynamic-require + version = require(resolve(path_, 'package.json')).version; + //eslint-disable-next-line no-empty + } catch (err) {} + return [basename(path_), version]; }); } @@ -132,7 +122,7 @@ function clearCache() { exports.updatePlugins = updatePlugins; -exports.getLoadedPluginVersions = function () { +exports.getLoadedPluginVersions = () => { return modules.map(mod => ({name: mod._name, version: mod._version})); }; @@ -141,6 +131,7 @@ exports.getLoadedPluginVersions = function () { // to prevent slowness if (cache.get('hyper.plugins') !== id || process.env.HYPER_FORCE_UPDATE) { // install immediately if the user changed plugins + //eslint-disable-next-line no-console console.log('plugins have changed / not init, scheduling plugins installation'); setTimeout(() => { updatePlugins(); @@ -178,9 +169,9 @@ function alert(message) { }); } -function toDependencies(plugins) { +function toDependencies(plugins_) { const obj = {}; - plugins.plugins.forEach(plugin => { + plugins_.plugins.forEach(plugin => { const regex = /.(@|#)/; const match = regex.exec(plugin); @@ -198,7 +189,7 @@ function toDependencies(plugins) { return obj; } -exports.subscribe = function (fn) { +exports.subscribe = fn => { watchers.push(fn); return () => { watchers.splice(watchers.indexOf(fn), 1); @@ -220,56 +211,59 @@ function getPaths() { exports.getPaths = getPaths; // get paths from renderer -exports.getBasePaths = function () { +exports.getBasePaths = () => { return {path, localPath}; }; function requirePlugins() { - const {plugins, localPlugins} = paths; + const {plugins: plugins_, localPlugins} = paths; - const load = path => { + const load = path_ => { let mod; try { // eslint-disable-next-line import/no-dynamic-require - mod = require(path); + mod = require(path_); const exposed = mod && Object.keys(mod).some(key => availableExtensions.has(key)); if (!exposed) { - notify('Plugin error!', `Plugin "${basename(path)}" does not expose any ` + - 'Hyper extension API methods'); + notify('Plugin error!', `Plugin "${basename(path_)}" does not expose any ` + 'Hyper extension API methods'); return; } // populate the name for internal errors here - mod._name = basename(path); + mod._name = basename(path_); try { // eslint-disable-next-line import/no-dynamic-require - mod._version = require(resolve(path, 'package.json')).version; + mod._version = require(resolve(path_, 'package.json')).version; } catch (err) { - console.warn(`No package.json found in ${path}`); + //eslint-disable-next-line no-console + console.warn(`No package.json found in ${path_}`); } + //eslint-disable-next-line no-console console.log(`Plugin ${mod._name} (${mod._version}) loaded.`); return mod; } catch (err) { + //eslint-disable-next-line no-console console.error(err); - notify('Plugin error!', `Plugin "${basename(path)}" failed to load (${err.message})`); + notify('Plugin error!', `Plugin "${basename(path_)}" failed to load (${err.message})`); } }; - return plugins.map(load) + return plugins_ + .map(load) .concat(localPlugins.map(load)) .filter(v => Boolean(v)); } -exports.onApp = function (app) { +exports.onApp = app_ => { modules.forEach(plugin => { if (plugin.onApp) { - plugin.onApp(app); + plugin.onApp(app_); } }); }; -exports.onWindow = function (win) { +exports.onWindow = win => { modules.forEach(plugin => { if (plugin.onWindow) { plugin.onWindow(win); @@ -295,7 +289,7 @@ function decorateObject(base, key) { return decorated; } -exports.extendKeymaps = function () { +exports.extendKeymaps = () => { modules.forEach(plugin => { if (plugin.extendKeymaps) { const keys = _keys.extend(plugin.extendKeymaps()); @@ -318,26 +312,26 @@ exports.getDeprecatedConfig = () => { return; } deprecated[plugin._name] = {css: pluginCSSDeprecated}; - }) + }); return deprecated; -} +}; -exports.decorateMenu = function (tpl) { +exports.decorateMenu = tpl => { return decorateObject(tpl, 'decorateMenu'); }; -exports.getDecoratedEnv = function (baseEnv) { +exports.getDecoratedEnv = baseEnv => { return decorateObject(baseEnv, 'decorateEnv'); }; -exports.getDecoratedConfig = function () { +exports.getDecoratedConfig = () => { const baseConfig = config.getConfig(); const decoratedConfig = decorateObject(baseConfig, 'decorateConfig'); const translatedConfig = config.htermConfigTranslate(decoratedConfig); return translatedConfig; }; -exports.getDecoratedBrowserOptions = function (defaults) { +exports.getDecoratedBrowserOptions = defaults => { return decorateObject(defaults, 'decorateBrowserOptions'); }; diff --git a/app/plugins/extensions.js b/app/plugins/extensions.js index 7cbefb04..57b2a439 100644 --- a/app/plugins/extensions.js +++ b/app/plugins/extensions.js @@ -1,18 +1,39 @@ module.exports = { availableExtensions: new Set([ - 'onApp', 'onWindow', 'onRendererWindow', 'onUnload', 'middleware', - 'reduceUI', 'reduceSessions', 'reduceTermGroups', - 'decorateMenu', 'decorateTerm', 'decorateHyper', + 'onApp', + 'onWindow', + 'onRendererWindow', + 'onUnload', + 'middleware', + 'reduceUI', + 'reduceSessions', + 'reduceTermGroups', + 'decorateMenu', + 'decorateTerm', + 'decorateHyper', 'decorateHyperTerm', // for backwards compatibility with hyperterm - 'decorateHeader', 'decorateTerms', 'decorateTab', - 'decorateNotification', 'decorateNotifications', - 'decorateTabs', 'decorateConfig', 'decorateEnv', - 'decorateTermGroup', 'decorateSplitPane', 'getTermProps', - 'getTabProps', 'getTabsProps', 'getTermGroupProps', - 'mapHyperTermState', 'mapTermsState', - 'mapHeaderState', 'mapNotificationsState', - 'mapHyperTermDispatch', 'mapTermsDispatch', - 'mapHeaderDispatch', 'mapNotificationsDispatch', + 'decorateHeader', + 'decorateTerms', + 'decorateTab', + 'decorateNotification', + 'decorateNotifications', + 'decorateTabs', + 'decorateConfig', + 'decorateEnv', + 'decorateTermGroup', + 'decorateSplitPane', + 'getTermProps', + 'getTabProps', + 'getTabsProps', + 'getTermGroupProps', + 'mapHyperTermState', + 'mapTermsState', + 'mapHeaderState', + 'mapNotificationsState', + 'mapHyperTermDispatch', + 'mapTermsDispatch', + 'mapHeaderDispatch', + 'mapNotificationsDispatch', 'extendKeymaps' ]) }; diff --git a/app/plugins/install.js b/app/plugins/install.js index da322fbb..02e61014 100644 --- a/app/plugins/install.js +++ b/app/plugins/install.js @@ -13,24 +13,29 @@ module.exports = { }; spawnQueue.push(end => { const cmd = [process.execPath, yarn].concat(args).join(' '); + //eslint-disable-next-line no-console console.log('Launching yarn:', cmd); - cp.exec(cmd, { - cwd: plugs.base, - env, - shell: true, - timeout: ms('5m'), - stdio: ['ignore', 'ignore', 'inherit'] - }, err => { - if (err) { - cb(err); - } else { - cb(null); - } + cp.exec( + cmd, + { + cwd: plugs.base, + env, + shell: true, + timeout: ms('5m'), + stdio: ['ignore', 'ignore', 'inherit'] + }, + err => { + if (err) { + cb(err); + } else { + cb(null); + } - end(); - spawnQueue.start(); - }); + end(); + spawnQueue.start(); + } + ); }); spawnQueue.start(); diff --git a/app/rpc.js b/app/rpc.js index cffd5da8..547f9dcf 100644 --- a/app/rpc.js +++ b/app/rpc.js @@ -3,7 +3,6 @@ const {ipcMain} = require('electron'); const uuid = require('uuid'); class Server extends EventEmitter { - constructor(win) { super(); this.win = win; @@ -48,7 +47,6 @@ class Server extends EventEmitter { this.destroyed = true; } } - } module.exports = win => { diff --git a/app/session.js b/app/session.js index 8ce1ba55..3d2a4d82 100644 --- a/app/session.js +++ b/app/session.js @@ -8,7 +8,10 @@ const {getDecoratedEnv} = require('./plugins'); const {productName, version} = require('./package'); const config = require('./config'); -const createNodePtyError = () => new Error('`node-pty` failed to load. Typically this means that it was built incorrectly. Please check the `readme.md` to more info.'); +const createNodePtyError = () => + new Error( + '`node-pty` failed to load. Typically this means that it was built incorrectly. Please check the `readme.md` to more info.' + ); let spawn; try { @@ -20,15 +23,19 @@ try { const envFromConfig = config.getConfig().env || {}; module.exports = class Session extends EventEmitter { - constructor({rows, cols: columns, cwd, shell, shellArgs}) { super(); - const baseEnv = Object.assign({}, process.env, { - LANG: app.getLocale().replace('-', '_') + '.UTF-8', - TERM: 'xterm-256color', - TERM_PROGRAM: productName, - TERM_PROGRAM_VERSION: version - }, envFromConfig); + const baseEnv = Object.assign( + {}, + process.env, + { + LANG: app.getLocale().replace('-', '_') + '.UTF-8', + TERM: 'xterm-256color', + TERM_PROGRAM: productName, + TERM_PROGRAM_VERSION: version + }, + envFromConfig + ); // Electron has a default value for process.env.GOOGLE_API_KEY // We don't want to leak this to the shell @@ -85,6 +92,7 @@ module.exports = class Session extends EventEmitter { try { this.pty.resize(cols, rows); } catch (err) { + //eslint-disable-next-line no-console console.error(err.stack); } } @@ -93,10 +101,10 @@ module.exports = class Session extends EventEmitter { try { this.pty.kill(); } catch (err) { + //eslint-disable-next-line no-console console.error('exit error', err.stack); } this.emit('exit'); this.ended = true; } - }; diff --git a/app/system-context-menu.js b/app/system-context-menu.js index be429913..4d2eb08e 100644 --- a/app/system-context-menu.js +++ b/app/system-context-menu.js @@ -3,23 +3,26 @@ const Registry = require('winreg'); const appPath = `"${process.execPath}"`; const regKey = `\\Software\\Classes\\Directory\\background\\shell\\Hyper`; const regParts = [ - {key: 'command', name: '', value: `${appPath} "%V"`}, - {name: '', value: 'Open Hyper here'}, - {name: 'Icon', value: `${appPath}`} + {key: 'command', name: '', value: `${appPath} "%V"`}, + {name: '', value: 'Open Hyper here'}, + {name: 'Icon', value: `${appPath}`} ]; function addValues(hyperKey, commandKey, callback) { - hyperKey.set(regParts[1].name, Registry.REG_SZ, regParts[1].value, err => { - if (err) { - console.error(err.message); + hyperKey.set(regParts[1].name, Registry.REG_SZ, regParts[1].value, error => { + if (error) { + //eslint-disable-next-line no-console + console.error(error.message); } hyperKey.set(regParts[2].name, Registry.REG_SZ, regParts[2].value, err => { if (err) { + //eslint-disable-next-line no-console console.error(err.message); } - commandKey.set(regParts[0].name, Registry.REG_SZ, regParts[0].value, err => { - if (err) { - console.error(err.message); + commandKey.set(regParts[0].name, Registry.REG_SZ, regParts[0].value, err_ => { + if (err_) { + //eslint-disable-next-line no-console + console.error(err_.message); } callback(); }); @@ -27,24 +30,30 @@ function addValues(hyperKey, commandKey, callback) { }); } -exports.add = function (callback) { +exports.add = callback => { const hyperKey = new Registry({hive: 'HKCU', key: regKey}); - const commandKey = new Registry({hive: 'HKCU', key: `${regKey}\\${regParts[0].key}`}); + const commandKey = new Registry({ + hive: 'HKCU', + key: `${regKey}\\${regParts[0].key}` + }); - hyperKey.keyExists((err, exists) => { - if (err) { - console.error(err.message); + hyperKey.keyExists((error, exists) => { + if (error) { + //eslint-disable-next-line no-console + console.error(error.message); } if (exists) { - commandKey.keyExists((err, exists) => { - if (err) { - console.error(err.message); + commandKey.keyExists((err_, exists_) => { + if (err_) { + //eslint-disable-next-line no-console + console.error(err_.message); } - if (exists) { + if (exists_) { addValues(hyperKey, commandKey, callback); } else { commandKey.create(err => { if (err) { + //eslint-disable-next-line no-console console.error(err.message); } addValues(hyperKey, commandKey, callback); @@ -54,11 +63,13 @@ exports.add = function (callback) { } else { hyperKey.create(err => { if (err) { + //eslint-disable-next-line no-console console.error(err.message); } - commandKey.create(err => { - if (err) { - console.error(err.message); + commandKey.create(err_ => { + if (err_) { + //eslint-disable-next-line no-console + console.error(err_.message); } addValues(hyperKey, commandKey, callback); }); @@ -67,9 +78,10 @@ exports.add = function (callback) { }); }; -exports.remove = function (callback) { +exports.remove = callback => { new Registry({hive: 'HKCU', key: regKey}).destroy(err => { if (err) { + //eslint-disable-next-line no-console console.error(err.message); } callback(); diff --git a/app/ui/window.js b/app/ui/window.js index 09bd48c9..e4d45e90 100644 --- a/app/ui/window.js +++ b/app/ui/window.js @@ -13,21 +13,24 @@ const fetchNotifications = require('../notifications'); const Session = require('../session'); module.exports = class Window { - constructor(options, cfg, fn) { - const opts = Object.assign({ - minWidth: 370, - minHeight: 190, - backgroundColor: toElectronBackgroundColor(cfg.backgroundColor || '#000'), - titleBarStyle: 'hidden-inset', - title: 'Hyper.app', - // we want to go frameless on windows and linux - frame: process.platform === 'darwin', - transparent: process.platform === 'darwin', - icon, - show: process.env.HYPER_DEBUG || process.env.HYPERTERM_DEBUG || isDev, - acceptFirstMouse: true - }, options); - const window = new BrowserWindow(app.plugins.getDecoratedBrowserOptions(opts)); + constructor(options_, cfg, fn) { + const winOpts = Object.assign( + { + minWidth: 370, + minHeight: 190, + backgroundColor: toElectronBackgroundColor(cfg.backgroundColor || '#000'), + titleBarStyle: 'hidden-inset', + title: 'Hyper.app', + // we want to go frameless on windows and linux + frame: process.platform === 'darwin', + transparent: process.platform === 'darwin', + icon, + show: process.env.HYPER_DEBUG || process.env.HYPERTERM_DEBUG || isDev, + acceptFirstMouse: true + }, + options_ + ); + const window = new BrowserWindow(app.plugins.getDecoratedBrowserOptions(winOpts)); const rpc = createRPC(window); const sessions = new Map(); @@ -39,12 +42,8 @@ module.exports = class Window { window.webContents.send('config change'); // notify user that shell changes require new sessions - if (cfg_.shell !== cfg.shell || - JSON.stringify(cfg_.shellArgs) !== JSON.stringify(cfg.shellArgs)) { - notify( - 'Shell configuration changed!', - 'Open a new tab or window to start using the new shell' - ); + if (cfg_.shell !== cfg.shell || JSON.stringify(cfg_.shellArgs) !== JSON.stringify(cfg.shellArgs)) { + notify('Shell configuration changed!', 'Open a new tab or window to start using the new shell'); } // update background color if necessary @@ -66,37 +65,41 @@ module.exports = class Window { // and createWindow deifinition. It's executed in place of // the callback passed as parameter, and deleted right after. (app.windowCallback || fn)(window); - delete (app.windowCallback); + delete app.windowCallback; fetchNotifications(window); // auto updates if (!isDev && process.platform !== 'linux') { AutoUpdater(window); } else { + //eslint-disable-next-line no-console console.log('ignoring auto updates during dev'); } }); rpc.on('new', options => { - const opts = Object.assign({ - rows: 40, - cols: 100, - cwd: process.argv[1] && isAbsolute(process.argv[1]) ? process.argv[1] : cfgDir, - splitDirection: undefined, - shell: cfg.shell, - shellArgs: cfg.shellArgs && Array.from(cfg.shellArgs) - }, options); + const sessionOpts = Object.assign( + { + rows: 40, + cols: 100, + cwd: process.argv[1] && isAbsolute(process.argv[1]) ? process.argv[1] : cfgDir, + splitDirection: undefined, + shell: cfg.shell, + shellArgs: cfg.shellArgs && Array.from(cfg.shellArgs) + }, + options + ); - const initSession = (opts, fn) => { - fn(uuid.v4(), new Session(opts)); + const initSession = (opts, fn_) => { + fn_(uuid.v4(), new Session(opts)); }; - initSession(opts, (uid, session) => { + initSession(sessionOpts, (uid, session) => { sessions.set(uid, session); rpc.emit('session add', { - rows: opts.rows, - cols: opts.cols, + rows: sessionOpts.rows, + cols: sessionOpts.cols, uid, - splitDirection: opts.splitDirection, + splitDirection: sessionOpts.splitDirection, shell: session.shell, pid: session.pty.pid }); @@ -116,6 +119,7 @@ module.exports = class Window { if (session) { session.exit(); } else { + //eslint-disable-next-line no-console console.log('session not found by', uid); } }); @@ -136,9 +140,9 @@ module.exports = class Window { const session = sessions.get(uid); if (escaped) { - const escapedData = session.shell.endsWith('cmd.exe') ? - `"${data}"` : // This is how cmd.exe does it - `'${data.replace(/'/g, `'\\''`)}'`; // Inside a single-quoted string nothing is interpreted + const escapedData = session.shell.endsWith('cmd.exe') + ? `"${data}"` // This is how cmd.exe does it + : `'${data.replace(/'/g, `'\\''`)}'`; // Inside a single-quoted string nothing is interpreted session.write(escapedData); } else { diff --git a/app/utils/to-electron-background-color.js b/app/utils/to-electron-background-color.js index 60bc8251..053abbae 100644 --- a/app/utils/to-electron-background-color.js +++ b/app/utils/to-electron-background-color.js @@ -13,5 +13,12 @@ module.exports = bgColor => { // http://stackoverflow.com/a/11019879/1202488 const alphaHex = Math.round(color.alpha() * 255).toString(16); - return '#' + alphaHex + color.hex().toString().substr(1); + return ( + '#' + + alphaHex + + color + .hex() + .toString() + .substr(1) + ); }; diff --git a/lib/actions/header.js b/lib/actions/header.js index 3b5ed07b..f72a1360 100644 --- a/lib/actions/header.js +++ b/lib/actions/header.js @@ -1,5 +1,11 @@ import {CLOSE_TAB, CHANGE_TAB} from '../constants/tabs'; -import {UI_WINDOW_MAXIMIZE, UI_WINDOW_UNMAXIMIZE, UI_OPEN_HAMBURGER_MENU, UI_WINDOW_MINIMIZE, UI_WINDOW_CLOSE} from '../constants/ui'; +import { + UI_WINDOW_MAXIMIZE, + UI_WINDOW_UNMAXIMIZE, + UI_OPEN_HAMBURGER_MENU, + UI_WINDOW_MINIMIZE, + UI_WINDOW_CLOSE +} from '../constants/ui'; import rpc from '../rpc'; import {userExitTermGroup, setActiveGroup} from './term-groups'; diff --git a/lib/actions/notifications.js b/lib/actions/notifications.js index e533225a..df928375 100644 --- a/lib/actions/notifications.js +++ b/lib/actions/notifications.js @@ -1,7 +1,4 @@ -import { - NOTIFICATION_MESSAGE, - NOTIFICATION_DISMISS -} from '../constants/notifications'; +import {NOTIFICATION_MESSAGE, NOTIFICATION_DISMISS} from '../constants/notifications'; export function dismissNotification(id) { return { diff --git a/lib/actions/sessions.js b/lib/actions/sessions.js index 2a26e4b1..b296a145 100644 --- a/lib/actions/sessions.js +++ b/lib/actions/sessions.js @@ -48,7 +48,7 @@ export function requestSession() { } export function addSessionData(uid, data) { - return function (dispatch, getState) { + return (dispatch, getState) => { dispatch({ type: SESSION_ADD_DATA, data, @@ -141,7 +141,7 @@ export function resizeSession(uid, cols, rows) { } export function sendSessionData(uid, data, escaped) { - return function (dispatch, getState) { + return (dispatch, getState) => { dispatch({ type: SESSION_USER_DATA, data, diff --git a/lib/actions/ui.js b/lib/actions/ui.js index 8af758e6..42e7a410 100644 --- a/lib/actions/ui.js +++ b/lib/actions/ui.js @@ -5,11 +5,7 @@ import getRootGroups from '../selectors'; import findBySession from '../utils/term-groups'; import notify from '../utils/notify'; import rpc from '../rpc'; -import { - requestSession, - sendSessionData, - setActiveSession -} from '../actions/sessions'; +import {requestSession, sendSessionData, setActiveSession} from '../actions/sessions'; import { UI_FONT_SIZE_SET, UI_FONT_SIZE_INCR, @@ -74,9 +70,7 @@ export function setFontSmoothing() { return dispatch => { setTimeout(() => { const devicePixelRatio = window.devicePixelRatio; - const fontSmoothing = devicePixelRatio < 2 ? - 'subpixel-antialiased' : - 'antialiased'; + const fontSmoothing = devicePixelRatio < 2 ? 'subpixel-antialiased' : 'antialiased'; dispatch({ type: UI_FONT_SMOOTHING_SET, @@ -100,11 +94,7 @@ const findChildSessions = (termGroups, uid) => { return [uid]; } - return group - .children - .reduce((total, childUid) => total.concat( - findChildSessions(termGroups, childUid) - ), []); + return group.children.reduce((total, childUid) => total.concat(findChildSessions(termGroups, childUid)), []); }; // Get the index of the next or previous group, @@ -126,6 +116,7 @@ function moveToNeighborPane(type) { const {uid} = findBySession(termGroups, sessions.activeUid); const childGroups = findChildSessions(termGroups.termGroups, termGroups.activeRootGroup); if (childGroups.length === 1) { + //eslint-disable-next-line no-console console.log('ignoring move for single group'); } else { const index = getNeighborIndex(childGroups, uid, type); @@ -156,6 +147,7 @@ export function moveLeft() { const index = groupUids.indexOf(uid); const next = groupUids[index - 1] || last(groupUids); if (!next || uid === next) { + //eslint-disable-next-line no-console console.log('ignoring left move action'); } else { dispatch(setActiveGroup(next)); @@ -176,6 +168,7 @@ export function moveRight() { const index = groupUids.indexOf(uid); const next = groupUids[index + 1] || groupUids[0]; if (!next || uid === next) { + //eslint-disable-next-line no-console console.log('ignoring right move action'); } else { dispatch(setActiveGroup(next)); @@ -195,10 +188,12 @@ export function moveTo(i) { const groupUids = getGroupUids(state); const uid = state.termGroups.activeRootGroup; if (uid === groupUids[i]) { + //eslint-disable-next-line no-console console.log('ignoring same uid'); } else if (groupUids[i]) { dispatch(setActiveGroup(groupUids[i])); } else { + //eslint-disable-next-line no-console console.log('ignoring inexistent index', i); } } @@ -235,6 +230,7 @@ export function openFile(path) { effect() { stat(path, (err, stats) => { if (err) { + //eslint-disable-next-line no-console console.error(err.stack); notify('Unable to open path', `"${path}" doesn't exist.`); } else { diff --git a/lib/actions/updater.js b/lib/actions/updater.js index 4c3d91d3..1c55eaad 100644 --- a/lib/actions/updater.js +++ b/lib/actions/updater.js @@ -1,7 +1,4 @@ -import { - UPDATE_INSTALL, - UPDATE_AVAILABLE -} from '../constants/updater'; +import {UPDATE_INSTALL, UPDATE_AVAILABLE} from '../constants/updater'; import rpc from '../rpc'; export function installUpdate() { diff --git a/lib/component.js b/lib/component.js index 2c91df83..e5a98990 100644 --- a/lib/component.js +++ b/lib/component.js @@ -2,7 +2,6 @@ import React from 'react'; import {StyleSheet, css} from 'aphrodite-simple'; export default class Component extends React.PureComponent { - constructor() { super(); this.styles_ = this.createStyleSheet(); @@ -39,9 +38,7 @@ export default class Component extends React.PureComponent { // // it's important classes never get mangled by // uglifiers so that we can avoid collisions - const component = this.constructor.name - .toString() - .toLowerCase(); + const component = this.constructor.name.toString().toLowerCase(); const globalName = `${component}_${c}`; return [globalName, css(this.styles_[c])]; } @@ -58,11 +55,10 @@ export default class Component extends React.PureComponent { // convert static objects from `babel-plugin-transform-jsx` // to `React.Element`. if (!this.template) { - throw new TypeError('Component doesn\'t define `template`'); + throw new TypeError("Component doesn't define `template`"); } // invoke the template creator passing our css helper return this.template(this.cssHelper); } - } diff --git a/lib/components/header.js b/lib/components/header.js index 19d2a9e7..c7d4b347 100644 --- a/lib/components/header.js +++ b/lib/components/header.js @@ -8,7 +8,6 @@ import Tabs_ from './tabs'; const Tabs = decorate(Tabs_, 'Tabs'); export default class Header extends Component { - constructor() { super(); this.onChangeIntent = this.onChangeIntent.bind(this); @@ -22,8 +21,7 @@ export default class Header extends Component { onChangeIntent(active) { // we ignore clicks if they're a byproduct of a drag // motion to move the window - if (window.screenX !== this.headerMouseDownWindowX || - window.screenY !== this.headerMouseDownWindowY) { + if (window.screenX !== this.headerMouseDownWindowX || window.screenY !== this.headerMouseDownWindowY) { return; } @@ -105,60 +103,47 @@ export default class Header extends Component { } const {hambMenu, winCtrls} = this.getWindowHeaderConfig(); const left = winCtrls === 'left'; - const maxButtonHref = this.props.maximized ? - './renderer/assets/icons.svg#restore-window' : - './renderer/assets/icons.svg#maximize-window'; + const maxButtonHref = this.props.maximized + ? './renderer/assets/icons.svg#restore-window' + : './renderer/assets/icons.svg#maximize-window'; - return (
- { - !isMac && -
1 && 'windowHeaderWithBorder')} - style={{borderColor}} - > - { - hambMenu && - 1 && 'windowHeaderWithBorder')} style={{borderColor}}> + {hambMenu && ( + - - - } - {title} - { - winCtrls && -
- - + - - - - - - -
- } -
- } - { this.props.customChildrenBefore } - - { this.props.customChildren } -
); + )} + {title} + {winCtrls && ( +
+ + + + + + + + + +
+ )} + + )} + {this.props.customChildrenBefore} + + {this.props.customChildren} + + ); } styles() { @@ -248,5 +233,4 @@ export default class Header extends Component { closeWindow: {':hover': {color: '#FE354E'}, ':active': {color: '#FE354E'}} }; } - } diff --git a/lib/components/notification.js b/lib/components/notification.js index ad976ba8..d28af573 100644 --- a/lib/components/notification.js +++ b/lib/components/notification.js @@ -2,7 +2,6 @@ import React from 'react'; import Component from '../component'; export default class Notification extends Component { - constructor() { super(); this.state = { @@ -44,11 +43,7 @@ export default class Notification extends Component { }); const {backgroundColor} = this.props; if (backgroundColor) { - el.style.setProperty( - 'background-color', - backgroundColor, - 'important' - ); + el.style.setProperty('background-color', backgroundColor, 'important'); } } } @@ -71,24 +66,18 @@ export default class Notification extends Component { template(css) { const {backgroundColor} = this.props; const opacity = this.state.dismissing ? 0 : 1; - return (
- { this.props.customChildrenBefore } - { this.props.children || this.props.text } - { - this.props.userDismissable ? - [x] : - null - } - { this.props.customChildren } -
); + return ( +
+ {this.props.customChildrenBefore} + {this.props.children || this.props.text} + {this.props.userDismissable ? ( + + [x] + + ) : null} + {this.props.customChildren} +
+ ); } styles() { @@ -121,5 +110,4 @@ export default class Notification extends Component { } }; } - } diff --git a/lib/components/notifications.js b/lib/components/notifications.js index 75a0b12a..d6e0bf70 100644 --- a/lib/components/notifications.js +++ b/lib/components/notifications.js @@ -8,12 +8,11 @@ import Notification_ from './notification'; const Notification = decorate(Notification_); export default class Notifications extends Component { - template(css) { - return (
- { this.props.customChildrenBefore } - { - this.props.fontShowing && + return ( +
+ {this.props.customChildrenBefore} + {this.props.fontShowing && ( - } + /> + )} - { - this.props.resizeShowing && + {this.props.resizeShowing && ( - } + /> + )} - { - this.props.messageShowing && + {this.props.messageShowing && ( { - this.props.messageURL ? [ + > + {this.props.messageURL ? ( + [ this.props.messageText, ' (', more, + > + more + , ')' - ] : null - } + ] + ) : null} - } + )} - { - this.props.updateShowing && + {this.props.updateShowing && ( + > Version {this.props.updateVersion} ready. - {this.props.updateNote && ` ${this.props.updateNote.trim().replace(/\.$/, '')}`} - {' '} - ( { window.require('electron').shell.openExternal(ev.target.href); ev.preventDefault(); }} href={`https://github.com/zeit/hyper/releases/tag/${this.props.updateVersion}`} - >notes). - {' '} + > + notes + ).{' '} - Restart - . - { ' ' } + > + Restart + .{' '} - } - { this.props.customChildren } -
); + )} + {this.props.customChildren} +
+ ); } styles() { @@ -111,5 +109,4 @@ export default class Notifications extends Component { } }; } - } diff --git a/lib/components/split-pane.js b/lib/components/split-pane.js index 260aa786..031fc681 100644 --- a/lib/components/split-pane.js +++ b/lib/components/split-pane.js @@ -3,7 +3,6 @@ import React from 'react'; import Component from '../component'; export default class SplitPane extends Component { - constructor(props) { super(props); this.handleDragStart = this.handleDragStart.bind(this); @@ -82,7 +81,7 @@ export default class SplitPane extends Component { template(css) { const children = this.props.children; const {direction, borderColor} = this.props; - const sizeProperty = direction === 'horizontal' ? 'height' : 'flexBasis' + const sizeProperty = direction === 'horizontal' ? 'height' : 'flexBasis'; let {sizes} = this.props; if (!sizes) { // workaround for the fact that if we don't specify @@ -90,39 +89,32 @@ export default class SplitPane extends Component { // right height for the horizontal panes sizes = new Array(children.length).fill(1 / children.length); } - return (
- { - React.Children.map(children, (child, i) => { + return ( +
+ {React.Children.map(children, (child, i) => { const style = { // flexBasis doesn't work for the first horizontal pane, height need to be specified - [sizeProperty]: (sizes[i] * 100) + '%', - flexBasis: (sizes[i] * 100) + '%', + [sizeProperty]: sizes[i] * 100 + '%', + flexBasis: sizes[i] * 100 + '%', flexGrow: 0 }; return [ -
- { child } +
+ {child}
, - i < children.length - 1 ? + i < children.length - 1 ? (
: - null + /> + ) : null ]; - }) - } -
-
); + })} +
+
+ ); } styles() { @@ -136,11 +128,11 @@ export default class SplitPane extends Component { height: '100%' }, - 'panes_vertical': { + panes_vertical: { flexDirection: 'row' }, - 'panes_horizontal': { + panes_horizontal: { flexDirection: 'column' }, @@ -157,7 +149,7 @@ export default class SplitPane extends Component { flexShrink: 0 }, - 'divider_vertical': { + divider_vertical: { borderLeft: '5px solid rgba(255, 255, 255, 0)', borderRight: '5px solid rgba(255, 255, 255, 0)', width: '11px', @@ -165,7 +157,7 @@ export default class SplitPane extends Component { cursor: 'col-resize' }, - 'divider_horizontal': { + divider_horizontal: { height: '11px', margin: '-5px 0', borderTop: '5px solid rgba(255, 255, 255, 0)', @@ -195,5 +187,4 @@ export default class SplitPane extends Component { this.onDragEnd(); } } - } diff --git a/lib/components/style-sheet.js b/lib/components/style-sheet.js index 962fe694..d9c3f5d0 100644 --- a/lib/components/style-sheet.js +++ b/lib/components/style-sheet.js @@ -1,7 +1,7 @@ -import React from 'react' +import React from 'react'; export default class StyleSheet extends React.PureComponent { - render () { + render() { const { customCSS, colors, @@ -11,11 +11,12 @@ export default class StyleSheet extends React.PureComponent { fontSmoothing, foregroundColor, borderColor - } = this.props + } = this.props; return ( -