more strict lint

This commit is contained in:
Shin'ya Ueoka 2017-09-17 08:59:12 +09:00
parent c5529958d5
commit 9ae814dfe4
21 changed files with 211 additions and 157 deletions

View file

@ -3,36 +3,39 @@ import * as consoleActions from './console';
const normalizeUrl = (string) => {
try {
return new URL(string).href
return new URL(string).href;
} catch (e) {
return 'http://' + string;
}
}
};
const openCommand = (url) => {
return browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => {
if (tabs.length > 0) {
return browser.tabs.update(tabs[0].id, { url: url });
return browser.tabs.query({
active: true, currentWindow: true
}).then((gotTabs) => {
if (gotTabs.length > 0) {
return browser.tabs.update(gotTabs[0].id, { url: url });
}
});
}
};
const tabopenCommand = (url) => {
return browser.tabs.create({ url: url });
}
};
const bufferCommand = (keywords) => {
return browser.tabs.query({ active: true, currentWindow: true }).then((tabss) => {
if (tabss.length > 0) {
return browser.tabs.query({
active: true, currentWindow: true
}).then((gotTabs) => {
if (gotTabs.length > 0) {
if (isNaN(keywords)) {
return tabs.selectByKeyword(tabss[0], keywords);
} else {
let index = parseInt(keywords, 10) - 1;
return tabs.selectAt(index);
return tabs.selectByKeyword(gotTabs[0], keywords);
}
let index = parseInt(keywords, 10) - 1;
return tabs.selectAt(index);
}
});
}
};
const doCommand = (name, remaining) => {
switch (name) {
@ -46,39 +49,43 @@ const doCommand = (name, remaining) => {
return bufferCommand(remaining);
}
throw new Error(name + ' command is not defined');
}
};
const getCompletions = (command, keywords) => {
switch (command) {
case 'buffer':
return tabs.getCompletions(keywords).then((tabs) => {
let items = tabs.map((tab) => {
return tabs.getCompletions(keywords).then((gotTabs) => {
let items = gotTabs.map((tab) => {
return {
caption: tab.title,
content: tab.title,
url: tab.url,
icon: tab.favIconUrl
}
};
});
return [{
name: "Buffers",
items: items
}];
return [
{
name: 'Buffers',
items: items
}
];
});
}
return Promise.resolve([]);
};
export function exec(line) {
const exec = (line) => {
let name = line.split(' ')[0];
let remaining = line.replace(name + ' ', '');
return doCommand(name, remaining).then(() => {
return consoleActions.hide();
});
}
};
export function complete(line) {
const complete = (line) => {
let command = line.split(' ', 1)[0];
let keywords = line.replace(command + ' ', '');
return getCompletions(command, keywords).then(consoleActions.setCompletions);
}
};
export { exec, complete };

View file

@ -1,28 +1,30 @@
import actions from '../actions';
export function showCommand(text) {
const showCommand = (text) => {
return {
type: actions.CONSOLE_SHOW_COMMAND,
text: text
};
}
};
export function setCompletions(completions) {
return {
const setCompletions = (completions) => {
return {
type: actions.CONSOLE_SET_COMPLETIONS,
completions: completions
};
}
};
export function showError(text) {
const showError = (text) => {
return {
type: actions.CONSOLE_SHOW_ERROR,
text: text
};
}
};
export function hide() {
return {
const hide = () => {
return {
type: actions.CONSOLE_HIDE
};
}
};
export { showCommand, setCompletions, showError, hide };

View file

@ -1,15 +1,17 @@
import actions from '../actions';
export function keyPress(code, ctrl) {
const keyPress = (code, ctrl) => {
return {
type: actions.INPUT_KEY_PRESS,
code,
ctrl
};
}
};
export function clearKeys() {
const clearKeys = () => {
return {
type: actions.INPUT_CLEAR_KEYS
}
}
};
};
export { keyPress, clearKeys };

View file

@ -1,10 +1,10 @@
import operations from '../operations';
import messages from '../messages';
import messages from '../messages';
import * as consoleActions from './console';
import * as tabs from '../background/tabs';
import * as zooms from '../background/zooms';
export function exec(operation, tab) {
const exec = (operation, tab) => {
switch (operation.type) {
case operations.TABS_CLOSE:
return tabs.closeTab(tab.id);
@ -28,9 +28,8 @@ export function exec(operation, tab) {
if (operations.alter) {
// alter url
return consoleActions.showCommand('open ' + tab.url);
} else {
return consoleActions.showCommand('open ');
}
return consoleActions.showCommand('open ');
case operations.COMMAND_BUFFER:
return consoleActions.showCommand('buffer ');
default:
@ -39,5 +38,6 @@ export function exec(operation, tab) {
operation
});
}
}
};
export { exec };