From 594cf088ed31f9fa9915660d31b319eb1afbf81d Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 3 Aug 2021 14:29:36 -0500 Subject: [PATCH] eslint: extend 'eslint:recommended' --- .eslintrc.js | 11 +++++++---- app/soapbox/components/blurhash.js | 4 +++- app/soapbox/components/relative_timestamp.js | 4 ++-- app/soapbox/components/status_action_bar.js | 4 +--- .../features/admin/components/report_status.js | 2 +- app/soapbox/features/compose/util/url_regex.js | 2 +- app/soapbox/features/emoji/emoji_utils.js | 11 +++++------ .../features/report/components/status_check_box.js | 2 +- .../features/status/components/action_bar.js | 2 +- app/soapbox/features/ui/index.js | 2 +- app/soapbox/reducers/__tests__/auth-test.js | 8 +++++--- app/soapbox/reducers/__tests__/list_editor-test.js | 1 - app/soapbox/reducers/__tests__/modal-test.js | 2 -- app/soapbox/reducers/notifications.js | 14 ++++++++------ app/soapbox/reducers/security.js | 9 +++++++-- app/soapbox/settings.js | 1 + app/soapbox/utils/numbers.js | 2 +- app/soapbox/utils/resize_image.js | 1 + webpack/translationRunner.js | 11 +++++------ 19 files changed, 51 insertions(+), 42 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 79076f8c7..d64080caa 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,6 +1,8 @@ module.exports = { root: true, + extends: 'eslint:recommended', + env: { browser: true, node: true, @@ -79,8 +81,10 @@ module.exports = { }, ], 'no-extra-semi': 'error', + 'no-const-assign': 'error', 'no-fallthrough': 'error', 'no-irregular-whitespace': 'error', + 'no-loop-func': 'error', 'no-mixed-spaces-and-tabs': 'error', 'no-nested-ternary': 'warn', 'no-trailing-spaces': 'warn', @@ -95,6 +99,8 @@ module.exports = { ignoreRestSiblings: true, }, ], + 'no-useless-escape': 'warn', + 'no-var': 'error', 'object-curly-spacing': ['error', 'always'], 'padded-blocks': [ 'error', @@ -102,14 +108,11 @@ module.exports = { classes: 'always', }, ], + 'prefer-const': 'error', quotes: ['error', 'single'], 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/components/blurhash.js b/app/soapbox/components/blurhash.js index 0bab022f8..0ad74277f 100644 --- a/app/soapbox/components/blurhash.js +++ b/app/soapbox/components/blurhash.js @@ -35,7 +35,9 @@ function Blurhash({ useEffect(() => { const { current: canvas } = canvasRef; - canvas.width = canvas.width; // resets canvas + + // resets canvas + canvas.width = canvas.width; // eslint-disable-line no-self-assign if (dummy || !hash) return; diff --git a/app/soapbox/components/relative_timestamp.js b/app/soapbox/components/relative_timestamp.js index 69c3bad23..5b12f6589 100644 --- a/app/soapbox/components/relative_timestamp.js +++ b/app/soapbox/components/relative_timestamp.js @@ -137,7 +137,7 @@ class RelativeTimestamp extends React.Component { this.state.now !== nextState.now; } - componentDidUpdate(prevProps) { + UNSAFE_componentWillReceiveProps(prevProps) { if (this.props.timestamp !== prevProps.timestamp) { this.setState({ now: Date.now() }); } @@ -147,7 +147,7 @@ class RelativeTimestamp extends React.Component { this._scheduleNextUpdate(this.props, this.state); } - componentDidUpdate() { + UNSAFE_componentWillUpdate() { this._scheduleNextUpdate(); } diff --git a/app/soapbox/components/status_action_bar.js b/app/soapbox/components/status_action_bar.js index fccf0feb7..fa4fd993e 100644 --- a/app/soapbox/components/status_action_bar.js +++ b/app/soapbox/components/status_action_bar.js @@ -93,8 +93,6 @@ class StatusActionBar extends ImmutablePureComponent { allowedEmoji: ImmutablePropTypes.list, emojiSelectorFocused: PropTypes.bool, handleEmojiSelectorUnfocus: PropTypes.func.isRequired, - emojiSelectorFocused: PropTypes.bool, - handleEmojiSelectorUnfocus: PropTypes.func.isRequired, }; static defaultProps = { @@ -245,7 +243,7 @@ class StatusActionBar extends ImmutablePureComponent { textarea.select(); document.execCommand('copy'); } catch (e) { - + // Do nothing } finally { document.body.removeChild(textarea); } diff --git a/app/soapbox/features/admin/components/report_status.js b/app/soapbox/features/admin/components/report_status.js index f34574cdf..11110adb8 100644 --- a/app/soapbox/features/admin/components/report_status.js +++ b/app/soapbox/features/admin/components/report_status.js @@ -43,7 +43,7 @@ class ReportStatus extends ImmutablePureComponent { if (status.get('media_attachments').size > 0) { if (status.get('media_attachments').some(item => item.get('type') === 'unknown')) { - + // Do nothing } else if (status.getIn(['media_attachments', 0, 'type']) === 'video') { const video = status.getIn(['media_attachments', 0]); diff --git a/app/soapbox/features/compose/util/url_regex.js b/app/soapbox/features/compose/util/url_regex.js index 3e34b725a..4ac11ca05 100644 --- a/app/soapbox/features/compose/util/url_regex.js +++ b/app/soapbox/features/compose/util/url_regex.js @@ -31,7 +31,7 @@ const stringSupplant = function(str, values) { }; export const urlRegex = (function() { - regexen.spaces_group = /\x09-\x0D\x20\x85\xA0\u1680\u180E\u2000-\u200A\u2028\u2029\u202F\u205F\u3000/; + regexen.spaces_group = /\x09-\x0D\x20\x85\xA0\u1680\u180E\u2000-\u200A\u2028\u2029\u202F\u205F\u3000/; // eslint-disable-line no-control-regex regexen.invalid_chars_group = /\uFFFE\uFEFF\uFFFF\u202A-\u202E/; regexen.punct = /\!'#%&'\(\)*\+,\\\-\.\/:;<=>\?@\[\]\^_{|}~\$/; regexen.validUrlPrecedingChars = regexSupplant(/(?:[^A-Za-z0-9@@$###{invalid_chars_group}]|^)/); diff --git a/app/soapbox/features/emoji/emoji_utils.js b/app/soapbox/features/emoji/emoji_utils.js index 34ddfdc0e..1f4629edf 100644 --- a/app/soapbox/features/emoji/emoji_utils.js +++ b/app/soapbox/features/emoji/emoji_utils.js @@ -70,7 +70,6 @@ const stringFromCodePoint = _String.fromCodePoint || function() { return result; }; - const _JSON = JSON; const COLONS_REGEX = /^(?:\:([^\:]+)\:)(?:\:skin-tone-(\d)\:)?$/; @@ -131,19 +130,19 @@ function getData(emoji, skin, set) { } } - if (data.short_names.hasOwnProperty(emoji)) { + if (Object.prototype.hasOwnProperty.call(data.short_names, emoji)) { emoji = data.short_names[emoji]; } - if (data.emojis.hasOwnProperty(emoji)) { + if (Object.prototype.hasOwnProperty.call(data.emojis, emoji)) { emojiData = data.emojis[emoji]; } } else if (emoji.id) { - if (data.short_names.hasOwnProperty(emoji.id)) { + if (Object.prototype.hasOwnProperty.call(data.short_names, emoji.id)) { emoji.id = data.short_names[emoji.id]; } - if (data.emojis.hasOwnProperty(emoji.id)) { + if (Object.prototype.hasOwnProperty.call(data.emojis, emoji.id)) { emojiData = data.emojis[emoji.id]; skin = skin || emoji.skin; } @@ -212,7 +211,7 @@ function deepMerge(a, b) { const originalValue = a[key]; let value = originalValue; - if (b.hasOwnProperty(key)) { + if (Object.prototype.hasOwnProperty.call(b, key)) { value = b[key]; } diff --git a/app/soapbox/features/report/components/status_check_box.js b/app/soapbox/features/report/components/status_check_box.js index c2f2199f3..8543d7b0d 100644 --- a/app/soapbox/features/report/components/status_check_box.js +++ b/app/soapbox/features/report/components/status_check_box.js @@ -26,7 +26,7 @@ export default class StatusCheckBox extends React.PureComponent { if (status.get('media_attachments').size > 0) { if (status.get('media_attachments').some(item => item.get('type') === 'unknown')) { - + // Do nothing } else if (status.getIn(['media_attachments', 0, 'type']) === 'video') { const video = status.getIn(['media_attachments', 0]); diff --git a/app/soapbox/features/status/components/action_bar.js b/app/soapbox/features/status/components/action_bar.js index 9012c98b8..b435c77a4 100644 --- a/app/soapbox/features/status/components/action_bar.js +++ b/app/soapbox/features/status/components/action_bar.js @@ -244,7 +244,7 @@ class ActionBar extends React.PureComponent { textarea.select(); document.execCommand('copy'); } catch (e) { - + // Do nothing } finally { document.body.removeChild(textarea); } diff --git a/app/soapbox/features/ui/index.js b/app/soapbox/features/ui/index.js index 49d58aca7..43d4b7b7c 100644 --- a/app/soapbox/features/ui/index.js +++ b/app/soapbox/features/ui/index.js @@ -336,7 +336,7 @@ class UI extends React.PureComponent { try { e.dataTransfer.dropEffect = 'copy'; } catch (err) { - + // Do nothing } return false; diff --git a/app/soapbox/reducers/__tests__/auth-test.js b/app/soapbox/reducers/__tests__/auth-test.js index 77a9b1965..6b367bf85 100644 --- a/app/soapbox/reducers/__tests__/auth-test.js +++ b/app/soapbox/reducers/__tests__/auth-test.js @@ -164,9 +164,11 @@ describe('auth reducer', () => { }; const state = fromJS({ - users: { '4567': { id: '4567', access_token: 'ABCDEFG' } }, - users: { '8901': { id: '1234', access_token: 'ABCDEFG' } }, - users: { '5432': { id: '5432', access_token: 'HIJKLMN' } }, + users: { + '4567': { id: '4567', access_token: 'ABCDEFG' }, + '8901': { id: '1234', access_token: 'ABCDEFG' }, + '5432': { id: '5432', access_token: 'HIJKLMN' }, + }, }); const expected = fromJS({ diff --git a/app/soapbox/reducers/__tests__/list_editor-test.js b/app/soapbox/reducers/__tests__/list_editor-test.js index 356bc8d7e..09ec6ab02 100644 --- a/app/soapbox/reducers/__tests__/list_editor-test.js +++ b/app/soapbox/reducers/__tests__/list_editor-test.js @@ -137,7 +137,6 @@ describe('list_editor reducer', () => { }); it('should handle LIST_UPDATE_FAIL', () => { - debugger; const state = ImmutableMap({ isSubmitting: true, }); diff --git a/app/soapbox/reducers/__tests__/modal-test.js b/app/soapbox/reducers/__tests__/modal-test.js index 17125d072..09281e82f 100644 --- a/app/soapbox/reducers/__tests__/modal-test.js +++ b/app/soapbox/reducers/__tests__/modal-test.js @@ -19,7 +19,6 @@ describe('modal reducer', () => { modalType: 'type1', modalProps: { props1: '1' }, }; - debugger; expect(reducer(state, action)).toMatchObject({ modalType: 'type1', modalProps: { props1: '1' }, @@ -34,7 +33,6 @@ describe('modal reducer', () => { const action = { type: MODAL_CLOSE, }; - debugger; expect(reducer(state, action)).toMatchObject({ modalType: null, modalProps: {}, diff --git a/app/soapbox/reducers/notifications.js b/app/soapbox/reducers/notifications.js index 9d819f4f3..9e2c1287d 100644 --- a/app/soapbox/reducers/notifications.js +++ b/app/soapbox/reducers/notifications.js @@ -55,6 +55,9 @@ const notificationToMap = notification => ImmutableMap({ // https://gitlab.com/soapbox-pub/soapbox-fe/-/issues/424 const isValid = notification => Boolean(notification.account.id); +const countUnseen = notifications => notifications.reduce((acc, cur) => + get(cur, ['pleroma', 'is_seen'], false) === false ? acc + 1 : acc, 0); + const normalizeNotification = (state, notification) => { const top = state.get('top'); @@ -78,12 +81,16 @@ const processRawNotifications = notifications => ( const expandNormalizedNotifications = (state, notifications, next) => { const items = processRawNotifications(notifications); + const unread = state.get('unread'); + const legacyUnread = countUnseen(notifications); return state.withMutations(mutable => { mutable.update('items', map => map.merge(items).sort(comparator)); if (!next) mutable.set('hasMore', false); mutable.set('isLoading', false); + + mutable.set('unread', Math.max(legacyUnread, unread)); }); }; @@ -127,9 +134,6 @@ const updateNotificationsQueue = (state, notification, intlMessages, intlLocale) }); }; -const countUnseen = notifications => notifications.reduce((acc, cur) => - get(cur, ['pleroma', 'is_seen'], false) === false ? acc + 1 : acc, 0); - export default function notifications(state = initialState, action) { switch(action.type) { case NOTIFICATIONS_EXPAND_REQUEST: @@ -150,9 +154,7 @@ export default function notifications(state = initialState, action) { mutable.set('totalQueuedNotificationsCount', 0); }); case NOTIFICATIONS_EXPAND_SUCCESS: - const legacyUnread = countUnseen(action.notifications); - return expandNormalizedNotifications(state, action.notifications, action.next) - .merge({ unread: Math.max(legacyUnread, state.get('unread')) }); + return expandNormalizedNotifications(state, action.notifications, action.next); case ACCOUNT_BLOCK_SUCCESS: return filterNotifications(state, action.relationship); case ACCOUNT_MUTE_SUCCESS: diff --git a/app/soapbox/reducers/security.js b/app/soapbox/reducers/security.js index 4fbeea042..b50b39801 100644 --- a/app/soapbox/reducers/security.js +++ b/app/soapbox/reducers/security.js @@ -8,13 +8,18 @@ const initialState = ImmutableMap({ tokens: ImmutableList(), }); +const deleteToken = (state, tokenId) => { + return state.update('tokens', tokens => { + return tokens.filterNot(token => token.get('id') === tokenId); + }); +}; + export default function security(state = initialState, action) { switch(action.type) { case FETCH_TOKENS_SUCCESS: return state.set('tokens', fromJS(action.tokens)); case REVOKE_TOKEN_SUCCESS: - const idx = state.get('tokens').findIndex(t => t.get('id') === action.id); - return state.deleteIn(['tokens', idx]); + return deleteToken(state, action.id); default: return state; } diff --git a/app/soapbox/settings.js b/app/soapbox/settings.js index e3f809435..1acaeee91 100644 --- a/app/soapbox/settings.js +++ b/app/soapbox/settings.js @@ -38,6 +38,7 @@ export default class Settings { try { localStorage.removeItem(key); } catch (e) { + // Do nothing } } return data; diff --git a/app/soapbox/utils/numbers.js b/app/soapbox/utils/numbers.js index 000ca3178..434473b40 100644 --- a/app/soapbox/utils/numbers.js +++ b/app/soapbox/utils/numbers.js @@ -1,7 +1,7 @@ import React from 'react'; import { FormattedNumber } from 'react-intl'; -const isNumber = number => typeof number === 'number' && number !== NaN; +const isNumber = number => typeof number === 'number' && !isNaN(number); export const shortNumberFormat = number => { if (!isNumber(number)) return '•'; diff --git a/app/soapbox/utils/resize_image.js b/app/soapbox/utils/resize_image.js index 45db240cb..ffb4ef936 100644 --- a/app/soapbox/utils/resize_image.js +++ b/app/soapbox/utils/resize_image.js @@ -1,3 +1,4 @@ +/* eslint-disable no-case-declarations */ import EXIF from 'exif-js'; const MAX_IMAGE_PIXELS = 2073600; // 1920x1080px diff --git a/webpack/translationRunner.js b/webpack/translationRunner.js index fb24b8ab6..5f75ee757 100644 --- a/webpack/translationRunner.js +++ b/webpack/translationRunner.js @@ -114,12 +114,11 @@ function findVariablesinAST(tree) { break; case parser.TYPE.plural: result.add(element.value); - const subTrees = Object.values(element.options).map((option) => option.value); - subTrees.forEach((subtree) => { - findVariablesinAST(subtree).forEach((variable) => { - result.add(variable); - }); - }); + Object.values(element.options) + .map(option => option.value) + .forEach(subtree => + findVariablesinAST(subtree) + .forEach(variable => result.add(variable))); break; case parser.TYPE.literal: break;