Merge branch 'eslint-recommended' into 'develop'

eslint: extend 'eslint:recommended'

See merge request soapbox-pub/soapbox-fe!661
This commit is contained in:
Alex Gleason 2021-08-03 19:57:41 +00:00
commit dcd964dba9
19 changed files with 51 additions and 42 deletions

View File

@ -1,6 +1,8 @@
module.exports = { module.exports = {
root: true, root: true,
extends: 'eslint:recommended',
env: { env: {
browser: true, browser: true,
node: true, node: true,
@ -79,8 +81,10 @@ module.exports = {
}, },
], ],
'no-extra-semi': 'error', 'no-extra-semi': 'error',
'no-const-assign': 'error',
'no-fallthrough': 'error', 'no-fallthrough': 'error',
'no-irregular-whitespace': 'error', 'no-irregular-whitespace': 'error',
'no-loop-func': 'error',
'no-mixed-spaces-and-tabs': 'error', 'no-mixed-spaces-and-tabs': 'error',
'no-nested-ternary': 'warn', 'no-nested-ternary': 'warn',
'no-trailing-spaces': 'warn', 'no-trailing-spaces': 'warn',
@ -95,6 +99,8 @@ module.exports = {
ignoreRestSiblings: true, ignoreRestSiblings: true,
}, },
], ],
'no-useless-escape': 'warn',
'no-var': 'error',
'object-curly-spacing': ['error', 'always'], 'object-curly-spacing': ['error', 'always'],
'padded-blocks': [ 'padded-blocks': [
'error', 'error',
@ -102,14 +108,11 @@ module.exports = {
classes: 'always', classes: 'always',
}, },
], ],
'prefer-const': 'error',
quotes: ['error', 'single'], quotes: ['error', 'single'],
semi: 'error', semi: 'error',
strict: 'off', strict: 'off',
'valid-typeof': 'error', 'valid-typeof': 'error',
'prefer-const': 'error',
'no-loop-func': 'error',
'no-const-assign': 'error',
'no-var': 'error',
'react/jsx-boolean-value': 'error', 'react/jsx-boolean-value': 'error',
'react/jsx-closing-bracket-location': ['error', 'line-aligned'], 'react/jsx-closing-bracket-location': ['error', 'line-aligned'],

View File

