From a310197a5a969f5e03246f08d4ff1a049b726b34 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 3 Aug 2021 12:10:42 -0500 Subject: [PATCH] eslint: prefer-const, no-loop-func, no-const-assign, no-var --- .eslintrc.js | 4 ++ app/soapbox/actions/alerts.js | 2 +- app/soapbox/actions/compose.js | 5 ++- app/soapbox/components/autosuggest_input.js | 4 +- .../components/autosuggest_textarea.js | 4 +- .../components/extended_video_player.js | 2 +- app/soapbox/components/media_gallery.js | 7 ++-- app/soapbox/components/profile_hover_card.js | 2 +- app/soapbox/components/status.js | 6 +-- app/soapbox/components/status_action_bar.js | 4 +- app/soapbox/components/status_content.js | 6 +-- app/soapbox/containers/status_container.js | 2 +- .../features/account/components/header.js | 4 +- .../account_gallery/components/media_item.js | 2 +- app/soapbox/features/account_gallery/index.js | 2 +- .../features/account_timeline/index.js | 2 +- .../features/compose/components/action_bar.js | 2 +- .../emoji_picker_dropdown_container.js | 2 +- .../features/compose/util/url_regex.js | 2 +- app/soapbox/features/edit_profile/index.js | 4 +- app/soapbox/features/emoji/emoji.js | 3 ++ .../features/emoji/emoji_compressed.js | 10 +++-- .../features/emoji/emoji_mart_data_light.js | 14 ++----- .../features/emoji/emoji_mart_search_light.js | 34 ++++++++--------- .../emoji/emoji_unicode_mapping_light.js | 13 +++---- app/soapbox/features/emoji/emoji_utils.js | 38 +++++++++---------- app/soapbox/features/filters/index.js | 2 +- app/soapbox/features/followers/index.js | 2 +- app/soapbox/features/following/index.js | 2 +- .../features/hashtag_timeline/index.js | 10 ++--- .../import_data/components/csv_importer.js | 2 +- .../components/column_settings.js | 2 +- .../components/multi_setting_toggle.js | 2 +- .../components/icon_picker_dropdown.js | 4 +- app/soapbox/features/soapbox_config/index.js | 2 +- .../features/status/components/action_bar.js | 4 +- .../features/status/components/card.js | 2 +- .../status/components/detailed_status.js | 2 +- .../containers/detailed_status_container.js | 2 +- app/soapbox/features/status/index.js | 4 +- .../features/ui/components/column_loading.js | 2 +- .../ui/components/profile_dropdown.js | 2 +- .../features/ui/components/tabs_bar.js | 2 +- app/soapbox/features/video/index.js | 2 +- app/soapbox/is_mobile.js | 2 +- app/soapbox/reducers/admin_log.js | 4 +- app/soapbox/reducers/notifications.js | 2 +- app/soapbox/selectors/index.js | 2 +- app/soapbox/utils/accounts.js | 4 +- app/soapbox/utils/features.js | 4 +- app/soapbox/utils/theme.js | 12 +++--- webpack/development.js | 2 +- webpack/translationRunner.js | 10 ++--- 53 files changed, 136 insertions(+), 136 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 7db751fec..e4c8cd801 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -105,6 +105,10 @@ module.exports = { semi: 'error', strict: 'off', 'valid-typeof': 'error', + 'prefer-const': 'error', + 'no-loop-func': 'error', + 'no-const-assign': 'error', + 'no-var': 'error', 'react/jsx-boolean-value': 'error', 'react/jsx-closing-bracket-location': ['error', 'line-aligned'], diff --git a/app/soapbox/actions/alerts.js b/app/soapbox/actions/alerts.js index 22ca16138..47ada2b98 100644 --- a/app/soapbox/actions/alerts.js +++ b/app/soapbox/actions/alerts.js @@ -45,7 +45,7 @@ export function showAlertForError(error) { } let message = statusText; - let title = `${status}`; + const title = `${status}`; if (data.error) { message = data.error; diff --git a/app/soapbox/actions/compose.js b/app/soapbox/actions/compose.js index 3a95cddd6..2e16b7f24 100644 --- a/app/soapbox/actions/compose.js +++ b/app/soapbox/actions/compose.js @@ -148,7 +148,7 @@ export function handleComposeSubmit(dispatch, getState, data, status) { const timeline = getState().getIn(['timelines', timelineId]); if (timeline && timeline.get('items').size > 0 && timeline.getIn(['items', 0]) !== null && timeline.get('online')) { - let dequeueArgs = {}; + const dequeueArgs = {}; if (timelineId === 'community') dequeueArgs.onlyMedia = getSettings(getState()).getIn(['community', 'other', 'onlyMedia']); dispatch(dequeueTimeline(timelineId, null, dequeueArgs)); dispatch(updateTimeline(timelineId, data.id)); @@ -272,6 +272,8 @@ export function uploadCompose(files) { for (const [i, f] of Array.from(files).entries()) { if (media.size + i > uploadLimit - 1) break; + // FIXME: Don't define function in loop + /* eslint-disable no-loop-func */ resizeImage(f).then(file => { const data = new FormData(); data.append('file', file); @@ -287,6 +289,7 @@ export function uploadCompose(files) { .then(({ data }) => dispatch(uploadComposeSuccess(data))); }).catch(error => dispatch(uploadComposeFail(error))); + /* eslint-enable no-loop-func */ }; }; }; diff --git a/app/soapbox/components/autosuggest_input.js b/app/soapbox/components/autosuggest_input.js index 2ae687417..8b3e5bb96 100644 --- a/app/soapbox/components/autosuggest_input.js +++ b/app/soapbox/components/autosuggest_input.js @@ -11,8 +11,8 @@ import { List as ImmutableList } from 'immutable'; const textAtCursorMatchesToken = (str, caretPosition, searchTokens) => { let word; - let left = str.slice(0, caretPosition).search(/\S+$/); - let right = str.slice(caretPosition).search(/\s/); + const left = str.slice(0, caretPosition).search(/\S+$/); + const right = str.slice(caretPosition).search(/\s/); if (right < 0) { word = str.slice(left); diff --git a/app/soapbox/components/autosuggest_textarea.js b/app/soapbox/components/autosuggest_textarea.js index ae44d3bfa..57ba6b4fc 100644 --- a/app/soapbox/components/autosuggest_textarea.js +++ b/app/soapbox/components/autosuggest_textarea.js @@ -11,8 +11,8 @@ import classNames from 'classnames'; const textAtCursorMatchesToken = (str, caretPosition) => { let word; - let left = str.slice(0, caretPosition).search(/\S+$/); - let right = str.slice(caretPosition).search(/\s/); + const left = str.slice(0, caretPosition).search(/\S+$/); + const right = str.slice(caretPosition).search(/\s/); if (right < 0) { word = str.slice(left); diff --git a/app/soapbox/components/extended_video_player.js b/app/soapbox/components/extended_video_player.js index b214a5988..c0553283c 100644 --- a/app/soapbox/components/extended_video_player.js +++ b/app/soapbox/components/extended_video_player.js @@ -41,7 +41,7 @@ export default class ExtendedVideoPlayer extends React.PureComponent { render() { const { src, muted, controls, alt } = this.props; - let conditionalAttributes = {}; + const conditionalAttributes = {}; if (isIOS()) { conditionalAttributes.playsInline = '1'; } diff --git a/app/soapbox/components/media_gallery.js b/app/soapbox/components/media_gallery.js index 01638b0b8..880afd22f 100644 --- a/app/soapbox/components/media_gallery.js +++ b/app/soapbox/components/media_gallery.js @@ -169,7 +169,7 @@ class Item extends React.PureComponent { ); } else if (attachment.get('type') === 'gifv') { - let conditionalAttributes = {}; + const conditionalAttributes = {}; if (isIOS()) { conditionalAttributes.playsInline = '1'; } @@ -563,9 +563,8 @@ class MediaGallery extends React.PureComponent { const { media, intl, sensitive } = this.props; const { visible } = this.state; const sizeData = this.getSizeData(media.size); - let children, spoilerButton; - children = media.take(ATTACHMENT_LIMIT).map((attachment, i) => ( + const children = media.take(ATTACHMENT_LIMIT).map((attachment, i) => ( )); + let spoilerButton; + if (visible) { spoilerButton = ; } else { diff --git a/app/soapbox/components/profile_hover_card.js b/app/soapbox/components/profile_hover_card.js index 77b0f54b4..202be475d 100644 --- a/app/soapbox/components/profile_hover_card.js +++ b/app/soapbox/components/profile_hover_card.js @@ -19,7 +19,7 @@ import { const getAccount = makeGetAccount(); const getBadges = (account) => { - let badges = []; + const badges = []; if (isAdmin(account)) { badges.push(); diff --git a/app/soapbox/components/status.js b/app/soapbox/components/status.js index 1bc5b5175..151a3e926 100644 --- a/app/soapbox/components/status.js +++ b/app/soapbox/components/status.js @@ -292,13 +292,13 @@ class Status extends ImmutablePureComponent { render() { let media = null; - let poll = null; + const poll = null; let statusAvatar, prepend, rebloggedByText, reblogContent; const { intl, hidden, featured, otherAccounts, unread, showThread, group } = this.props; - let { status, account, ...other } = this.props; - + // FIXME: why does this need to reassign status and account?? + let { status, account, ...other } = this.props; // eslint-disable-line prefer-const if (status === null) { return null; diff --git a/app/soapbox/components/status_action_bar.js b/app/soapbox/components/status_action_bar.js index 206170e24..fccf0feb7 100644 --- a/app/soapbox/components/status_action_bar.js +++ b/app/soapbox/components/status_action_bar.js @@ -284,7 +284,7 @@ class StatusActionBar extends ImmutablePureComponent { const mutingConversation = status.get('muted'); const ownAccount = status.getIn(['account', 'id']) === me; - let menu = []; + const menu = []; menu.push({ text: intl.formatMessage(messages.open), action: this.handleOpen }); @@ -388,7 +388,7 @@ class StatusActionBar extends ImmutablePureComponent { '😩': messages.reactionWeary, }[meEmojiReact] || messages.favourite); - let menu = this._makeMenu(publicStatus); + const menu = this._makeMenu(publicStatus); let reblogIcon = 'retweet'; let replyIcon; let replyTitle; diff --git a/app/soapbox/components/status_content.js b/app/soapbox/components/status_content.js index 0473e600a..0e5d066ea 100644 --- a/app/soapbox/components/status_content.js +++ b/app/soapbox/components/status_content.js @@ -50,8 +50,8 @@ class StatusContent extends React.PureComponent { const links = node.querySelectorAll('a'); - for (var i = 0; i < links.length; ++i) { - let link = links[i]; + for (let i = 0; i < links.length; ++i) { + const link = links[i]; if (link.classList.contains('status-link')) { continue; } @@ -59,7 +59,7 @@ class StatusContent extends React.PureComponent { link.setAttribute('rel', 'nofollow noopener'); link.setAttribute('target', '_blank'); - let mention = this.props.status.get('mentions').find(item => link.href === `${item.get('url')}`); + const mention = this.props.status.get('mentions').find(item => link.href === `${item.get('url')}`); if (mention) { link.addEventListener('click', this.onMentionClick.bind(this, mention), false); diff --git a/app/soapbox/containers/status_container.js b/app/soapbox/containers/status_container.js index 8f7af89a3..5d0490c60 100644 --- a/app/soapbox/containers/status_container.js +++ b/app/soapbox/containers/status_container.js @@ -69,7 +69,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({ onReply(status, router) { dispatch((_, getState) => { - let state = getState(); + const state = getState(); if (state.getIn(['compose', 'text']).trim().length !== 0) { dispatch(openModal('CONFIRM', { message: intl.formatMessage(messages.replyMessage), diff --git a/app/soapbox/features/account/components/header.js b/app/soapbox/features/account/components/header.js index 4bb1822d7..384547338 100644 --- a/app/soapbox/features/account/components/header.js +++ b/app/soapbox/features/account/components/header.js @@ -138,7 +138,7 @@ class Header extends ImmutablePureComponent { makeMenu() { const { account, intl, me, meAccount, version } = this.props; - let menu = []; + const menu = []; if (!account || !me) { return []; @@ -245,7 +245,7 @@ class Header extends ImmutablePureComponent { makeInfo() { const { account, me } = this.props; - let info = []; + const info = []; if (!account || !me) return info; diff --git a/app/soapbox/features/account_gallery/components/media_item.js b/app/soapbox/features/account_gallery/components/media_item.js index e3781eb05..afc15568f 100644 --- a/app/soapbox/features/account_gallery/components/media_item.js +++ b/app/soapbox/features/account_gallery/components/media_item.js @@ -93,7 +93,7 @@ class MediaItem extends ImmutablePureComponent { /> ); } else if (['gifv', 'video'].indexOf(attachment.get('type')) !== -1) { - let conditionalAttributes = {}; + const conditionalAttributes = {}; if (isIOS()) { conditionalAttributes.playsInline = '1'; } diff --git a/app/soapbox/features/account_gallery/index.js b/app/soapbox/features/account_gallery/index.js index bc2892038..d09182d09 100644 --- a/app/soapbox/features/account_gallery/index.js +++ b/app/soapbox/features/account_gallery/index.js @@ -29,7 +29,7 @@ const mapStateToProps = (state, { params, withReplies = false }) => { if (accountFetchError) { accountId = null; } else { - let account = accounts.find(acct => username.toLowerCase() === acct.getIn(['acct'], '').toLowerCase()); + const account = accounts.find(acct => username.toLowerCase() === acct.getIn(['acct'], '').toLowerCase()); accountId = account ? account.getIn(['id'], null) : -1; accountUsername = account ? account.getIn(['acct'], '') : ''; } diff --git a/app/soapbox/features/account_timeline/index.js b/app/soapbox/features/account_timeline/index.js index b62fdf779..313b42c27 100644 --- a/app/soapbox/features/account_timeline/index.js +++ b/app/soapbox/features/account_timeline/index.js @@ -29,7 +29,7 @@ const mapStateToProps = (state, { params, withReplies = false }) => { if (accountFetchError) { accountId = null; } else { - let account = accounts.find(acct => username.toLowerCase() === acct.getIn(['acct'], '').toLowerCase()); + const account = accounts.find(acct => username.toLowerCase() === acct.getIn(['acct'], '').toLowerCase()); accountId = account ? account.getIn(['id'], null) : -1; accountUsername = account ? account.getIn(['acct'], '') : ''; accountApId = account ? account.get('url') : ''; diff --git a/app/soapbox/features/compose/components/action_bar.js b/app/soapbox/features/compose/components/action_bar.js index fe12495b9..3a4098e87 100644 --- a/app/soapbox/features/compose/components/action_bar.js +++ b/app/soapbox/features/compose/components/action_bar.js @@ -67,7 +67,7 @@ class ActionBar extends React.PureComponent { const { intl, onClickLogOut, meUsername, isStaff } = this.props; const size = this.props.size || 16; - let menu = []; + const menu = []; menu.push({ text: intl.formatMessage(messages.profile), to: `/@${meUsername}` }); menu.push({ text: intl.formatMessage(messages.lists), to: '/lists' }); diff --git a/app/soapbox/features/compose/containers/emoji_picker_dropdown_container.js b/app/soapbox/features/compose/containers/emoji_picker_dropdown_container.js index 0e76839e4..b633165c2 100644 --- a/app/soapbox/features/compose/containers/emoji_picker_dropdown_container.js +++ b/app/soapbox/features/compose/containers/emoji_picker_dropdown_container.js @@ -38,7 +38,7 @@ const getFrequentlyUsedEmojis = createSelector([ .toArray(); if (emojis.length < DEFAULTS.length) { - let uniqueDefaults = DEFAULTS.filter(emoji => !emojis.includes(emoji)); + const uniqueDefaults = DEFAULTS.filter(emoji => !emojis.includes(emoji)); emojis = emojis.concat(uniqueDefaults.slice(0, DEFAULTS.length - emojis.length)); } diff --git a/app/soapbox/features/compose/util/url_regex.js b/app/soapbox/features/compose/util/url_regex.js index 7f1e17620..3e34b725a 100644 --- a/app/soapbox/features/compose/util/url_regex.js +++ b/app/soapbox/features/compose/util/url_regex.js @@ -16,7 +16,7 @@ const regexSupplant = function(regex, flags) { regex = regex.source; } return new RegExp(regex.replace(/#\{(\w+)\}/g, function(match, name) { - var newRegex = regexen[name] || ''; + let newRegex = regexen[name] || ''; if (typeof newRegex !== 'string') { newRegex = newRegex.source; } diff --git a/app/soapbox/features/edit_profile/index.js b/app/soapbox/features/edit_profile/index.js index a9cbdca67..5704652d0 100644 --- a/app/soapbox/features/edit_profile/index.js +++ b/app/soapbox/features/edit_profile/index.js @@ -142,8 +142,8 @@ class EditProfile extends ImmutablePureComponent { getFormdata = () => { const data = this.getParams(); - let formData = new FormData(); - for (let key in data) { + const formData = new FormData(); + for (const key in data) { // Compact the submission. This should probably be done better. const shouldAppend = Boolean(data[key] !== undefined || key.startsWith('fields_attributes')); if (shouldAppend) formData.append(key, data[key] || ''); diff --git a/app/soapbox/features/emoji/emoji.js b/app/soapbox/features/emoji/emoji.js index 62d03ac88..da23bc99f 100644 --- a/app/soapbox/features/emoji/emoji.js +++ b/app/soapbox/features/emoji/emoji.js @@ -18,6 +18,8 @@ const emojify = (str, customEmojis = {}, autoplay = false) => { if (i === str.length) { break; } else if (str[i] === ':') { + // FIXME: This is insane. + /* eslint-disable no-loop-func */ if (!(() => { rend = str.indexOf(':', i + 1) + 1; if (!rend) return false; // no pair of ':' @@ -33,6 +35,7 @@ const emojify = (str, customEmojis = {}, autoplay = false) => { } return false; })()) rend = ++i; + /* eslint-enable no-loop-func */ } else if (tag >= 0) { // <, & rend = str.indexOf('>;'[tag], i + 1) + 1; if (!rend) { diff --git a/app/soapbox/features/emoji/emoji_compressed.js b/app/soapbox/features/emoji/emoji_compressed.js index 74b53ce5c..4fb51ed0a 100644 --- a/app/soapbox/features/emoji/emoji_compressed.js +++ b/app/soapbox/features/emoji/emoji_compressed.js @@ -87,7 +87,7 @@ Object.keys(emojiIndex.emojis).forEach(key => { } const { native } = emoji; - let { short_names, search, unified } = emojiMartData.emojis[key]; + const { short_names, search, unified } = emojiMartData.emojis[key]; if (short_names[0] !== key) { throw new Error('The compresser expects the first short_code to be the ' + @@ -95,9 +95,11 @@ Object.keys(emojiIndex.emojis).forEach(key => { 'is no longer the case.'); } - short_names = short_names.slice(1); // first short name can be inferred from the key - - const searchData = [native, short_names, search]; + const searchData = [ + native, + short_names.slice(1), // first short name can be inferred from the key + search, + ]; if (unicodeToUnifiedName(native) !== unified) { // unified name can't be derived from unicodeToUnifiedName diff --git a/app/soapbox/features/emoji/emoji_mart_data_light.js b/app/soapbox/features/emoji/emoji_mart_data_light.js index 45086fc4c..f8f4c4033 100644 --- a/app/soapbox/features/emoji/emoji_mart_data_light.js +++ b/app/soapbox/features/emoji/emoji_mart_data_light.js @@ -8,28 +8,22 @@ const emojis = {}; // decompress Object.keys(shortCodesToEmojiData).forEach((shortCode) => { - let [ + const [ filenameData, // eslint-disable-line no-unused-vars searchData, ] = shortCodesToEmojiData[shortCode]; - let [ + const [ native, short_names, search, unified, ] = searchData; - if (!unified) { - // unified name can be derived from unicodeToUnifiedName - unified = unicodeToUnifiedName(native); - } - - short_names = [shortCode].concat(short_names); emojis[shortCode] = { native, search, - short_names, - unified, + short_names: [shortCode].concat(short_names), + unified: unified || unicodeToUnifiedName(native), }; }); diff --git a/app/soapbox/features/emoji/emoji_mart_search_light.js b/app/soapbox/features/emoji/emoji_mart_search_light.js index 55166112b..89e25785f 100644 --- a/app/soapbox/features/emoji/emoji_mart_search_light.js +++ b/app/soapbox/features/emoji/emoji_mart_search_light.js @@ -4,16 +4,16 @@ import data from './emoji_mart_data_light'; import { getData, getSanitizedData, uniq, intersect } from './emoji_utils'; -let originalPool = {}; +const originalPool = {}; let index = {}; -let emojisList = {}; -let emoticonsList = {}; +const emojisList = {}; +const emoticonsList = {}; let customEmojisList = []; -for (let emoji in data.emojis) { - let emojiData = data.emojis[emoji]; - let { short_names, emoticons } = emojiData; - let id = short_names[0]; +for (const emoji in data.emojis) { + const emojiData = data.emojis[emoji]; + const { short_names, emoticons } = emojiData; + const id = short_names[0]; if (emoticons) { emoticons.forEach(emoticon => { @@ -31,7 +31,7 @@ for (let emoji in data.emojis) { function clearCustomEmojis(pool) { customEmojisList.forEach((emoji) => { - let emojiId = emoji.id || emoji.short_names[0]; + const emojiId = emoji.id || emoji.short_names[0]; delete pool[emojiId]; delete emojisList[emojiId]; @@ -42,7 +42,7 @@ export function addCustomToPool(custom, pool = originalPool) { if (customEmojisList.length) clearCustomEmojis(pool); custom.forEach((emoji) => { - let emojiId = emoji.id || emoji.short_names[0]; + const emojiId = emoji.id || emoji.short_names[0]; if (emojiId && !pool[emojiId]) { pool[emojiId] = getData(emoji); @@ -85,8 +85,8 @@ export function search(value, { emojisToShowFilter, maxResults, include, exclude pool = {}; data.categories.forEach(category => { - let isIncluded = include && include.length ? include.indexOf(category.name.toLowerCase()) > -1 : true; - let isExcluded = exclude && exclude.length ? exclude.indexOf(category.name.toLowerCase()) > -1 : false; + const isIncluded = include && include.length ? include.indexOf(category.name.toLowerCase()) > -1 : true; + const isExcluded = exclude && exclude.length ? exclude.indexOf(category.name.toLowerCase()) > -1 : false; if (!isIncluded || isExcluded) { return; } @@ -95,8 +95,8 @@ export function search(value, { emojisToShowFilter, maxResults, include, exclude }); if (custom.length) { - let customIsIncluded = include && include.length ? include.indexOf('custom') > -1 : true; - let customIsExcluded = exclude && exclude.length ? exclude.indexOf('custom') > -1 : false; + const customIsIncluded = include && include.length ? include.indexOf('custom') > -1 : true; + const customIsExcluded = exclude && exclude.length ? exclude.indexOf('custom') > -1 : false; if (customIsIncluded && !customIsExcluded) { addCustomToPool(custom, pool); } @@ -116,13 +116,13 @@ export function search(value, { emojisToShowFilter, maxResults, include, exclude aIndex = aIndex[char]; if (!aIndex.results) { - let scores = {}; + const scores = {}; aIndex.results = []; aIndex.pool = {}; - for (let id in aPool) { - let emoji = aPool[id], + for (const id in aPool) { + const emoji = aPool[id], { search } = emoji, sub = value.substr(0, length), subIndex = search.indexOf(sub); @@ -139,7 +139,7 @@ export function search(value, { emojisToShowFilter, maxResults, include, exclude } aIndex.results.sort((a, b) => { - let aScore = scores[a.id], + const aScore = scores[a.id], bScore = scores[b.id]; return aScore - bScore; diff --git a/app/soapbox/features/emoji/emoji_unicode_mapping_light.js b/app/soapbox/features/emoji/emoji_unicode_mapping_light.js index 918684c31..b9fa9e90e 100644 --- a/app/soapbox/features/emoji/emoji_unicode_mapping_light.js +++ b/app/soapbox/features/emoji/emoji_unicode_mapping_light.js @@ -15,19 +15,16 @@ const { unicodeToFilename } = require('./unicode_to_filename'); const unicodeMapping = {}; function processEmojiMapData(emojiMapData, shortCode) { - let [ native, filename ] = emojiMapData; - if (!filename) { - // filename name can be derived from unicodeToFilename - filename = unicodeToFilename(native); - } + const [ native, filename ] = emojiMapData; + unicodeMapping[native] = { - shortCode: shortCode, - filename: filename, + shortCode, + filename: filename || unicodeToFilename(native), }; } Object.keys(shortCodesToEmojiData).forEach((shortCode) => { - let [ filenameData ] = shortCodesToEmojiData[shortCode]; + const [ filenameData ] = shortCodesToEmojiData[shortCode]; filenameData.forEach(emojiMapData => processEmojiMapData(emojiMapData, shortCode)); }); emojisWithoutShortCodes.forEach(emojiMapData => processEmojiMapData(emojiMapData)); diff --git a/app/soapbox/features/emoji/emoji_utils.js b/app/soapbox/features/emoji/emoji_utils.js index 740914dba..34ddfdc0e 100644 --- a/app/soapbox/features/emoji/emoji_utils.js +++ b/app/soapbox/features/emoji/emoji_utils.js @@ -6,7 +6,7 @@ import data from './emoji_mart_data_light'; const buildSearch = (data) => { const search = []; - let addToSearch = (strings, split) => { + const addToSearch = (strings, split) => { if (!strings) { return; } @@ -33,12 +33,12 @@ const buildSearch = (data) => { const _String = String; const stringFromCodePoint = _String.fromCodePoint || function() { - let MAX_SIZE = 0x4000; - let codeUnits = []; + const MAX_SIZE = 0x4000; + const codeUnits = []; let highSurrogate; let lowSurrogate; let index = -1; - let length = arguments.length; + const length = arguments.length; if (!length) { return ''; } @@ -80,16 +80,16 @@ const SKINS = [ ]; function unifiedToNative(unified) { - let unicodes = unified.split('-'), + const unicodes = unified.split('-'), codePoints = unicodes.map((u) => `0x${u}`); return stringFromCodePoint.apply(null, codePoints); } function sanitize(emoji) { - let { name, short_names, skin_tone, skin_variations, emoticons, unified, custom, imageUrl } = emoji, - id = emoji.id || short_names[0], - colons = `:${id}:`; + const { name, short_names, skin_tone, skin_variations, emoticons, unified, custom, imageUrl } = emoji; + const id = emoji.id || short_names[0]; + const colons = `:${id}:`; if (custom) { return { @@ -102,14 +102,10 @@ function sanitize(emoji) { }; } - if (skin_tone) { - colons += `:skin-tone-${skin_tone}:`; - } - return { id, name, - colons, + colons: skin_tone ? `${colons}:skin-tone-${skin_tone}:` : colons, emoticons, unified: unified.toLowerCase(), skin: skin_tone || (skin_variations ? 1 : null), @@ -125,7 +121,7 @@ function getData(emoji, skin, set) { let emojiData = {}; if (typeof emoji === 'string') { - let matches = emoji.match(COLONS_REGEX); + const matches = emoji.match(COLONS_REGEX); if (matches) { emoji = matches[1]; @@ -168,7 +164,7 @@ function getData(emoji, skin, set) { if (emojiData.skin_variations && skin > 1 && set) { emojiData = JSON.parse(_JSON.stringify(emojiData)); - let skinKey = SKINS[skin - 1], + const skinKey = SKINS[skin - 1], variationData = emojiData.skin_variations[skinKey]; if (!variationData.variations && emojiData.variations) { @@ -178,8 +174,8 @@ function getData(emoji, skin, set) { if (variationData[`has_img_${set}`]) { emojiData.skin_tone = skin; - for (let k in variationData) { - let v = variationData[k]; + for (const k in variationData) { + const v = variationData[k]; emojiData[k] = v; } } @@ -210,11 +206,11 @@ function intersect(a, b) { } function deepMerge(a, b) { - let o = {}; + const o = {}; - for (let key in a) { - let originalValue = a[key], - value = originalValue; + for (const key in a) { + const originalValue = a[key]; + let value = originalValue; if (b.hasOwnProperty(key)) { value = b[key]; diff --git a/app/soapbox/features/filters/index.js b/app/soapbox/features/filters/index.js index c1b78f67d..d48667de3 100644 --- a/app/soapbox/features/filters/index.js +++ b/app/soapbox/features/filters/index.js @@ -96,7 +96,7 @@ class Filters extends ImmutablePureComponent { const { intl, dispatch } = this.props; const { phrase, whole_word, expires_at, irreversible } = this.state; const { home_timeline, public_timeline, notifications, conversations } = this.state; - let context = []; + const context = []; if (home_timeline) { context.push('home'); diff --git a/app/soapbox/features/followers/index.js b/app/soapbox/features/followers/index.js index 079867772..25d91880e 100644 --- a/app/soapbox/features/followers/index.js +++ b/app/soapbox/features/followers/index.js @@ -28,7 +28,7 @@ const mapStateToProps = (state, { params, withReplies = false }) => { if (accountFetchError) { accountId = null; } else { - let account = accounts.find(acct => username.toLowerCase() === acct.getIn(['acct'], '').toLowerCase()); + const account = accounts.find(acct => username.toLowerCase() === acct.getIn(['acct'], '').toLowerCase()); accountId = account ? account.getIn(['id'], null) : -1; } diff --git a/app/soapbox/features/following/index.js b/app/soapbox/features/following/index.js index 9148b0949..7e480e1a9 100644 --- a/app/soapbox/features/following/index.js +++ b/app/soapbox/features/following/index.js @@ -28,7 +28,7 @@ const mapStateToProps = (state, { params, withReplies = false }) => { if (accountFetchError) { accountId = null; } else { - let account = accounts.find(acct => username.toLowerCase() === acct.getIn(['acct'], '').toLowerCase()); + const account = accounts.find(acct => username.toLowerCase() === acct.getIn(['acct'], '').toLowerCase()); accountId = account ? account.getIn(['id'], null) : -1; } diff --git a/app/soapbox/features/hashtag_timeline/index.js b/app/soapbox/features/hashtag_timeline/index.js index 213a833b3..ea9b30e84 100644 --- a/app/soapbox/features/hashtag_timeline/index.js +++ b/app/soapbox/features/hashtag_timeline/index.js @@ -26,7 +26,7 @@ class HashtagTimeline extends React.PureComponent { }; title = () => { - let title = [this.props.params.id]; + const title = [this.props.params.id]; if (this.additionalFor('any')) { title.push(' ', ); @@ -54,13 +54,13 @@ class HashtagTimeline extends React.PureComponent { } _subscribe(dispatch, id, tags = {}) { - let any = (tags.any || []).map(tag => tag.value); - let all = (tags.all || []).map(tag => tag.value); - let none = (tags.none || []).map(tag => tag.value); + const any = (tags.any || []).map(tag => tag.value); + const all = (tags.all || []).map(tag => tag.value); + const none = (tags.none || []).map(tag => tag.value); [id, ...any].map(tag => { this.disconnects.push(dispatch(connectHashtagStream(id, tag, status => { - let tags = status.tags.map(tag => tag.name); + const tags = status.tags.map(tag => tag.name); return all.filter(tag => tags.includes(tag)).length === all.length && none.filter(tag => tags.includes(tag)).length === 0; diff --git a/app/soapbox/features/import_data/components/csv_importer.js b/app/soapbox/features/import_data/components/csv_importer.js index a0523e924..aa7d967f4 100644 --- a/app/soapbox/features/import_data/components/csv_importer.js +++ b/app/soapbox/features/import_data/components/csv_importer.js @@ -28,7 +28,7 @@ class CSVImporter extends ImmutablePureComponent { handleSubmit = (event) => { const { dispatch, action, intl } = this.props; - let params = new FormData(); + const params = new FormData(); params.append('list', this.state.file); this.setState({ isLoading: true }); diff --git a/app/soapbox/features/notifications/components/column_settings.js b/app/soapbox/features/notifications/components/column_settings.js index 38437cfef..b9c5d44f0 100644 --- a/app/soapbox/features/notifications/components/column_settings.js +++ b/app/soapbox/features/notifications/components/column_settings.js @@ -22,7 +22,7 @@ export default class ColumnSettings extends React.PureComponent { onAllSoundsChange = (path, checked) => { const soundSettings = [['sounds', 'follow'], ['sounds', 'favourite'], ['sounds', 'pleroma:emoji_reaction'], ['sounds', 'mention'], ['sounds', 'reblog'], ['sounds', 'poll'], ['sounds', 'move']]; - for (var i = 0; i < soundSettings.length; i++) { + for (let i = 0; i < soundSettings.length; i++) { this.props.onChange(soundSettings[i], checked); } } diff --git a/app/soapbox/features/notifications/components/multi_setting_toggle.js b/app/soapbox/features/notifications/components/multi_setting_toggle.js index 392369edc..9eae3d599 100644 --- a/app/soapbox/features/notifications/components/multi_setting_toggle.js +++ b/app/soapbox/features/notifications/components/multi_setting_toggle.js @@ -19,7 +19,7 @@ export default class MultiSettingToggle extends React.PureComponent { } onChange = ({ target }) => { - for (var i = 0; i < this.props.settingPaths.length; i++) { + for (let i = 0; i < this.props.settingPaths.length; i++) { this.props.onChange(this.props.settingPaths[i], target.checked); } } diff --git a/app/soapbox/features/soapbox_config/components/icon_picker_dropdown.js b/app/soapbox/features/soapbox_config/components/icon_picker_dropdown.js index 8afaa5154..a414c96e7 100644 --- a/app/soapbox/features/soapbox_config/components/icon_picker_dropdown.js +++ b/app/soapbox/features/soapbox_config/components/icon_picker_dropdown.js @@ -121,7 +121,7 @@ class IconPickerMenu extends React.PureComponent { return
; } - let data = { compressed: true, categories: [], aliases: [], emojis: [] }; + const data = { compressed: true, categories: [], aliases: [], emojis: [] }; const title = intl.formatMessage(messages.emoji); const { modifierOpen } = this.state; @@ -209,7 +209,7 @@ class IconPickerDropdown extends React.PureComponent { const { intl, onPickEmoji, value } = this.props; const title = intl.formatMessage(messages.emoji); const { active, loading, placement } = this.state; - let forkAwesomeIcons = require('../forkawesome.json'); + const forkAwesomeIcons = require('../forkawesome.json'); return (
diff --git a/app/soapbox/features/soapbox_config/index.js b/app/soapbox/features/soapbox_config/index.js index 9196bdb9f..9754de627 100644 --- a/app/soapbox/features/soapbox_config/index.js +++ b/app/soapbox/features/soapbox_config/index.js @@ -454,7 +454,7 @@ class ColorPicker extends React.PureComponent { render() { const { style, value, onChange } = this.props; - let margin_left_picker = isMobile(window.innerWidth) ? '20px' : '12px'; + const margin_left_picker = isMobile(window.innerWidth) ? '20px' : '12px'; return (
diff --git a/app/soapbox/features/status/components/action_bar.js b/app/soapbox/features/status/components/action_bar.js index 8cc300e5d..9012c98b8 100644 --- a/app/soapbox/features/status/components/action_bar.js +++ b/app/soapbox/features/status/components/action_bar.js @@ -294,7 +294,7 @@ class ActionBar extends React.PureComponent { '😩': messages.reactionWeary, }[meEmojiReact] || messages.favourite); - let menu = []; + const menu = []; if (publicStatus) { menu.push({ text: intl.formatMessage(messages.copy), action: this.handleCopy }); @@ -360,7 +360,7 @@ class ActionBar extends React.PureComponent { if (status.get('visibility') === 'direct') reblogIcon = 'envelope'; else if (status.get('visibility') === 'private') reblogIcon = 'lock'; - let reblog_disabled = (status.get('visibility') === 'direct' || status.get('visibility') === 'private'); + const reblog_disabled = (status.get('visibility') === 'direct' || status.get('visibility') === 'private'); return ( diff --git a/app/soapbox/features/status/components/card.js b/app/soapbox/features/status/components/card.js index 676acf9ec..a0506a694 100644 --- a/app/soapbox/features/status/components/card.js +++ b/app/soapbox/features/status/components/card.js @@ -179,7 +179,7 @@ export default class Card extends React.PureComponent { let embed = ''; const imageUrl = card.get('image') || card.getIn(['pleroma', 'opengraph', 'thumbnail_url']); - let thumbnail =
; + const thumbnail =
; if (interactive) { if (embedded) { diff --git a/app/soapbox/features/status/components/detailed_status.js b/app/soapbox/features/status/components/detailed_status.js index 581c47ca7..1f0809132 100644 --- a/app/soapbox/features/status/components/detailed_status.js +++ b/app/soapbox/features/status/components/detailed_status.js @@ -95,7 +95,7 @@ export default class DetailedStatus extends ImmutablePureComponent { } let media = ''; - let poll = ''; + const poll = ''; let statusTypeIcon = ''; if (this.props.measureHeight) { diff --git a/app/soapbox/features/status/containers/detailed_status_container.js b/app/soapbox/features/status/containers/detailed_status_container.js index 668ba020f..cbe1d8485 100644 --- a/app/soapbox/features/status/containers/detailed_status_container.js +++ b/app/soapbox/features/status/containers/detailed_status_container.js @@ -59,7 +59,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({ onReply(status, router) { dispatch((_, getState) => { - let state = getState(); + const state = getState(); if (state.getIn(['compose', 'text']).trim().length !== 0) { dispatch(openModal('CONFIRM', { message: intl.formatMessage(messages.replyMessage), diff --git a/app/soapbox/features/status/index.js b/app/soapbox/features/status/index.js index 0a687b855..5bac4fff9 100644 --- a/app/soapbox/features/status/index.js +++ b/app/soapbox/features/status/index.js @@ -90,7 +90,7 @@ const makeMapStateToProps = () => { const ids = [statusId]; while (ids.length > 0) { - let id = ids.shift(); + const id = ids.shift(); const replies = contextReplies.get(id); if (statusId !== id) { @@ -199,7 +199,7 @@ class Status extends ImmutablePureComponent { } handleReplyClick = (status) => { - let { askReplyConfirmation, dispatch, intl } = this.props; + const { askReplyConfirmation, dispatch, intl } = this.props; if (askReplyConfirmation) { dispatch(openModal('CONFIRM', { message: intl.formatMessage(messages.replyMessage), diff --git a/app/soapbox/features/ui/components/column_loading.js b/app/soapbox/features/ui/components/column_loading.js index ce0685d5e..9d5ba9e55 100644 --- a/app/soapbox/features/ui/components/column_loading.js +++ b/app/soapbox/features/ui/components/column_loading.js @@ -19,7 +19,7 @@ export default class ColumnLoading extends ImmutablePureComponent { }; render() { - let { title, icon } = this.props; + const { title, icon } = this.props; return ( diff --git a/app/soapbox/features/ui/components/profile_dropdown.js b/app/soapbox/features/ui/components/profile_dropdown.js index b5162d931..565be4e10 100644 --- a/app/soapbox/features/ui/components/profile_dropdown.js +++ b/app/soapbox/features/ui/components/profile_dropdown.js @@ -103,7 +103,7 @@ class ProfileDropdown extends React.PureComponent { const { intl, account, otherAccounts } = this.props; const size = this.props.size || 16; - let menu = []; + const menu = []; menu.push({ text: this.renderAccount(account), to: `/@${account.get('acct')}` }); diff --git a/app/soapbox/features/ui/components/tabs_bar.js b/app/soapbox/features/ui/components/tabs_bar.js index 7056093f5..fda0e19cc 100644 --- a/app/soapbox/features/ui/components/tabs_bar.js +++ b/app/soapbox/features/ui/components/tabs_bar.js @@ -53,7 +53,7 @@ class TabsBar extends React.PureComponent { getNavLinks() { const { intl: { formatMessage }, logo, account, dashboardCount, notificationCount, chatsCount } = this.props; - let links = []; + const links = []; if (logo) { links.push( diff --git a/app/soapbox/features/video/index.js b/app/soapbox/features/video/index.js index ccc32057d..2b70d6db3 100644 --- a/app/soapbox/features/video/index.js +++ b/app/soapbox/features/video/index.js @@ -208,7 +208,7 @@ class Video extends React.PureComponent { const x = (e.clientX - rect.left) / this.volWidth; //x position within the element. if(!isNaN(x)) { - var slideamt = x; + let slideamt = x; if(x > 1) { slideamt = 1; } else if(x < 0) { diff --git a/app/soapbox/is_mobile.js b/app/soapbox/is_mobile.js index 4c7c23e20..c21e9c0e0 100644 --- a/app/soapbox/is_mobile.js +++ b/app/soapbox/is_mobile.js @@ -11,7 +11,7 @@ export function isMobile(width) { const iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; let userTouching = false; -let listenerOptions = supportsPassiveEvents ? { passive: true } : false; +const listenerOptions = supportsPassiveEvents ? { passive: true } : false; function touchListener() { userTouching = true; diff --git a/app/soapbox/reducers/admin_log.js b/app/soapbox/reducers/admin_log.js index 874cab373..7bf305877 100644 --- a/app/soapbox/reducers/admin_log.js +++ b/app/soapbox/reducers/admin_log.js @@ -12,8 +12,8 @@ const initialState = ImmutableMap({ }); const parseItems = items => { - let ids = []; - let map = {}; + const ids = []; + const map = {}; items.forEach(item => { ids.push(item.id); diff --git a/app/soapbox/reducers/notifications.js b/app/soapbox/reducers/notifications.js index c07507c58..641038339 100644 --- a/app/soapbox/reducers/notifications.js +++ b/app/soapbox/reducers/notifications.js @@ -113,7 +113,7 @@ const updateNotificationsQueue = (state, notification, intlMessages, intlLocale) const alreadyExists = queuedNotifications.has(notification.id) || listedNotifications.has(notification.id); if (alreadyExists) return state; - let newQueuedNotifications = queuedNotifications; + const newQueuedNotifications = queuedNotifications; return state.withMutations(mutable => { if (totalQueuedNotificationsCount <= MAX_QUEUED_NOTIFICATIONS) { diff --git a/app/soapbox/selectors/index.js b/app/soapbox/selectors/index.js index 2591eadd6..35ee305fb 100644 --- a/app/soapbox/selectors/index.js +++ b/app/soapbox/selectors/index.js @@ -126,7 +126,7 @@ export const makeGetStatus = () => { const getAlertsBase = state => state.get('alerts'); export const getAlerts = createSelector([getAlertsBase], (base) => { - let arr = []; + const arr = []; base.forEach(item => { arr.push({ diff --git a/app/soapbox/utils/accounts.js b/app/soapbox/utils/accounts.js index ce52a5562..77e3f3997 100644 --- a/app/soapbox/utils/accounts.js +++ b/app/soapbox/utils/accounts.js @@ -3,7 +3,7 @@ import { List as ImmutableList } from 'immutable'; const guessDomain = account => { try { - let re = /https?:\/\/(.*?)\//i; + const re = /https?:\/\/(.*?)\//i; return re.exec(account.get('url'))[1]; } catch(e) { return null; @@ -50,7 +50,7 @@ export const getFollowDifference = (state, accountId, type) => { }; export const isLocal = account => { - let domain = account.get('acct').split('@')[1]; + const domain = account.get('acct').split('@')[1]; return domain === undefined ? true : false; }; diff --git a/app/soapbox/utils/features.js b/app/soapbox/utils/features.js index 5ec07ae87..f89652219 100644 --- a/app/soapbox/utils/features.js +++ b/app/soapbox/utils/features.js @@ -20,8 +20,8 @@ export const getFeatures = createSelector([ }); export const parseVersion = version => { - let regex = /^([\w\.]*)(?: \(compatible; ([\w]*) (.*)\))?$/; - let match = regex.exec(version); + const regex = /^([\w\.]*)(?: \(compatible; ([\w]*) (.*)\))?$/; + const match = regex.exec(version); return { software: match[2] || 'Mastodon', version: match[3] || match[1], diff --git a/app/soapbox/utils/theme.js b/app/soapbox/utils/theme.js index 5997019a8..b398145bf 100644 --- a/app/soapbox/utils/theme.js +++ b/app/soapbox/utils/theme.js @@ -29,12 +29,12 @@ function hexToRgb(hex) { // Taken from chromatism.js // https://github.com/graypegg/chromatism/blob/master/src/conversions/rgb.js const rgbToHsl = value => { - var r = value.r / 255; - var g = value.g / 255; - var b = value.b / 255; - var rgbOrdered = [ r, g, b ].sort(); - var l = ((rgbOrdered[0] + rgbOrdered[2]) / 2) * 100; - var s, h; + const r = value.r / 255; + const g = value.g / 255; + const b = value.b / 255; + const rgbOrdered = [ r, g, b ].sort(); + const l = ((rgbOrdered[0] + rgbOrdered[2]) / 2) * 100; + let s, h; if (rgbOrdered[0] === rgbOrdered[2]) { s = 0; h = 0; diff --git a/webpack/development.js b/webpack/development.js index 7af796427..10ed123ae 100644 --- a/webpack/development.js +++ b/webpack/development.js @@ -25,7 +25,7 @@ const backendEndpoints = [ ]; const makeProxyConfig = () => { - let proxyConfig = {}; + const proxyConfig = {}; proxyConfig['/api/patron'] = { target: patronUrl, secure: secureProxy, diff --git a/webpack/translationRunner.js b/webpack/translationRunner.js index 35f235128..a4da53c57 100644 --- a/webpack/translationRunner.js +++ b/webpack/translationRunner.js @@ -105,7 +105,7 @@ manageTranslations({ /* eslint-disable no-console */ function findVariablesinAST(tree) { - let result = new Set(); + const result = new Set(); tree.forEach((element) => { switch (element.type) { case parser.TYPE.argument: @@ -114,7 +114,7 @@ function findVariablesinAST(tree) { break; case parser.TYPE.plural: result.add(element.value); - let subTrees = Object.values(element.options).map((option) => option.value); + const subTrees = Object.values(element.options).map((option) => option.value); subTrees.forEach((subtree) => { findVariablesinAST(subtree).forEach((variable) => { result.add(variable); @@ -139,7 +139,7 @@ const extractedMessagesFiles = readMessageFiles(translationsDirectory); const extractedMessages = extractedMessagesFiles.reduce((acc, messageFile) => { messageFile.descriptors.forEach((descriptor) => { descriptor.descriptors.forEach((item) => { - let variables = findVariables(item.defaultMessage); + const variables = findVariables(item.defaultMessage); acc.push({ id: item.id, defaultMessage: item.defaultMessage, @@ -172,7 +172,7 @@ function pushIfUnique(arr, newItem) { const problems = translations.reduce((acc, translation) => { extractedMessages.forEach((message) => { try { - let translationVariables = findVariables(translation.data[message.id]); + const translationVariables = findVariables(translation.data[message.id]); if ([...difference(translationVariables, message.variables)].length > 0) { pushIfUnique(acc, { language: translation.language, @@ -206,7 +206,7 @@ if (problems.length > 0) { console.error('-'.repeat(60)); problems.forEach((problem) => { - let color = (problem.severity === 'error') ? '\x1b[31m' : ''; + const color = (problem.severity === 'error') ? '\x1b[31m' : ''; console.error(`${color}${problem.language}\t${problem.type}\t${problem.id}\x1b[0m`); }); console.error('\n');