Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correct eslint errors #62

Merged
merged 2 commits into from
Sep 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions app/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const toggleMainWindow = () => {
}
};

const execute = message => {
const execute = (message) => {
switch (message.action) {
case 'openurl':
if (message.item.arg) {
Expand Down Expand Up @@ -146,7 +146,7 @@ const handleWindowCollapse = () => {
*/
const handleDidFinishLoad = () => {
const t = config.get('theme') || '';
loadTheme(t).then(theme => {
loadTheme(t).then((theme) => {
if (theme) {
win.webContents.send(IPC_LOAD_THEME, theme);
}
Expand Down Expand Up @@ -175,7 +175,7 @@ const handleQueryCommand = (evt, { q: queryPhrase }, plugins) => {
// if plugins are found with the current keyword
// only make queries to those plugins
if (matchedPlugins.length) {
matchedPlugins.forEach(plugin => {
matchedPlugins.forEach((plugin) => {
// query helper only if the query string isn't set
if (!queryString.length) {
results.push(queryHelper(plugin, keyword));
Expand All @@ -187,15 +187,15 @@ const handleQueryCommand = (evt, { q: queryPhrase }, plugins) => {
});
} else {
// otherwise, do a regular query to core plugins
plugins.forEach(plugin => {
plugins.forEach((plugin) => {
// if core, then query the results
if (plugin.isCore && (!plugin.keyword || keyword === plugin.keyword)) {
results.push(queryResults(plugin, fractions));
}
});
}

Promise.all(results).then(resultSet => {
Promise.all(results).then((resultSet) => {
const retval = resultSet
// flatten and merge items
.reduce((prev, next) => prev.concat(next))
Expand All @@ -210,7 +210,7 @@ const handleQueryCommand = (evt, { q: queryPhrase }, plugins) => {
}
return -1;
})
.filter(i => {
.filter((i) => {
const score = i.title.toLowerCase().score(keyword);
// eslint-disable-next-line no-extra-boolean-cast
return Boolean(score)
Expand Down Expand Up @@ -247,7 +247,7 @@ const handleItemDetailsRequest = (evt, item) => {
content = retrieveItemDetails(item, plugin);
}
// resolve and update the state
Promise.resolve(content).then(html => {
Promise.resolve(content).then((html) => {
cacheConf.set(cacheKey, html);
evt.sender.send(IPC_ITEM_DETAILS_RESPONSE, html);
});
Expand Down Expand Up @@ -321,7 +321,7 @@ const createWindow = () => {
*
* @param {Object[]} plugins - An array of plugin objects
*/
const registerIpcListeners = plugins => {
const registerIpcListeners = (plugins) => {
// listen to query commands and queries
// for results and sends it to the renderer
ipcMain.on(IPC_QUERY_COMMAND, (evt, message) => debounceHandleQueryCommand(evt, message, plugins));
Expand Down
34 changes: 17 additions & 17 deletions app/main/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ const { MAX_RESULTS } = require('../constants');
* @param {String} directory - The directory to read
* @return {Promise} - An array of plugin paths
*/
exports.loadPluginsInPath = directory => new Promise(resolve => {
exports.loadPluginsInPath = directory => new Promise((resolve) => {
const loaded = [];
fs.readdir(directory, (err, plugins) => {
if (plugins && plugins.length) {
plugins.forEach(plugin => {
plugins.forEach((plugin) => {
if (plugin !== '.DS_Store') {
const pluginPath = path.resolve(directory, plugin);
loaded.push(pluginPath);
Expand All @@ -35,7 +35,7 @@ exports.loadPluginsInPath = directory => new Promise(resolve => {
*
* @param
*/
exports.isCorePlugin = directory => {
exports.isCorePlugin = (directory) => {
const dirname = path.dirname(directory);
if (dirname === PLUGIN_PATH) {
return false;
Expand All @@ -49,7 +49,7 @@ exports.isCorePlugin = directory => {
* @param {String} directory - A plugin directory
* @return {Boolean} - True if it is a theme
*/
exports.isPluginATheme = directory => {
exports.isPluginATheme = (directory) => {
try {
const pkg = require(path.resolve(directory, 'package.json')); // eslint-disable-line global-require
// TODO: change the mechanism?
Expand All @@ -73,9 +73,9 @@ exports.isPluginATheme = directory => {
* @param {String} plugin - The plugin object
* @return {Promise} - A modified clone of the plugin object
*/
exports.applyModuleProperties = plugin => new Promise(resolve => {
exports.applyModuleProperties = plugin => new Promise((resolve) => {
const plistPath = path.resolve(plugin.path, 'info.plist');
fs.access(plistPath, fs.constants.R_OK, err1 => {
fs.access(plistPath, fs.constants.R_OK, (err1) => {
if (err1) {
// retrieve the keyword and action from the plugin
// eslint-disable-next-line global-require
Expand All @@ -98,7 +98,7 @@ exports.applyModuleProperties = plugin => new Promise(resolve => {
const plistData = plist.parse(data);
let keyword = '';
let action = '';
plistData.objects.forEach(o => {
plistData.objects.forEach((o) => {
if (o.type === 'alfred.workflow.input.scriptfilter') {
keyword = o.config.keyword;
} else if (o.type === 'alfred.workflow.action.openurl') {
Expand All @@ -125,10 +125,10 @@ exports.applyModuleProperties = plugin => new Promise(resolve => {
* @param {String[]} directories - An array of directories to load
* @return {Promise} - Resolves a list of plugin objects
*/
exports.loadPlugins = (directories) => new Promise(resolve => {
exports.loadPlugins = directories => new Promise((resolve) => {
const prom = directories.map(exports.loadPluginsInPath);
Promise.all(prom)
.then(pluginSets => {
.then((pluginSets) => {
const allPlugins = pluginSets
// merge promise results
.reduce((a, b) => a.concat(b))
Expand Down Expand Up @@ -158,7 +158,7 @@ exports.loadPlugins = (directories) => new Promise(resolve => {
* @param {Object} plugin - The plugin object data
* @return {Object}
*/
exports.connectItems = (items, plugin) => items.map(i => {
exports.connectItems = (items, plugin) => items.map((i) => {
const icon = {
path: '',
};
Expand Down Expand Up @@ -196,7 +196,7 @@ exports.connectItems = (items, plugin) => items.map(i => {
* @param {String[]} args - An array of arguments
* @return {Promise} - An array of results
*/
exports.queryResults = (plugin, args) => new Promise(resolve => {
exports.queryResults = (plugin, args) => new Promise((resolve) => {
const query = args.join(' ');
// process based on the schema
switch (plugin.schema) {
Expand All @@ -209,7 +209,7 @@ exports.queryResults = (plugin, args) => new Promise(resolve => {
};
const child = fork(plugin.path, args, options);
let msg = '';
child.stdout.on('data', data => {
child.stdout.on('data', (data) => {
if (data) {
msg += data.toString();
}
Expand All @@ -236,7 +236,7 @@ exports.queryResults = (plugin, args) => new Promise(resolve => {
: pluginObj.execute;

if (output) {
Promise.resolve(output).then(i => {
Promise.resolve(output).then((i) => {
const items = exports.connectItems(i.items, plugin);
resolve(items);
});
Expand All @@ -257,7 +257,7 @@ exports.queryResults = (plugin, args) => new Promise(resolve => {
* @param {String[]} keyword - The query keyword
* @return {Promise} - An array of results
*/
exports.queryHelper = (plugin, keyword) => new Promise(resolve => {
exports.queryHelper = (plugin, keyword) => new Promise((resolve) => {
let items = [];
if (!plugin.helper) {
resolve(items);
Expand All @@ -269,7 +269,7 @@ exports.queryHelper = (plugin, keyword) => new Promise(resolve => {
if (typeof plugin.helper === 'function') {
helperItem = plugin.helper(keyword);
}
Promise.resolve(helperItem).then(item => {
Promise.resolve(helperItem).then((item) => {
items.push(item);
items = exports.connectItems(items, plugin);
resolve(items);
Expand All @@ -286,7 +286,7 @@ exports.queryHelper = (plugin, keyword) => new Promise(resolve => {
* @param {Object} plugin - The plugin object
* @return {Promise} - Resolves to the rendered html string
*/
exports.retrieveItemDetails = (item, plugin) => new Promise(resolve => {
exports.retrieveItemDetails = (item, plugin) => new Promise((resolve) => {
// retrieve the rendered content
let type = 'html';
let content = '';
Expand All @@ -303,7 +303,7 @@ exports.retrieveItemDetails = (item, plugin) => new Promise(resolve => {
}
}
// resolve and update the state
Promise.resolve(content).then(res => {
Promise.resolve(content).then((res) => {
let html = res;
if (type === 'md') {
const md = new MarkdownIt();
Expand Down
2 changes: 1 addition & 1 deletion app/main/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { THEME_PATH } = require('../../utils/paths');
* @param {String} theme - The name of the theme
* @return {Promise} - The theme module
*/
exports.loadTheme = theme => new Promise(resolve => {
exports.loadTheme = theme => new Promise((resolve) => {
if (theme) {
const p = path.resolve(THEME_PATH, theme);
// eslint-disable-next-line global-require
Expand Down
10 changes: 4 additions & 6 deletions app/renderer/src/components/Icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ const iconImgText = compose(
}),
);

const Icon = ({ icon }) => {
let src = '';
switch (icon.type) {
const Icon = (props) => {
switch (props.icon.type) {
case 'text':
return <span {...iconImgText} role="presentation">{icon.letter}</span>;
return <span {...iconImgText} role="presentation">{props.icon.letter}</span>;
case 'file':
// no break
default: // eslint-disable-line no-fallthrough
src = icon.path;
return <img {...iconImg} src={src} role="presentation" />;
return <img {...iconImg} src={props.icon.path} role="presentation" />;
}
};

Expand Down
2 changes: 1 addition & 1 deletion app/renderer/src/components/QueryField.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const QueryField = class extends Component {
return (
<div {...base}>
<input
ref={c => { this.input = c && c; }}
ref={(c) => { this.input = c && c; }}
onChange={onChange}
value={value}
{...styles}
Expand Down
18 changes: 13 additions & 5 deletions app/renderer/src/components/ResultList.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,24 @@ const shown = style({

const ResultList = class extends Component {
render() {
const props = this.props;
// Retrieve an array of <ResultItemContainer /> containers
const getResultItems = (results, selectedIndex, theme) => results.map((item, key) => <ResultItemContainer key={key} theme={theme} item={item} selected={selectedIndex === key} />);
const getResultItems = (results, selectedIndex, theme) => results.map(
(item, key) => (
<ResultItemContainer
key={key}
theme={theme}
item={item}
selected={selectedIndex === key}
/>
)
);
// get current item
const currItem = props.results[props.selectedIndex];
const currItem = this.props.results[this.props.selectedIndex];

return (
<div {...style({ position: 'relative', paddingTop: 15, paddingBottom: 15 })}>
<ol {...compose(base, props.results.length && shown)} ref={c => { this.c = c; }}>
{getResultItems(props.results, props.selectedIndex, props.theme)}
<ol {...compose(base, this.props.results.length && shown)} ref={(c) => { this.c = c; }}>
{getResultItems(this.props.results, this.props.selectedIndex, this.props.theme)}
</ol>
{currItem && <ResultDetailsContainer item={currItem} />}
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/src/containers/QueryFieldContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const QueryFieldContainer = class extends Component {
const { theme, q } = this.props;
return (
<QueryField
ref={c => { this.queryField = c; }}
ref={(c) => { this.queryField = c; }}
value={q}
onChange={this.handleChange}
theme={theme}
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/src/containers/ResultListContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const ResultListContainer = class extends Component {
if (results.length) {
return (
<ResultList
ref={c => { this.c = c; }}
ref={(c) => { this.c = c; }}
theme={theme}
results={results}
selectedIndex={selectedIndex}
Expand Down