From 9ae814dfe45426f8df9b89b305392770344a7d50 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 17 Sep 2017 08:59:12 +0900 Subject: more strict lint --- src/background/index.js | 30 ++++++++++++++++++------------ src/background/keys.js | 12 +++++------- src/background/tabs.js | 32 +++++++++++++++++--------------- 3 files changed, 40 insertions(+), 34 deletions(-) (limited to 'src/background') diff --git a/src/background/index.js b/src/background/index.js index ef1b881..a4217c1 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -5,9 +5,10 @@ import * as commandActions from '../actions/command'; import * as consoleActions from '../actions/console'; import reducers from '../reducers'; import messages from '../messages'; -import * as store from '../store' +import * as store from '../store'; let prevInput = []; + const backgroundStore = store.createStore(reducers, (e, sender) => { console.error('Vim-Vixen:', e); if (sender) { @@ -15,9 +16,9 @@ const backgroundStore = store.createStore(reducers, (e, sender) => { } }); backgroundStore.subscribe((sender) => { - let currentInput = backgroundStore.getState().input + let currentInput = backgroundStore.getState().input; if (JSON.stringify(prevInput) === JSON.stringify(currentInput)) { - return + return; } prevInput = currentInput; @@ -39,13 +40,14 @@ backgroundStore.subscribe((sender) => { const keyQueueChanged = (state, sender) => { let prefix = keys.asKeymapChars(state.input.keys); - let matched = Object.keys(keys.defaultKeymap).filter((keys) => { - return keys.startsWith(prefix); + let matched = Object.keys(keys.defaultKeymap).filter((keyStr) => { + return keyStr.startsWith(prefix); }); - if (matched.length == 0) { + if (matched.length === 0) { backgroundStore.dispatch(inputActions.clearKeys(), sender); return Promise.resolve(); - } else if (matched.length > 1 || matched.length === 1 && prefix !== matched[0]) { + } else if (matched.length > 1 || + matched.length === 1 && prefix !== matched[0]) { return Promise.resolve(); } let action = keys.defaultKeymap[matched]; @@ -56,15 +58,19 @@ const keyQueueChanged = (state, sender) => { const handleMessage = (message, sender) => { switch (message.type) { case messages.KEYDOWN: - return backgroundStore.dispatch(inputActions.keyPress(message.code, message.ctrl), sender); + return backgroundStore.dispatch( + inputActions.keyPress(message.code, message.ctrl), sender); case messages.CONSOLE_BLURRED: - return backgroundStore.dispatch(consoleActions.hide(), sender); + return backgroundStore.dispatch( + consoleActions.hide(), sender); case messages.CONSOLE_ENTERED: - return backgroundStore.dispatch(commandActions.exec(message.text), sender); + return backgroundStore.dispatch( + commandActions.exec(message.text), sender); case messages.CONSOLE_CHANGEED: - return backgroundStore.dispatch(commandActions.complete(message.text), sender); + return backgroundStore.dispatch( + commandActions.complete(message.text), sender); } -} +}; browser.runtime.onMessage.addListener((message, sender) => { try { diff --git a/src/background/keys.js b/src/background/keys.js index 8d75aba..9121e0f 100644 --- a/src/background/keys.js +++ b/src/background/keys.js @@ -30,28 +30,26 @@ const defaultKeymap = { 'F': { type: operations.FOLLOW_START, newTab: true }, 'H': { type: operations.HISTORY_PREV }, 'L': { type: operations.HISTORY_NEXT }, -} +}; const asKeymapChars = (keys) => { return keys.map((k) => { let c = String.fromCharCode(k.code); if (k.ctrl) { return ''; - } else { - return c } + return c; }).join(''); -} +}; const asCaretChars = (keys) => { return keys.map((k) => { let c = String.fromCharCode(k.code); if (k.ctrl) { return '^' + c.toUpperCase(); - } else { - return c; } + return c; }).join(''); -} +}; export { defaultKeymap, asKeymapChars, asCaretChars }; diff --git a/src/background/tabs.js b/src/background/tabs.js index bd69b4b..32f71ba 100644 --- a/src/background/tabs.js +++ b/src/background/tabs.js @@ -12,9 +12,8 @@ const reopenTab = () => { let session = sessions[0]; if (session.tab) { return browser.sessions.restore(session.tab.sessionId); - } else { - return browser.sessions.restore(session.window.sessionId); } + return browser.sessions.restore(session.window.sessionId); }); }; @@ -24,20 +23,20 @@ const selectAt = (index) => { return; } if (index < 0 || tabs.length <= index) { - throw new RangeError(`tab ${index} does not exist`) + throw new RangeError(`tab ${index} does not exist`); } let id = tabs[index].id; - return browser.tabs.update(id, { active: true }) + return browser.tabs.update(id, { active: true }); }); }; const selectByKeyword = (current, keyword) => { return browser.tabs.query({ currentWindow: true }).then((tabs) => { let matched = tabs.filter((t) => { - return t.url.includes(keyword) || t.title.includes(keyword) - }) + return t.url.includes(keyword) || t.title.includes(keyword); + }); - if (matched.length == 0) { + if (matched.length === 0) { throw new RangeError('No matching buffer for ' + keyword); } for (let tab of matched) { @@ -47,13 +46,13 @@ const selectByKeyword = (current, keyword) => { } return browser.tabs.update(matched[0].id, { active: true }); }); -} +}; const getCompletions = (keyword) => { return browser.tabs.query({ currentWindow: true }).then((tabs) => { let matched = tabs.filter((t) => { - return t.url.includes(keyword) || t.title.includes(keyword) - }) + return t.url.includes(keyword) || t.title.includes(keyword); + }); return matched; }); }; @@ -63,9 +62,9 @@ const selectPrevTab = (current, count) => { if (tabs.length < 2) { return; } - let select = (current - count) % tabs.length + let select = (current - count) % tabs.length; let id = tabs[select].id; - return browser.tabs.update(id, { active: true }) + return browser.tabs.update(id, { active: true }); }); }; @@ -74,9 +73,9 @@ const selectNextTab = (current, count) => { if (tabs.length < 2) { return; } - let select = (current + count + tabs.length) % tabs.length + let select = (current + count + tabs.length) % tabs.length; let id = tabs[select].id; - return browser.tabs.update(id, { active: true }) + return browser.tabs.update(id, { active: true }); }); }; @@ -87,4 +86,7 @@ const reload = (current, cache) => { ); }; -export { closeTab, reopenTab, selectAt, selectByKeyword, getCompletions, selectPrevTab, selectNextTab, reload }; +export { + closeTab, reopenTab, selectAt, selectByKeyword, getCompletions, + selectPrevTab, selectNextTab, reload +}; -- cgit v1.2.3