@ -35,7 +35,9 @@ function Blurhash({
useEffect(() => { useEffect(() => {
const { current: canvas } = canvasRef; 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; if (dummy || !hash) return;

View File

@ -137,7 +137,7 @@ class RelativeTimestamp extends React.Component {
this.state.now !== nextState.now; this.state.now !== nextState.now;
} }
componentDidUpdate(prevProps) { UNSAFE_componentWillReceiveProps(prevProps) {
if (this.props.timestamp !== prevProps.timestamp) { if (this.props.timestamp !== prevProps.timestamp) {
this.setState({ now: Date.now() }); this.setState({ now: Date.now() });
} }
@ -147,7 +147,7 @@ class RelativeTimestamp extends React.Component {
this._scheduleNextUpdate(this.props, this.state); this._scheduleNextUpdate(this.props, this.state);
} }
componentDidUpdate() { UNSAFE_componentWillUpdate() {
this._scheduleNextUpdate(); this._scheduleNextUpdate();
} }

View File

@ -93,8 +93,6 @@ class StatusActionBar extends ImmutablePureComponent {
allowedEmoji: ImmutablePropTypes.list, allowedEmoji: ImmutablePropTypes.list,
emojiSelectorFocused: PropTypes.bool, emojiSelectorFocused: PropTypes.bool,
handleEmojiSelectorUnfocus: PropTypes.func.isRequired, handleEmojiSelectorUnfocus: PropTypes.func.isRequired,
emojiSelectorFocused: PropTypes.bool,
handleEmojiSelectorUnfocus: PropTypes.func.isRequired,
}; };
static defaultProps = { static defaultProps = {
@ -245,7 +243,7 @@ class StatusActionBar extends ImmutablePureComponent {
textarea.select(); textarea.select();
document.execCommand('copy'); document.execCommand('copy');
} catch (e) { } catch (e) {
// Do nothing
} finally { } finally {
document.body.removeChild(textarea); document.body.removeChild(textarea);
} }

View File

@ -43,7 +43,7 @@ class ReportStatus extends ImmutablePureComponent {
if (status.get('media_attachments').size > 0) { if (status.get('media_attachments').size > 0) {
if (status.get('media_attachments').some(item => item.get('type') === 'unknown')) { if (status.get('media_attachments').some(item => item.get('type') === 'unknown')) {
// Do nothing
} else if (status.getIn(['media_attachments', 0, 'type']) === 'video') { } else if (status.getIn(['media_attachments', 0, 'type']) === 'video') {
const video = status.getIn(['media_attachments', 0]); const video = status.getIn(['media_attachments', 0]);

View File

@ -31,7 +31,7 @@ const stringSupplant = function(str, values) {
}; };
export const urlRegex = (function() { 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.invalid_chars_group = /\uFFFE\uFEFF\uFFFF\u202A-\u202E/;
regexen.punct = /\!'#%&'\(\)*\+,\\\-\.\/:;<=>\?@\[\]\^_{|}~\$/; regexen.punct = /\!'#%&'\(\)*\+,\\\-\.\/:;<=>\?@\[\]\^_{|}~\$/;
regexen.validUrlPrecedingChars = regexSupplant(/(?:[^A-Za-z0-9@$##{invalid_chars_group}]|^)/); regexen.validUrlPrecedingChars = regexSupplant(/(?:[^A-Za-z0-9@$##{invalid_chars_group}]|^)/);

View File

@ -70,7 +70,6 @@ const stringFromCodePoint = _String.fromCodePoint || function() {
return result; return result;
}; };
const _JSON = JSON; const _JSON = JSON;
const COLONS_REGEX = /^(?:\:([^\:]+)\:)(?:\:skin-tone-(\d)\:)?$/; 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]; emoji = data.short_names[emoji];
} }
if (data.emojis.hasOwnProperty(emoji)) { if (Object.prototype.hasOwnProperty.call(data.emojis, emoji)) {
emojiData = data.emojis[emoji]; emojiData = data.emojis[emoji];
} }
} else if (emoji.id) { } 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]; 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]; emojiData = data.emojis[emoji.id];
skin = skin || emoji.skin; skin = skin || emoji.skin;
} }
@ -212,7 +211,7 @@ function deepMerge(a, b) {
const originalValue = a[key]; const originalValue = a[key];
let value = originalValue; let value = originalValue;
if (b.hasOwnProperty(key)) { if (Object.prototype.hasOwnProperty.call(b, key)) {
value = b[key]; value = b[key];
} }

View File

@ -26,7 +26,7 @@ export default class StatusCheckBox extends React.PureComponent {
if (status.get('media_attachments').size > 0) { if (status.get('media_attachments').size > 0) {
if (status.get('media_attachments').some(item => item.get('type') === 'unknown')) { if (status.get('media_attachments').some(item => item.get('type') === 'unknown')) {
// Do nothing
} else if (status.getIn(['media_attachments', 0, 'type']) === 'video') { } else if (status.getIn(['media_attachments', 0, 'type']) === 'video') {
const video = status.getIn(['media_attachments', 0]); const video = status.getIn(['media_attachments', 0]);

View File

@ -244,7 +244,7 @@ class ActionBar extends React.PureComponent {
textarea.select(); textarea.select();
document.execCommand('copy'); document.execCommand('copy');
} catch (e) { } catch (e) {
// Do nothing
} finally { } finally {
document.body.removeChild(textarea); document.body.removeChild(textarea);
} }

View File

@ -336,7 +336,7 @@ class UI extends React.PureComponent {
try { try {
e.dataTransfer.dropEffect = 'copy'; e.dataTransfer.dropEffect = 'copy';
} catch (err) { } catch (err) {
// Do nothing
} }
return false; return false;

View File

@ -164,9 +164,11 @@ describe('auth reducer', () => {
}; };
const state = fromJS({ const state = fromJS({
users: { '4567': { id: '4567', access_token: 'ABCDEFG' } }, users: {
users: { '8901': { id: '1234', access_token: 'ABCDEFG' } }, '4567': { id: '4567', access_token: 'ABCDEFG' },
users: { '5432': { id: '5432', access_token: 'HIJKLMN' } }, '8901': { id: '1234', access_token: 'ABCDEFG' },
'5432': { id: '5432', access_token: 'HIJKLMN' },
},
}); });
const expected = fromJS({ const expected = fromJS({

View File

@ -137,7 +137,6 @@ describe('list_editor reducer', () => {
}); });
it('should handle LIST_UPDATE_FAIL', () => { it('should handle LIST_UPDATE_FAIL', () => {
debugger;
const state = ImmutableMap({ const state = ImmutableMap({
isSubmitting: true, isSubmitting: true,
}); });

View File

@ -19,7 +19,6 @@ describe('modal reducer', () => {
modalType: 'type1', modalType: 'type1',
modalProps: { props1: '1' }, modalProps: { props1: '1' },
}; };
debugger;
expect(reducer(state, action)).toMatchObject({ expect(reducer(state, action)).toMatchObject({
modalType: 'type1', modalType: 'type1',
modalProps: { props1: '1' }, modalProps: { props1: '1' },
@ -34,7 +33,6 @@ describe('modal reducer', () => {
const action = { const action = {
type: MODAL_CLOSE, type: MODAL_CLOSE,
}; };
debugger;
expect(reducer(state, action)).toMatchObject({ expect(reducer(state, action)).toMatchObject({
modalType: null, modalType: null,
modalProps: {}, modalProps: {},

View File

@ -55,6 +55,9 @@ const notificationToMap = notification => ImmutableMap({
// https://gitlab.com/soapbox-pub/soapbox-fe/-/issues/424 // https://gitlab.com/soapbox-pub/soapbox-fe/-/issues/424
const isValid = notification => Boolean(notification.account.id); 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 normalizeNotification = (state, notification) => {
const top = state.get('top'); const top = state.get('top');
@ -78,12 +81,16 @@ const processRawNotifications = notifications => (
const expandNormalizedNotifications = (state, notifications, next) => { const expandNormalizedNotifications = (state, notifications, next) => {
const items = processRawNotifications(notifications); const items = processRawNotifications(notifications);
const unread = state.get('unread');
const legacyUnread = countUnseen(notifications);
return state.withMutations(mutable => { return state.withMutations(mutable => {
mutable.update('items', map => map.merge(items).sort(comparator)); mutable.update('items', map => map.merge(items).sort(comparator));
if (!next) mutable.set('hasMore', false); if (!next) mutable.set('hasMore', false);
mutable.set('isLoading', 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) { export default function notifications(state = initialState, action) {
switch(action.type) { switch(action.type) {
case NOTIFICATIONS_EXPAND_REQUEST: case NOTIFICATIONS_EXPAND_REQUEST:
@ -150,9 +154,7 @@ export default function notifications(state = initialState, action) {
mutable.set('totalQueuedNotificationsCount', 0); mutable.set('totalQueuedNotificationsCount', 0);
}); });
case NOTIFICATIONS_EXPAND_SUCCESS: case NOTIFICATIONS_EXPAND_SUCCESS:
const legacyUnread = countUnseen(action.notifications); return expandNormalizedNotifications(state, action.notifications, action.next);
return expandNormalizedNotifications(state, action.notifications, action.next)
.merge({ unread: Math.max(legacyUnread, state.get('unread')) });
case ACCOUNT_BLOCK_SUCCESS: case ACCOUNT_BLOCK_SUCCESS:
return filterNotifications(state, action.relationship); return filterNotifications(state, action.relationship);
case ACCOUNT_MUTE_SUCCESS: case ACCOUNT_MUTE_SUCCESS:

View File

@ -8,13 +8,18 @@ const initialState = ImmutableMap({
tokens: ImmutableList(), 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) { export default function security(state = initialState, action) {
switch(action.type) { switch(action.type) {
case FETCH_TOKENS_SUCCESS: case FETCH_TOKENS_SUCCESS:
return state.set('tokens', fromJS(action.tokens)); return state.set('tokens', fromJS(action.tokens));
case REVOKE_TOKEN_SUCCESS: case REVOKE_TOKEN_SUCCESS:
const idx = state.get('tokens').findIndex(t => t.get('id') === action.id); return deleteToken(state, action.id);
return state.deleteIn(['tokens', idx]);
default: default:
return state; return state;
} }

View File

@ -38,6 +38,7 @@ export default class Settings {
try { try {
localStorage.removeItem(key); localStorage.removeItem(key);
} catch (e) { } catch (e) {
// Do nothing
} }
} }
return data; return data;

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import { FormattedNumber } from 'react-intl'; 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 => { export const shortNumberFormat = number => {
if (!isNumber(number)) return '•'; if (!isNumber(number)) return '•';

View File

@ -1,3 +1,4 @@
/* eslint-disable no-case-declarations */
import EXIF from 'exif-js'; import EXIF from 'exif-js';
const MAX_IMAGE_PIXELS = 2073600; // 1920x1080px const MAX_IMAGE_PIXELS = 2073600; // 1920x1080px

View File

@ -114,12 +114,11 @@ function findVariablesinAST(tree) {
break; break;
case parser.TYPE.plural: case parser.TYPE.plural:
result.add(element.value); result.add(element.value);
const subTrees = Object.values(element.options).map((option) => option.value); Object.values(element.options)
subTrees.forEach((subtree) => { .map(option => option.value)
findVariablesinAST(subtree).forEach((variable) => { .forEach(subtree =>
result.add(variable); findVariablesinAST(subtree)
}); .forEach(variable => result.add(variable)));
});
break; break;
case parser.TYPE.literal: case parser.TYPE.literal:
break; break;