From 89afcfd897775e8a0b664c2e8782ba85be814adf Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Fri, 23 Jun 2017 17:35:07 +0100 Subject: [PATCH] Linting --- src/ComposerHistoryManager.js | 4 ++-- src/RichText.js | 2 +- src/autocomplete/CommandProvider.js | 4 ++-- src/autocomplete/FuzzyMatcher.js | 14 ++++++++------ src/autocomplete/QueryMatcher.js | 4 +++- src/components/structures/UserSettings.js | 8 +++++--- src/components/views/rooms/MessageComposerInput.js | 4 ++-- 7 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/ComposerHistoryManager.js b/src/ComposerHistoryManager.js index face75ea8a..ef9232c684 100644 --- a/src/ComposerHistoryManager.js +++ b/src/ComposerHistoryManager.js @@ -21,14 +21,14 @@ class HistoryItem { let {message} = this; if (format === 'markdown') { if (this.format === 'html') { - message = _flow([RichText.HTMLtoContentState, RichText.stateToMarkdown])(message); + message = _flow([RichText.htmlToContentState, RichText.stateToMarkdown])(message); } return ContentState.createFromText(message); } else { if (this.format === 'markdown') { message = new Markdown(message).toHTML(); } - return RichText.HTMLtoContentState(message); + return RichText.htmlToContentState(message); } } } diff --git a/src/RichText.js b/src/RichText.js index 6edde23129..f2f2d533a8 100644 --- a/src/RichText.js +++ b/src/RichText.js @@ -50,7 +50,7 @@ export const contentStateToHTML = (contentState: ContentState) => { }); }; -export function HTMLtoContentState(html: string): ContentState { +export function htmlToContentState(html: string): ContentState { return ContentState.createFromBlockArray(convertFromHTML(html)); } diff --git a/src/autocomplete/CommandProvider.js b/src/autocomplete/CommandProvider.js index c54d0fd49e..9ae3a7badb 100644 --- a/src/autocomplete/CommandProvider.js +++ b/src/autocomplete/CommandProvider.js @@ -77,7 +77,7 @@ const COMMANDS = [ command: '/op', args: ' []', description: 'Define the power level of a user', - } + }, ]; const COMMAND_RE = /(^\/\w*)/g; @@ -96,7 +96,7 @@ export default class CommandProvider extends AutocompleteProvider { let completions = []; const {command, range} = this.getCurrentCommand(query, selection); if (command) { - completions = this.matcher.match(command[0]).map(result => { + completions = this.matcher.match(command[0]).map((result) => { return { completion: result.command + ' ', component: (, keys: Array): KeyMap { const keyMap = new KeyMap(); @@ -48,7 +50,7 @@ class FuzzyMatcher { keyMap.objectMap = map; keyMap.priorityMap = priorities; - keyMap.keys = _sortBy(_keys(map), [value => priorities[value]]); + keyMap.keys = _sortBy(_keys(map), [(value) => priorities[value]]); return keyMap; } @@ -74,15 +76,15 @@ class FuzzyMatcher { match(query: String): Array { const candidates = this.matcher.transduce(query, this.options.distance || DEFAULT_DISTANCE); // TODO FIXME This is hideous. Clean up when possible. - const val = _sortedUniq(_sortBy(_flatMap(candidates, candidate => { - return this.keyMap.objectMap[candidate[0]].map(value => { + const val = _sortedUniq(_sortBy(_flatMap(candidates, (candidate) => { + return this.keyMap.objectMap[candidate[0]].map((value) => { return { distance: candidate[1], ...value, }; }); }), - [candidate => candidate.distance, candidate => this.keyMap.priorityMap[candidate]])); + [(candidate) => candidate.distance, (candidate) => this.keyMap.priorityMap[candidate]])); console.log(val); return val; } diff --git a/src/autocomplete/QueryMatcher.js b/src/autocomplete/QueryMatcher.js index b4c27a7179..ead7ea8047 100644 --- a/src/autocomplete/QueryMatcher.js +++ b/src/autocomplete/QueryMatcher.js @@ -14,13 +14,15 @@ class KeyMap { export default class QueryMatcher { /** - * Given an array of objects and keys, returns a KeyMap + * @param {object[]} objects the objects to perform a match on + * @param {string[]} keys an array of keys within each object to match on * Keys can refer to object properties by name and as in JavaScript (for nested properties) * * To use, simply presort objects by required criteria, run through this function and create a QueryMatcher with the * resulting KeyMap. * * TODO: Handle arrays and objects (Fuse did this, RoomProvider uses it) + * @return {KeyMap} */ static valuesToKeyMap(objects: Array, keys: Array): KeyMap { const keyMap = new KeyMap(); diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index d31bd7fc7c..9171b081ab 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -642,6 +642,10 @@ module.exports = React.createClass({ }, _renderUserInterfaceSettings: function() { + // TODO: this ought to be a separate component so that we don't need + // to rebind the onChange each time we render + const onChange = (e) => + UserSettingsStore.setLocalSetting('autocompleteDelay', + e.target.value); return (

{ _t("User Interface") }

@@ -657,9 +661,7 @@ module.exports = React.createClass({ UserSettingsStore.setLocalSetting('autocompleteDelay', + e.target.value) - } + onChange={onChange} /> diff --git a/src/components/views/rooms/MessageComposerInput.js b/src/components/views/rooms/MessageComposerInput.js index 09183bfab6..4d7c0f7a80 100644 --- a/src/components/views/rooms/MessageComposerInput.js +++ b/src/components/views/rooms/MessageComposerInput.js @@ -201,7 +201,7 @@ export default class MessageComposerInput extends React.Component { let {body, formatted_body} = payload.event.getContent(); formatted_body = formatted_body || escape(body); if (formatted_body) { - let content = RichText.HTMLtoContentState(`
${formatted_body}
`); + let content = RichText.htmlToContentState(`
${formatted_body}
`); if (!this.state.isRichtextEnabled) { content = ContentState.createFromText(RichText.stateToMarkdown(content)); } @@ -350,7 +350,7 @@ export default class MessageComposerInput extends React.Component { let contentState = null; if (enabled) { const md = new Markdown(this.state.editorState.getCurrentContent().getPlainText()); - contentState = RichText.HTMLtoContentState(md.toHTML()); + contentState = RichText.htmlToContentState(md.toHTML()); } else { let markdown = RichText.stateToMarkdown(this.state.editorState.getCurrentContent()); if (markdown[markdown.length - 1] === '\n') {