From e1e8da4b2aa3f79a47149bae75f13dbaf6c221d3 Mon Sep 17 00:00:00 2001 From: Pavel Mineev Date: Fri, 29 Jan 2021 00:23:29 +0300 Subject: [PATCH] use parens for arrow funcs always --- frontend/.babelrc.js | 2 +- frontend/.prettierrc.js | 1 - frontend/app/common/api.ts | 4 +-- frontend/app/common/fetcher.test.ts | 12 ++++---- frontend/app/common/fetcher.ts | 6 ++-- .../app/components/auth-panel/auth-panel.tsx | 10 +++---- frontend/app/components/auth/auth.tsx | 6 ++-- .../comment-form__subscribe-by-rss.test.tsx | 2 +- .../components/comment-form/comment-form.tsx | 10 +++---- .../components/comment-form/text-expander.tsx | 2 +- .../app/components/comment/comment.test.tsx | 14 ++++----- frontend/app/components/comment/comment.tsx | 10 +++---- .../components/comment/connected-comment.tsx | 8 ++--- frontend/app/components/dropdown/dropdown.tsx | 2 +- .../list-comments/list-comments.tsx | 2 +- .../app/components/root/in-view/in-view.tsx | 4 +-- frontend/app/components/root/root.tsx | 10 +++---- frontend/app/components/settings/settings.tsx | 8 ++--- frontend/app/components/thread/thread.tsx | 4 +-- .../user-info/last-comments-list.tsx | 2 +- frontend/app/components/with-theme/index.tsx | 2 +- frontend/app/counter.ts | 2 +- frontend/app/deleteme.ts | 4 +-- frontend/app/embed.ts | 12 ++++---- frontend/app/last-comments.tsx | 2 +- frontend/app/store/comments/actions.ts | 18 +++++------ frontend/app/store/comments/reducers.ts | 6 ++-- frontend/app/store/provider/actions.ts | 4 +-- frontend/app/store/theme/actions.ts | 2 +- frontend/app/store/thread/utils.ts | 4 +-- frontend/app/store/user-info/actions.ts | 2 +- frontend/app/store/user/actions.ts | 30 +++++++++---------- frontend/app/store/user/reducers.ts | 4 +-- frontend/app/utils/jwt.ts | 2 +- frontend/app/utils/loadLocale.ts | 20 ++++++------- frontend/app/utils/sleep.ts | 2 +- frontend/tasks/checkTranslation.js | 4 +-- frontend/tasks/generateDictionary.js | 4 +-- frontend/tasks/localeLoadTemplate.js | 2 +- frontend/webpack.config.js | 2 +- 40 files changed, 121 insertions(+), 126 deletions(-) diff --git a/frontend/.babelrc.js b/frontend/.babelrc.js index 2104e039..a1f177ab 100644 --- a/frontend/.babelrc.js +++ b/frontend/.babelrc.js @@ -1,4 +1,4 @@ -const getPresetEnv = options => ['@babel/preset-env', options]; +const getPresetEnv = (options) => ['@babel/preset-env', options]; const preactPreset = [ '@babel/preset-react', { diff --git a/frontend/.prettierrc.js b/frontend/.prettierrc.js index 585d0f3f..f7757bd0 100644 --- a/frontend/.prettierrc.js +++ b/frontend/.prettierrc.js @@ -6,7 +6,6 @@ module.exports = { singleQuote: true, trailingComma: 'es5', bracketSpacing: true, - arrowParens: 'avoid', overrides: [ { files: ['*.html'], diff --git a/frontend/app/common/api.ts b/frontend/app/common/api.ts index c469b31f..3026bf73 100644 --- a/frontend/app/common/api.ts +++ b/frontend/app/common/api.ts @@ -53,7 +53,7 @@ export const logIn = (provider: AuthProvider): Promise => { clearInterval(checkInterval); getUser() - .then(user => { + .then((user) => { resolve(user); }) .catch(() => { @@ -263,7 +263,7 @@ export const uploadImage = (image: File): Promise => { contentType: 'multipart/form-data', body: data, }) - .then(resp => ({ + .then((resp) => ({ name: image.name, size: image.size, type: image.type, diff --git a/frontend/app/common/fetcher.test.ts b/frontend/app/common/fetcher.test.ts index 0da74117..019f5e10 100644 --- a/frontend/app/common/fetcher.test.ts +++ b/frontend/app/common/fetcher.test.ts @@ -17,10 +17,10 @@ describe('fetcher', () => { return fetcher .get('/api/some') - .then(data => { + .then((data) => { throw new Error('Request should be failed'); }) - .catch(e => { + .catch((e) => { expect(e.code).toBe(2); expect(e.error).toBe('you just cant'); expect(e.details).toBe('you just cant at all'); @@ -39,10 +39,10 @@ describe('fetcher', () => { return fetcher .get('/api/some') - .then(data => { + .then((data) => { throw new Error('Request should be failed'); }) - .catch(e => { + .catch((e) => { expect(e.code).toBe(401); expect(e.error).toBe('Not authorized.'); }); @@ -61,10 +61,10 @@ describe('fetcher', () => { return fetcher .get({ url: '/api/some', logError: false }) - .then(data => { + .then((data) => { throw new Error('Request should be failed'); }) - .catch(e => { + .catch((e) => { expect(e.code).toBe(0); expect(e.error).toBe('Something went wrong.'); }); diff --git a/frontend/app/common/fetcher.ts b/frontend/app/common/fetcher.ts index 9b76992c..fb8caaef 100644 --- a/frontend/app/common/fetcher.ts +++ b/frontend/app/common/fetcher.ts @@ -83,7 +83,7 @@ const fetcher = methods.reduce>((acc, method) => { } return fetch(rurl, parameters) - .then(res => { + .then((res) => { const date = (res.headers.has('date') && res.headers.get('date')) || ''; const timestamp = isNaN(Date.parse(date)) ? 0 : Date.parse(date); const timeDiff = (new Date().getTime() - timestamp) / 1000; @@ -104,7 +104,7 @@ const fetcher = methods.reduce>((acc, method) => { throw new RequestError(descriptor.defaultMessage, res.status); } - return res.text().then(text => { + return res.text().then((text) => { let err; try { err = JSON.parse(text); @@ -125,7 +125,7 @@ const fetcher = methods.reduce>((acc, method) => { return res.text(); }) - .catch(e => { + .catch((e) => { if (isFailedFetch(e)) { throw new RequestError(e.message, -2); } diff --git a/frontend/app/components/auth-panel/auth-panel.tsx b/frontend/app/components/auth-panel/auth-panel.tsx index 92989876..81d0d63f 100644 --- a/frontend/app/components/auth-panel/auth-panel.tsx +++ b/frontend/app/components/auth-panel/auth-panel.tsx @@ -193,7 +193,7 @@ export class AuthPanel extends Component { {' '} - {sortArray.find(x => 'selected' in x && x.selected!)!.label} + {sortArray.find((x) => 'selected' in x && x.selected!)!.label} @@ -562,7 +562,7 @@ class Comment extends Component { time: new Date(props.data.time), orig: isEditing ? props.data.orig && - props.data.orig.replace(/&[#A-Za-z0-9]+;/gi, entity => { + props.data.orig.replace(/&[#A-Za-z0-9]+;/gi, (entity) => { const span = document.createElement('span'); span.innerHTML = entity; return span.innerText; @@ -702,7 +702,7 @@ class Comment extends Component { href={`${o.locator.url}#${COMMENT_NODE_CLASSNAME_PREFIX}${o.pid}`} aria-label={goToParentMessage} title={goToParentMessage} - onClick={e => this.scrollToParent(e)} + onClick={(e) => this.scrollToParent(e)} > {' '} diff --git a/frontend/app/components/comment/connected-comment.tsx b/frontend/app/components/comment/connected-comment.tsx index c0f9895c..b01d39a4 100644 --- a/frontend/app/components/comment/connected-comment.tsx +++ b/frontend/app/components/comment/connected-comment.tsx @@ -40,7 +40,7 @@ const mapStateToProps = (state: StoreState, cprops: { data: CommentType }) => { const props: ProvidedProps = { editMode: getCommentMode(cprops.data.id)(state), user: state.user, - isUserBanned: cprops.data.user.block || state.bannedUsers.find(u => u.id === cprops.data.user.id) !== undefined, + isUserBanned: cprops.data.user.block || state.bannedUsers.find((u) => u.id === cprops.data.user.id) !== undefined, post_info: state.info, isCommentsDisabled: state.info.read_only || false, theme: state.theme, @@ -64,9 +64,9 @@ export const boundActions = bindActions({ setVerifiedStatus, }); -export const ConnectedComment: FunctionComponent< - Omit -> = props => { +export const ConnectedComment: FunctionComponent> = ( + props +) => { const providedProps = mapStateToProps(useStore().getState(), props); const actions = useActions(boundActions); const intl = useIntl(); diff --git a/frontend/app/components/dropdown/dropdown.tsx b/frontend/app/components/dropdown/dropdown.tsx index cedf783a..8fbf36ee 100644 --- a/frontend/app/components/dropdown/dropdown.tsx +++ b/frontend/app/components/dropdown/dropdown.tsx @@ -91,7 +91,7 @@ export class Dropdown extends Component { const windowHeight = window.innerHeight; const dcBottom = (() => { // TODO: use ref - const dc = Array.from(this.rootNode.current.children).find(c => c.classList.contains('dropdown__content')); + const dc = Array.from(this.rootNode.current.children).find((c) => c.classList.contains('dropdown__content')); if (!dc) return 0; const rect = dc.getBoundingClientRect(); return window.scrollY + Math.abs(rect.top) + dc.scrollHeight + 10; diff --git a/frontend/app/components/list-comments/list-comments.tsx b/frontend/app/components/list-comments/list-comments.tsx index 96c000a9..4a608f27 100644 --- a/frontend/app/components/list-comments/list-comments.tsx +++ b/frontend/app/components/list-comments/list-comments.tsx @@ -16,7 +16,7 @@ const ListComments: FunctionComponent = ({ comments = [] }) = return (
- {comments.map(comment => ( + {comments.map((comment) => ( void>(); observer = new window.IntersectionObserver( - entries => { - entries.forEach(e => { + (entries) => { + entries.forEach((e) => { const setInView = instanceMap.get(e.target); if (!setInView) return; setInView(e.isIntersecting); diff --git a/frontend/app/components/root/root.tsx b/frontend/app/components/root/root.tsx index fedf6747..4f79f430 100644 --- a/frontend/app/components/root/root.tsx +++ b/frontend/app/components/root/root.tsx @@ -49,14 +49,14 @@ const mapStateToProps = (state: StoreState) => ({ user: state.user, childToParentComments: Object.entries(state.comments.childComments).reduce( (accumulator: Record, [key, children]) => { - children.forEach(child => (accumulator[child] = key)); + children.forEach((child) => (accumulator[child] = key)); return accumulator; }, {} ), collapsedThreads: state.collapsedThreads, topComments: state.comments.topComments, - pinnedComments: state.comments.pinnedComments.map(id => state.comments.allComments[id]).filter(c => !c.hidden), + pinnedComments: state.comments.pinnedComments.map((id) => state.comments.allComments[id]).filter((c) => !c.hidden), theme: state.theme, info: state.info, hiddenUsers: state.hiddenUsers, @@ -166,7 +166,7 @@ export class Root extends Component { if (!document.querySelector(hash)) { const ids = getCollapsedParents(hash, this.props.childToParentComments, this.props.collapsedThreads); - ids.forEach(id => this.props.setCollapse(id, false)); + ids.forEach((id) => this.props.setCollapse(id, false)); } setTimeout(() => { @@ -284,7 +284,7 @@ export class Root extends Component { role="region" aria-label={this.props.intl.formatMessage(messages.pinnedComments)} > - {this.props.pinnedComments.map(comment => ( + {this.props.pinnedComments.map((comment) => ( { {(IS_MOBILE && commentsShown < this.props.topComments.length ? this.props.topComments.slice(0, commentsShown) : this.props.topComments - ).map(id => ( + ).map((id) => ( { block = (user: BlockedUser) => { if (!window.confirm(this.props.intl.formatMessage(messages.blockUser, { userName: user.name }))) return; this.setState({ - unblockedUsers: this.state.unblockedUsers.filter(x => x !== user.id), + unblockedUsers: this.state.unblockedUsers.filter((x) => x !== user.id), }); this.props.blockUser(user.id, user.name, 'permanently'); }; @@ -78,7 +78,7 @@ export default class Settings extends Component { hide = (user: User) => { this.setState({ - unhiddenUsers: this.state.unhiddenUsers.filter(x => x !== user.id), + unhiddenUsers: this.state.unhiddenUsers.filter((x) => x !== user.id), }); this.props.hideUser(user); }; @@ -114,7 +114,7 @@ export default class Settings extends Component { )} {!!hiddenUsersList.length && (
    - {hiddenUsersList.map(user => { + {hiddenUsersList.map((user) => { const isUserUnhidden = unhiddenUsers.includes(user.id); return ( @@ -163,7 +163,7 @@ export default class Settings extends Component { {!!blockedUsers.length && (
      - {blockedUsers.map(user => { + {blockedUsers.map((user) => { const isUserUnblocked = unblockedUsers.includes(user.id); return ( diff --git a/frontend/app/components/thread/thread.tsx b/frontend/app/components/thread/thread.tsx index 0006e3cd..4b8a3584 100644 --- a/frontend/app/components/thread/thread.tsx +++ b/frontend/app/components/thread/thread.tsx @@ -52,7 +52,7 @@ export const Thread: FunctionComponent = ({ id, level, mix, getPreview }) aria-expanded={!collapsed} > - {inviewProps => ( + {(inviewProps) => ( = ({ id, level, mix, getPreview }) {!collapsed && childs && !!childs.length && - childs.map(currentId => ( + childs.map((currentId) => ( ))} {level < 6 && ( diff --git a/frontend/app/components/user-info/last-comments-list.tsx b/frontend/app/components/user-info/last-comments-list.tsx index 0036f010..792bd6fb 100644 --- a/frontend/app/components/user-info/last-comments-list.tsx +++ b/frontend/app/components/user-info/last-comments-list.tsx @@ -15,7 +15,7 @@ const LastCommentsList = ({ comments, isLoading }: { comments: CommentType[]; is return ( <> - {comments.map(comment => ( + {comments.map((comment) => ( state.theme; * Connects redux theme property to component's */ function withTheme

      (PlainComponent: ComponentType

      ) { - const C: FunctionComponent> = props => { + const C: FunctionComponent> = (props) => { const theme = useSelector(themeSelector); // eslint-disable-next-line @typescript-eslint/no-explicit-any return ; diff --git a/frontend/app/counter.ts b/frontend/app/counter.ts index a710b7b2..491f37fe 100644 --- a/frontend/app/counter.ts +++ b/frontend/app/counter.ts @@ -33,7 +33,7 @@ function init(): void { if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { try { const res = JSON.parse(this.responseText) as { url: string; count: number }[]; - res.forEach(item => map[item.url].map(n => (n.innerHTML = item.count.toString(10)))); + res.forEach((item) => map[item.url].map((n) => (n.innerHTML = item.count.toString(10)))); } catch (e) {} } }; diff --git a/frontend/app/deleteme.ts b/frontend/app/deleteme.ts index 0d041f54..1e05824d 100644 --- a/frontend/app/deleteme.ts +++ b/frontend/app/deleteme.ts @@ -20,14 +20,14 @@ async function init(): Promise { return; } - getUser().then(user => { + getUser().then((user) => { if (!user || !user.admin) { handleNotAuthorizedError(node); return; } approveDeleteMe(token).then( - data => { + (data) => { node.innerHTML = `

      User deleted successfully

      ${JSON.stringify(data, null, 4)}
      diff --git a/frontend/app/embed.ts b/frontend/app/embed.ts index 1ef8c820..369d9289 100644 --- a/frontend/app/embed.ts +++ b/frontend/app/embed.ts @@ -76,9 +76,9 @@ function createInstance(config: typeof window.remark_config) { config.url = (config.url || `${window.location.origin}${window.location.pathname}`).split('#')[0]; const query = Object.keys(config) - .filter(key => key !== '__colors__') + .filter((key) => key !== '__colors__') .map( - key => + (key) => `${encodeURIComponent(key)}=${encodeURIComponent( config[key as keyof Omit] as string | number | boolean )}` @@ -97,7 +97,7 @@ function createInstance(config: typeof window.remark_config) { const titleElement = document.querySelector('title'); if (titleElement) { - titleObserver = new MutationObserver(mutations => postTitleToIframe(mutations[0].target.textContent!)); + titleObserver = new MutationObserver((mutations) => postTitleToIframe(mutations[0].target.textContent!)); titleObserver.observe(titleElement, { subtree: true, characterData: true, @@ -228,14 +228,14 @@ function createInstance(config: typeof window.remark_config) { document.removeEventListener('keydown', this.onKeyDown); }, delay: null, - events: ['', 'webkit', 'moz', 'MS', 'o'].map(prefix => (prefix ? `${prefix}TransitionEnd` : 'transitionend')), + events: ['', 'webkit', 'moz', 'MS', 'o'].map((prefix) => (prefix ? `${prefix}TransitionEnd` : 'transitionend')), onAnimationClose() { const el = this.node!; if (!this.node) { return; } this.delay = window.setTimeout(this.animationStop, 1000); - this.events.forEach(event => el.addEventListener(event, this.animationStop, false)); + this.events.forEach((event) => el.addEventListener(event, this.animationStop, false)); }, onKeyDown(e) { // ESCAPE key pressed @@ -252,7 +252,7 @@ function createInstance(config: typeof window.remark_config) { clearTimeout(t.delay); t.delay = null; } - t.events.forEach(event => t.node!.removeEventListener(event, t.animationStop, false)); + t.events.forEach((event) => t.node!.removeEventListener(event, t.animationStop, false)); return t.remove(); }, remove() { diff --git a/frontend/app/last-comments.tsx b/frontend/app/last-comments.tsx index 7780abe1..57d90d1e 100644 --- a/frontend/app/last-comments.tsx +++ b/frontend/app/last-comments.tsx @@ -35,7 +35,7 @@ async function init(): Promise { throw new Error('Remark42: Site ID is undefined.'); } - (Array.from(nodes) as HTMLElement[]).forEach(node => { + (Array.from(nodes) as HTMLElement[]).forEach((node) => { const max = (node.dataset.max && parseInt(node.dataset.max, 10)) || max_last_comments || DEFAULT_LAST_COMMENTS_MAX; const locale = getLocale(window.remark_config); diff --git a/frontend/app/store/comments/actions.ts b/frontend/app/store/comments/actions.ts index 17fdf8e8..5e9e7d2a 100644 --- a/frontend/app/store/comments/actions.ts +++ b/frontend/app/store/comments/actions.ts @@ -18,7 +18,7 @@ import { setItem } from 'common/local-storage'; import { LS_SORT_KEY } from 'common/constants'; /** sets comments, and put pinned comments in cache */ -export const setComments = (comments: Node[]): StoreAction => dispatch => { +export const setComments = (comments: Node[]): StoreAction => (dispatch) => { dispatch({ type: COMMENTS_SET, comments, @@ -26,23 +26,21 @@ export const setComments = (comments: Node[]): StoreAction => dispatch => }; /** appends comment to tree */ -export const addComment = ( - text: string, - title: string, - pid?: Comment['id'] -): StoreAction> => async dispatch => { +export const addComment = (text: string, title: string, pid?: Comment['id']): StoreAction> => async ( + dispatch +) => { const comment = await api.addComment({ text, title, pid }); dispatch({ type: COMMENTS_APPEND, pid: pid || null, comment }); }; /** edits comment in tree */ -export const updateComment = (id: Comment['id'], text: string): StoreAction> => async dispatch => { +export const updateComment = (id: Comment['id'], text: string): StoreAction> => async (dispatch) => { const comment = await api.updateComment({ id, text }); dispatch({ type: COMMENTS_EDIT, comment }); }; /** edits comment in tree */ -export const putVote = (id: Comment['id'], value: number): StoreAction> => async dispatch => { +export const putVote = (id: Comment['id'], value: number): StoreAction> => async (dispatch) => { await api.putCommentVote({ id, value }); const comment = await api.getComment(id); dispatch({ type: COMMENTS_EDIT, comment }); @@ -85,7 +83,7 @@ export const fetchComments = (sort?: Sorting): StoreAction> => asy const data = await api.getPostComments(sort || comments.sort); dispatch({ type: COMMENTS_REQUEST_SUCCESS }); if (hiddenUsersIds.length > 0) { - data.comments = filterTree(data.comments, node => hiddenUsersIds.indexOf(node.comment.user.id) === -1); + data.comments = filterTree(data.comments, (node) => hiddenUsersIds.indexOf(node.comment.user.id) === -1); } dispatch(setComments(data.comments)); @@ -95,7 +93,7 @@ export const fetchComments = (sort?: Sorting): StoreAction> => asy }; /** sets mode for comment, either reply or edit */ -export const setCommentMode = (mode: StoreState['comments']['activeComment']): StoreAction => dispatch => { +export const setCommentMode = (mode: StoreState['comments']['activeComment']): StoreAction => (dispatch) => { if (mode !== null && mode.state === CommentMode.None) { mode = null; } diff --git a/frontend/app/store/comments/reducers.ts b/frontend/app/store/comments/reducers.ts index ddeb9072..22b0b8d5 100644 --- a/frontend/app/store/comments/reducers.ts +++ b/frontend/app/store/comments/reducers.ts @@ -30,7 +30,7 @@ export const topComments = ( case COMMENTS_SET: { return cmpRef( state, - action.comments.map(x => x.comment.id) + action.comments.map((x) => x.comment.id) ); } case COMMENTS_APPEND: { @@ -146,7 +146,7 @@ export const pinnedComments = ( ): Comment['id'][] => { switch (action.type) { case COMMENTS_SET: { - return getPinnedComments(action.comments).map(x => x.id); + return getPinnedComments(action.comments).map((x) => x.id); } case COMMENTS_EDIT: { const index = state.indexOf(action.comment.id); @@ -162,7 +162,7 @@ export const pinnedComments = ( case COMMENTS_PATCH: { if (!Object.prototype.hasOwnProperty.call(action.patch, 'pin')) return state; if (!action.patch.pin) { - return state.filter(x => action.ids.indexOf(x) === -1); + return state.filter((x) => action.ids.indexOf(x) === -1); } return [...state, ...action.ids].reduce((c, x) => { if (c.indexOf(x) === -1) { diff --git a/frontend/app/store/provider/actions.ts b/frontend/app/store/provider/actions.ts index 87710ae0..2cab2d15 100644 --- a/frontend/app/store/provider/actions.ts +++ b/frontend/app/store/provider/actions.ts @@ -6,7 +6,7 @@ const PROVIDER_LOCALSTORAGE_KEY = '__remarkProvider'; /** saves last login provider from localstorage and put to store */ export function updateProvider(payload: PROVIDER_UPDATE_ACTION['payload']): StoreAction { - return dispatch => { + return (dispatch) => { setItem(PROVIDER_LOCALSTORAGE_KEY, JSON.stringify(payload)); dispatch({ type: PROVIDER_UPDATE, @@ -17,7 +17,7 @@ export function updateProvider(payload: PROVIDER_UPDATE_ACTION['payload']): Stor /** restores last login provider from localstorage and put to store */ export function restoreProvider(): StoreAction { - return dispatch => { + return (dispatch) => { const payloadString = getItem(PROVIDER_LOCALSTORAGE_KEY); if (!payloadString) return; try { diff --git a/frontend/app/store/theme/actions.ts b/frontend/app/store/theme/actions.ts index 1fca40b6..f5077597 100644 --- a/frontend/app/store/theme/actions.ts +++ b/frontend/app/store/theme/actions.ts @@ -3,7 +3,7 @@ import { Theme } from 'common/types'; import { StoreAction } from '../'; import { THEME_SET } from './types'; -export const setTheme = (theme: Theme): StoreAction => dispatch => +export const setTheme = (theme: Theme): StoreAction => (dispatch) => dispatch({ type: THEME_SET, theme, diff --git a/frontend/app/store/thread/utils.ts b/frontend/app/store/thread/utils.ts index 3a6910de..537fabc2 100644 --- a/frontend/app/store/thread/utils.ts +++ b/frontend/app/store/thread/utils.ts @@ -23,8 +23,8 @@ export const getCollapsedComments = (): string[] => * @param info list of string of type "site-id_url_comment-id */ export const saveCollapsedComments = (siteId: string, url: string, info: Comment['id'][]): void => { - const data = info.map(i => `${siteId}_${url}_${i}`); - const notForThisPost = getFromLocalStorage().filter(entry => entry.indexOf(`${siteId}_${url}`) === -1); + const data = info.map((i) => `${siteId}_${url}_${i}`); + const notForThisPost = getFromLocalStorage().filter((entry) => entry.indexOf(`${siteId}_${url}`) === -1); const all = new Set([...notForThisPost, ...data]); localStorageSetItem(LS_COLLAPSE_KEY, JSON.stringify([...all])); }; diff --git a/frontend/app/store/user-info/actions.ts b/frontend/app/store/user-info/actions.ts index 50a14662..030571d9 100644 --- a/frontend/app/store/user-info/actions.ts +++ b/frontend/app/store/user-info/actions.ts @@ -5,7 +5,7 @@ import { userInfo } from 'common/user-info-settings'; import { StoreAction } from '../index'; import { USER_INFO_SET } from './types'; -export const fetchInfo = (): StoreAction> => async dispatch => { +export const fetchInfo = (): StoreAction> => async (dispatch) => { if (!userInfo.id) { return null; } diff --git a/frontend/app/store/user/actions.ts b/frontend/app/store/user/actions.ts index b58e2e70..2337c205 100644 --- a/frontend/app/store/user/actions.ts +++ b/frontend/app/store/user/actions.ts @@ -28,13 +28,13 @@ function setUser(user: User | null = null): USER_SET_ACTION { }; } -export const fetchUser = (): StoreAction> => async dispatch => { +export const fetchUser = (): StoreAction> => async (dispatch) => { const user = await api.getUser(); dispatch(setUser(user)); return user; }; -export const logIn = (provider: AuthProvider): StoreAction> => async dispatch => { +export const logIn = (provider: AuthProvider): StoreAction> => async (dispatch) => { const user = await api.logIn(provider); dispatch(updateProvider({ name: provider.name })); @@ -44,13 +44,13 @@ export const logIn = (provider: AuthProvider): StoreAction> return user; }; -export const logout = (): StoreAction> => async dispatch => { +export const logout = (): StoreAction> => async (dispatch) => { await api.logOut(); dispatch(unsetCommentMode()); dispatch(setUser()); }; -export const fetchBlockedUsers = (): StoreAction> => async dispatch => { +export const fetchBlockedUsers = (): StoreAction> => async (dispatch) => { const list = (await api.getBlocked()) || []; dispatch({ type: USER_BANLIST_SET, list }); @@ -58,11 +58,9 @@ export const fetchBlockedUsers = (): StoreAction> => asyn return list; }; -export const blockUser = ( - id: User['id'], - name: string, - ttl: BlockTTL -): StoreAction> => async dispatch => { +export const blockUser = (id: User['id'], name: string, ttl: BlockTTL): StoreAction> => async ( + dispatch +) => { await api.blockUser(id, ttl); dispatch({ type: USER_BAN, @@ -78,19 +76,19 @@ export const unblockUser = (id: User['id']): StoreAction> => async await api.unblockUser(id); dispatch({ type: USER_UNBAN, id }); const comments = Object.values(getState().comments.allComments); - const userComments = comments.filter(comment => comment.user.id === id); + const userComments = comments.filter((comment) => comment.user.id === id); if (!userComments.length) return; const user = comments[0].user; dispatch({ type: COMMENTS_PATCH, - ids: userComments.map(c => c.id), + ids: userComments.map((c) => c.id), patch: { user: { ...user, block: false } }, }); }; -export const fetchHiddenUsers = (): StoreAction => dispatch => { +export const fetchHiddenUsers = (): StoreAction => (dispatch) => { const hiddenUsers = getHiddenUsers(); dispatch({ type: USER_HIDELIST_SET, payload: hiddenUsers }); @@ -103,8 +101,8 @@ export const hideUser = (user: User): StoreAction => (dispatch, getState) setItem(LS_HIDDEN_USERS_KEY, JSON.stringify(hiddenUsers)); const ids = Object.values(getState().comments.allComments) - .filter(c => c.user.id === user.id) - .map(c => c.id); + .filter((c) => c.user.id === user.id) + .map((c) => c.id); dispatch({ type: USER_HIDE, user }); dispatch({ type: COMMENTS_PATCH, ids, patch: { hidden: true } }); @@ -133,14 +131,14 @@ export const setVerifiedStatus = (id: User['id'], status: boolean): StoreAction< await api.removeVerifiedStatus(id); } const comments = Object.values(getState().comments.allComments); - const userComments = comments.filter(c => c.user.id === id); + const userComments = comments.filter((c) => c.user.id === id); if (!userComments.length) return; const user = userComments[0].user; dispatch({ type: COMMENTS_PATCH, - ids: userComments.map(c => c.id), + ids: userComments.map((c) => c.id), patch: { user: { ...user, verified: status } }, }); }; diff --git a/frontend/app/store/user/reducers.ts b/frontend/app/store/user/reducers.ts index 37ea9e6c..f45f48ff 100644 --- a/frontend/app/store/user/reducers.ts +++ b/frontend/app/store/user/reducers.ts @@ -38,13 +38,13 @@ export const bannedUsers = (state: BlockedUser[] = [], action: USER_ACTIONS): Bl return action.list; } case USER_BAN: { - if (state.find(u => u.id === action.user.id) !== undefined) { + if (state.find((u) => u.id === action.user.id) !== undefined) { return state; } return [action.user, ...state]; } case USER_UNBAN: { - const index = state.findIndex(u => u.id === action.id); + const index = state.findIndex((u) => u.id === action.id); if (index === -1) { return state; } diff --git a/frontend/app/utils/jwt.ts b/frontend/app/utils/jwt.ts index a860d11b..f4774244 100644 --- a/frontend/app/utils/jwt.ts +++ b/frontend/app/utils/jwt.ts @@ -4,7 +4,7 @@ export function parseJwt(toke const jsonPayload = decodeURIComponent( atob(base64) .split('') - .map(c => `%${`00${c.charCodeAt(0).toString(16)}`.slice(-2)}`) + .map((c) => `%${`00${c.charCodeAt(0).toString(16)}`.slice(-2)}`) .join('') ); diff --git a/frontend/app/utils/loadLocale.ts b/frontend/app/utils/loadLocale.ts index be614ace..876b1e44 100644 --- a/frontend/app/utils/loadLocale.ts +++ b/frontend/app/utils/loadLocale.ts @@ -4,34 +4,34 @@ const enMessages = {}; export async function loadLocale(locale: string): Promise> { if (locale === 'ru') { - return import(/* webpackChunkName: "ru" */ '../locales/ru.json').then(res => res.default).catch(() => enMessages); + return import(/* webpackChunkName: "ru" */ '../locales/ru.json').then((res) => res.default).catch(() => enMessages); } if (locale === 'de') { - return import(/* webpackChunkName: "de" */ '../locales/de.json').then(res => res.default).catch(() => enMessages); + return import(/* webpackChunkName: "de" */ '../locales/de.json').then((res) => res.default).catch(() => enMessages); } if (locale === 'fi') { - return import(/* webpackChunkName: "fi" */ '../locales/fi.json').then(res => res.default).catch(() => enMessages); + return import(/* webpackChunkName: "fi" */ '../locales/fi.json').then((res) => res.default).catch(() => enMessages); } if (locale === 'es') { - return import(/* webpackChunkName: "es" */ '../locales/es.json').then(res => res.default).catch(() => enMessages); + return import(/* webpackChunkName: "es" */ '../locales/es.json').then((res) => res.default).catch(() => enMessages); } if (locale === 'zh') { - return import(/* webpackChunkName: "zh" */ '../locales/zh.json').then(res => res.default).catch(() => enMessages); + return import(/* webpackChunkName: "zh" */ '../locales/zh.json').then((res) => res.default).catch(() => enMessages); } if (locale === 'tr') { - return import(/* webpackChunkName: "tr" */ '../locales/tr.json').then(res => res.default).catch(() => enMessages); + return import(/* webpackChunkName: "tr" */ '../locales/tr.json').then((res) => res.default).catch(() => enMessages); } if (locale === 'bg') { - return import(/* webpackChunkName: "bg" */ '../locales/bg.json').then(res => res.default).catch(() => enMessages); + return import(/* webpackChunkName: "bg" */ '../locales/bg.json').then((res) => res.default).catch(() => enMessages); } if (locale === 'ua') { - return import(/* webpackChunkName: "ua" */ '../locales/ua.json').then(res => res.default).catch(() => enMessages); + return import(/* webpackChunkName: "ua" */ '../locales/ua.json').then((res) => res.default).catch(() => enMessages); } if (locale === 'pl') { - return import(/* webpackChunkName: "pl" */ '../locales/pl.json').then(res => res.default).catch(() => enMessages); + return import(/* webpackChunkName: "pl" */ '../locales/pl.json').then((res) => res.default).catch(() => enMessages); } if (locale === 'vi') { - return import(/* webpackChunkName: "vi" */ '../locales/vi.json').then(res => res.default).catch(() => enMessages); + return import(/* webpackChunkName: "vi" */ '../locales/vi.json').then((res) => res.default).catch(() => enMessages); } return enMessages; diff --git a/frontend/app/utils/sleep.ts b/frontend/app/utils/sleep.ts index 333f666c..abe5aad0 100644 --- a/frontend/app/utils/sleep.ts +++ b/frontend/app/utils/sleep.ts @@ -1,3 +1,3 @@ export function sleep(ms = 1000): Promise { - return new Promise(resolve => setTimeout(resolve, ms)); + return new Promise((resolve) => setTimeout(resolve, ms)); } diff --git a/frontend/tasks/checkTranslation.js b/frontend/tasks/checkTranslation.js index 7642d6e2..675ba221 100644 --- a/frontend/tasks/checkTranslation.js +++ b/frontend/tasks/checkTranslation.js @@ -5,10 +5,10 @@ const { keys } = require('./getTranslationKeys'); const errors = []; -locales.forEach(locale => { +locales.forEach((locale) => { const dict = require(getLocalePath({ locale })); const keysFromDict = Object.keys(dict); - keysFromDict.forEach(key => { + keysFromDict.forEach((key) => { if (!keys.includes(key)) { errors.push( `"${key}" key not found in "${locale}" locale dict. Please run "npm run translation:generate" and commit changes.` diff --git a/frontend/tasks/generateDictionary.js b/frontend/tasks/generateDictionary.js index 82e4a6b2..da2e85e5 100644 --- a/frontend/tasks/generateDictionary.js +++ b/frontend/tasks/generateDictionary.js @@ -19,7 +19,7 @@ function sortDict(dict) { ); } -locales.forEach(locale => { +locales.forEach((locale) => { let currentDict = {}; const pathToDict = getLocalePath({ locale }); if (fs.existsSync(pathToDict)) { @@ -35,6 +35,6 @@ locales.forEach(locale => { fs.writeFileSync(pathToDict, `${JSON.stringify(currentDict, null, 2)}\n`); fs.writeFileSync( path.resolve(__dirname, `../app/utils/loadLocale.ts`), - renderLoadLocale(locales.filter(locale => locale !== 'en')) + renderLoadLocale(locales.filter((locale) => locale !== 'en')) ); }); diff --git a/frontend/tasks/localeLoadTemplate.js b/frontend/tasks/localeLoadTemplate.js index f9d2424e..fda9cb9d 100644 --- a/frontend/tasks/localeLoadTemplate.js +++ b/frontend/tasks/localeLoadTemplate.js @@ -6,7 +6,7 @@ const enMessages = {}; export async function loadLocale(locale: string): Promise> { ${locales .map( - locale => ` if (locale === '${locale}') { + (locale) => ` if (locale === '${locale}') { return import(/* webpackChunkName: "${locale}" */ '../locales/${locale}.json').then((res) => res.default).catch(() => enMessages); } ` diff --git a/frontend/webpack.config.js b/frontend/webpack.config.js index 32da97b1..bcc48529 100644 --- a/frontend/webpack.config.js +++ b/frontend/webpack.config.js @@ -32,7 +32,7 @@ const exclude = [ 'react-intl', 'intl-messageformat', 'intl-messageformat-parser', -].map(m => path.resolve(__dirname, 'node_modules', m)); +].map((m) => path.resolve(__dirname, 'node_modules', m)); const htmlMinifyOptions = { minifyCSS: true,