Add prettier

This commit is contained in:
Ken-Håvard Lieng 2018-04-06 01:46:22 +02:00
parent 0cbbc1b8ff
commit b176b79144
46 changed files with 832 additions and 544 deletions

View file

@ -50,7 +50,7 @@ export default class Socket {
this.retry();
};
this.ws.onmessage = (e) => {
this.ws.onmessage = e => {
this.setTimeoutPing();
const msg = JSON.parse(e.data);

View file

@ -2,55 +2,40 @@ import React from 'react';
import linkify from '../linkify';
describe('linkify()', () => {
const proto = href => href.indexOf('http') !== 0 ? `http://${href}` : href;
const linkTo = href => <a href={proto(href)} rel="noopener noreferrer" target="_blank">{href}</a>;
const proto = href => (href.indexOf('http') !== 0 ? `http://${href}` : href);
const linkTo = href => (
<a href={proto(href)} rel="noopener noreferrer" target="_blank">
{href}
</a>
);
it('returns the arg when no matches are found', () => [
null,
undefined,
10,
false,
true,
'just some text',
''
].forEach(input => expect(linkify(input)).toBe(input)));
it('returns the arg when no matches are found', () =>
[null, undefined, 10, false, true, 'just some text', ''].forEach(input =>
expect(linkify(input)).toBe(input)
));
it('linkifies text', () => Object.entries({
'google.com': linkTo('google.com'),
'google.com stuff': [
linkTo('google.com'),
' stuff'
],
'cake google.com stuff': [
'cake ',
linkTo('google.com'),
' stuff'
],
'cake google.com stuff https://google.com': [
'cake ',
linkTo('google.com'),
' stuff ',
linkTo('https://google.com')
],
'cake google.com stuff pie https://google.com ': [
'cake ',
linkTo('google.com'),
' stuff pie ',
linkTo('https://google.com'),
' '
],
' google.com': [
' ',
linkTo('google.com')
],
'google.com ': [
linkTo('google.com'),
' '
],
'/google.com?': [
'/',
linkTo('google.com'),
'?'
]
}).forEach(([ input, expected ]) => expect(linkify(input)).toEqual(expected)));
it('linkifies text', () =>
Object.entries({
'google.com': linkTo('google.com'),
'google.com stuff': [linkTo('google.com'), ' stuff'],
'cake google.com stuff': ['cake ', linkTo('google.com'), ' stuff'],
'cake google.com stuff https://google.com': [
'cake ',
linkTo('google.com'),
' stuff ',
linkTo('https://google.com')
],
'cake google.com stuff pie https://google.com ': [
'cake ',
linkTo('google.com'),
' stuff pie ',
linkTo('https://google.com'),
' '
],
' google.com': [' ', linkTo('google.com')],
'google.com ': [linkTo('google.com'), ' '],
'/google.com?': ['/', linkTo('google.com'), '?']
}).forEach(([input, expected]) =>
expect(linkify(input)).toEqual(expected)
));
});

View file

@ -8,7 +8,10 @@ export function normalizeChannel(channel) {
return channel;
}
return channel.split('#').join('').toLowerCase();
return channel
.split('#')
.join('')
.toLowerCase();
}
export function isChannel(name) {

View file

@ -30,12 +30,19 @@ export default function linkify(text) {
}
result.push(
<a target="_blank" rel="noopener noreferrer" href={match.getAnchorHref()}>
<a
target="_blank"
rel="noopener noreferrer"
href={match.getAnchorHref()}
>
{match.matchedText}
</a>
);
} else if (typeof result[result.length - 1] === 'string') {
result[result.length - 1] += text.slice(pos, match.offset + match.matchedText.length);
result[result.length - 1] += text.slice(
pos,
match.offset + match.matchedText.length
);
} else {
result.push(text.slice(pos, match.offset + match.matchedText.length));
}

View file

@ -18,7 +18,13 @@ export function findBreakpoints(text) {
return breakpoints;
}
export function messageHeight(message, wrapWidth, charWidth, indent = 0, windowWidth) {
export function messageHeight(
message,
wrapWidth,
charWidth,
indent = 0,
windowWidth
) {
let pad = (6 + (message.from ? message.from.length + 1 : 0)) * charWidth;
let height = lineHeight + 8;
@ -26,7 +32,7 @@ export function messageHeight(message, wrapWidth, charWidth, indent = 0, windowW
wrapWidth -= userListWidth;
}
if (pad + (message.length * charWidth) < wrapWidth) {
if (pad + message.length * charWidth < wrapWidth) {
return height;
}
@ -35,7 +41,7 @@ export function messageHeight(message, wrapWidth, charWidth, indent = 0, windowW
let prevPos = 0;
for (let i = 0; i < breaks.length; i++) {
if (pad + ((breaks[i].end - prevBreak) * charWidth) >= wrapWidth) {
if (pad + (breaks[i].end - prevBreak) * charWidth >= wrapWidth) {
prevBreak = prevPos;
pad = indent;
height += lineHeight;
@ -44,7 +50,7 @@ export function messageHeight(message, wrapWidth, charWidth, indent = 0, windowW
prevPos = breaks[i].next;
}
if (pad + ((message.length - prevBreak) * charWidth) >= wrapWidth) {
if (pad + (message.length - prevBreak) * charWidth >= wrapWidth) {
height += lineHeight;
}

View file

@ -99,7 +99,10 @@ export default function initRouter(routes, store) {
history.listen(location => {
const nextMatch = match(patterns, location);
if (nextMatch && nextMatch.location.pathname !== matched.location.pathname) {
if (
nextMatch &&
nextMatch.location.pathname !== matched.location.pathname
) {
matched = nextMatch;
store.dispatch(matched);
}