Skip to content

Commit

Permalink
deps: Upgrade prettier.
Browse files Browse the repository at this point in the history
Looks like this requires some formatting changes. Some of them look
OK, some neutral [1]. In a few places where we'd really like to keep
test data compact, add some `prettier-ignore`s.

Changelog: https://github.com/prettier/prettier/blob/main/CHANGELOG.md

[1] zulip#4789 (comment)
  • Loading branch information
chrisbobbe committed Jun 9, 2021
1 parent 8011e73 commit 7b712e0
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 53 deletions.
1 change: 1 addition & 0 deletions src/__tests__/jsBackport-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { objectFromEntries } from '../jsBackport';
describe('objectFromEntries', () => {
test('basic', () => {
expect(
// prettier-ignore
objectFromEntries([['number', 1], ['null', null], ['obj', {}], ['undef', undefined]]),
).toStrictEqual({ number: 1, null: null, obj: {}, undef: undefined });
});
Expand Down
28 changes: 12 additions & 16 deletions src/account/accountsSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export type AccountStatus = {| ...Identity, isLoggedIn: boolean |};
* This should be used in preference to `getAccounts` where we don't
* actually need the API keys, but just need to know whether we have them.
*/
export const getAccountStatuses: Selector<$ReadOnlyArray<AccountStatus>> = createSelector(
getAccounts,
accounts =>
accounts.map(({ realm, email, apiKey }) => ({ realm, email, isLoggedIn: apiKey !== '' })),
export const getAccountStatuses: Selector<
$ReadOnlyArray<AccountStatus>,
> = createSelector(getAccounts, accounts =>
accounts.map(({ realm, email, apiKey }) => ({ realm, email, isLoggedIn: apiKey !== '' })),
);

/** The list of known accounts, reduced to `Identity`. */
Expand Down Expand Up @@ -96,15 +96,12 @@ export const tryGetCurrentRealm = (state: GlobalState): URL | void =>
* * `getAuth` for use in the bulk of the app, operating on a logged-in
* active account.
*/
export const tryGetAuth: Selector<Auth | void> = createSelector(
tryGetActiveAccount,
account => {
if (!account || account.apiKey === '') {
return undefined;
}
return authOfAccount(account);
},
);
export const tryGetAuth: Selector<Auth | void> = createSelector(tryGetActiveAccount, account => {
if (!account || account.apiKey === '') {
return undefined;
}
return authOfAccount(account);
});

/**
* True just if there is an active, logged-in account.
Expand Down Expand Up @@ -136,9 +133,8 @@ export const getAuth = (state: GlobalState): Auth => {
*
* See `getAuth` and `tryGetAuth` for discussion.
*/
export const getIdentity: Selector<Identity> = createSelector(
getAuth,
auth => identityOfAuth(auth),
export const getIdentity: Selector<Identity> = createSelector(getAuth, auth =>
identityOfAuth(auth),
);

/**
Expand Down
1 change: 1 addition & 0 deletions src/boot/__tests__/replaceRevive-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const data = {
[SERIALIZED_TYPE_FIELD_NAME]: { c: [3] },
},
}),
// prettier-ignore
mapNumKeys: Immutable.Map([[1, 1], [2, 2], [3, 3], [4, 4]]),
emptyMap: Immutable.Map([]),
zulipVersion: new ZulipVersion('3.0.0'),
Expand Down
3 changes: 2 additions & 1 deletion src/chat/__tests__/flagsReducer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ describe('flagsReducer', () => {

const action = deepFreeze({
type: MESSAGE_FETCH_COMPLETE,
messages: [{ id: 1, flags: ['read'] }, { id: 2, flags: [] }],
// prettier-ignore
messages: [{ id: 1, flags: ['read'] }, { id: 2, flags: [] }]
});

const expectedState = {
Expand Down
10 changes: 8 additions & 2 deletions src/chat/narrowsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,17 @@ const updateFlagNarrow = (state, narrowStr, op, messageIds): NarrowsState => {
}
switch (op) {
case 'add': {
return state.set(narrowStr, [...value, ...messageIds].sort((a, b) => a - b));
return state.set(
narrowStr,
[...value, ...messageIds].sort((a, b) => a - b),
);
}
case 'remove': {
const messageIdSet = new Set(messageIds);
return state.set(narrowStr, value.filter(id => !messageIdSet.has(id)));
return state.set(
narrowStr,
value.filter(id => !messageIdSet.has(id)),
);
}
default:
ensureUnreachable(op);
Expand Down
8 changes: 3 additions & 5 deletions src/compose/MentionWarnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,9 @@ class MentionWarnings extends PureComponent<Props, State> {

let isSubscribed: boolean;
try {
isSubscribed = (await api.getSubscriptionToStream(
auth,
mentionedUser.user_id,
stream.stream_id,
)).is_subscribed;
isSubscribed = (
await api.getSubscriptionToStream(auth, mentionedUser.user_id, stream.stream_id)
).is_subscribed;
} catch (err) {
this.showSubscriptionStatusLoadError(mentionedUser);
return;
Expand Down
14 changes: 8 additions & 6 deletions src/emoji/emojiSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ export const getActiveImageEmojiById: Selector<RealmEmojiById> = createSelector(
},
);

export const getAllImageEmojiByCode: Selector<{| [string]: ImageEmojiType |}> = createSelector(
getAllImageEmojiById,
emojis => objectFromEntries(Object.keys(emojis).map(id => [emojis[id].code, emojis[id]])),
export const getAllImageEmojiByCode: Selector<{|
[string]: ImageEmojiType,
|}> = createSelector(getAllImageEmojiById, emojis =>
objectFromEntries(Object.keys(emojis).map(id => [emojis[id].code, emojis[id]])),
);

export const getActiveImageEmojiByName: Selector<{| [string]: ImageEmojiType |}> = createSelector(
getActiveImageEmojiById,
emojis => objectFromEntries(Object.keys(emojis).map(id => [emojis[id].name, emojis[id]])),
export const getActiveImageEmojiByName: Selector<{|
[string]: ImageEmojiType,
|}> = createSelector(getActiveImageEmojiById, emojis =>
objectFromEntries(Object.keys(emojis).map(id => [emojis[id].name, emojis[id]])),
);
8 changes: 8 additions & 0 deletions src/pm-conversations/__tests__/pmConversationsModel-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('reducer', () => {
{ user_ids: [2, 1].map(makeUserId), max_message_id: 345 }, // user_ids out of order
];
const expected = {
// prettier-ignore
map: Immutable.Map([['', 234], ['1', 123], ['1,2', 345]]),
sorted: Immutable.List(['1,2', '', '1']),
};
Expand All @@ -62,6 +63,7 @@ describe('reducer', () => {
action([msg(45, [user1]), msg(123, [user1, user2]), eg.streamMessage(), msg(234, [user1])]),
);
expect(state).toEqual({
// prettier-ignore
map: Immutable.Map([['1', 234], ['1,2', 123]]),
sorted: Immutable.List(['1', '1,2']),
});
Expand All @@ -79,6 +81,7 @@ describe('reducer', () => {
]),
);
expect(state).toEqual({
// prettier-ignore
map: Immutable.Map([['1', 234], ['1,2', 456], ['2', 345]]),
sorted: Immutable.List(['1,2', '2', '1']),
});
Expand All @@ -103,6 +106,7 @@ describe('reducer', () => {
// This is here mostly for checked documentation of what's in
// baseState, to help in reading the other test cases.
expect(baseState).toEqual({
// prettier-ignore
map: Immutable.Map([['1', 234], ['1,2', 123]]),
sorted: Immutable.List(['1', '1,2']),
});
Expand All @@ -116,6 +120,7 @@ describe('reducer', () => {
test('new conversation, newest message', () => {
const state = reducer(baseState, action(345, [user2]));
expect(state).toEqual({
// prettier-ignore
map: Immutable.Map([['1', 234], ['1,2', 123], ['2', 345]]),
sorted: Immutable.List(['2', '1', '1,2']),
});
Expand All @@ -124,6 +129,7 @@ describe('reducer', () => {
test('new conversation, not newest message', () => {
const state = reducer(baseState, action(159, [user2]));
expect(state).toEqual({
// prettier-ignore
map: Immutable.Map([['1', 234], ['1,2', 123], ['2', 159]]),
sorted: Immutable.List(['1', '2', '1,2']),
});
Expand All @@ -132,6 +138,7 @@ describe('reducer', () => {
test('existing conversation, newest message', () => {
const state = reducer(baseState, action(345, [user1, user2]));
expect(state).toEqual({
// prettier-ignore
map: Immutable.Map([['1', 234], ['1,2', 345]]),
sorted: Immutable.List(['1,2', '1']),
});
Expand All @@ -140,6 +147,7 @@ describe('reducer', () => {
test('existing newest conversation, newest message', () => {
const state = reducer(baseState, action(345, [user1]));
expect(state).toEqual({
// prettier-ignore
map: Immutable.Map([['1', 345], ['1,2', 123]]),
sorted: Immutable.List(['1', '1,2']),
});
Expand Down
5 changes: 4 additions & 1 deletion src/pm-conversations/pmConversationsModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ function keyOfUsers(ids: UserId[], ownUserId: UserId): PmConversationKey {

// Input must indeed be a PM, else throws.
function keyOfPrivateMessage(msg: Message | Outbox, ownUserId: UserId): PmConversationKey {
return keyOfUsers(recipientsOfPrivateMessage(msg).map(r => r.id), ownUserId);
return keyOfUsers(
recipientsOfPrivateMessage(msg).map(r => r.id),
ownUserId,
);
}

/** The users in the conversation, other than self. */
Expand Down
12 changes: 8 additions & 4 deletions src/pm-conversations/pmConversationsSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ function getRecentConversationsModernImpl(
return null;
}

const unreadsKey = pmUnreadsKeyFromPmKeyIds(keyRecipients.map(r => r.user_id), ownUserId);
const unreadsKey = pmUnreadsKeyFromPmKeyIds(
keyRecipients.map(r => r.user_id),
ownUserId,
);

const msgId = map.get(recentsKey);
invariant(msgId !== undefined, 'pm-conversations: key in sorted should be in map');
Expand All @@ -128,7 +131,8 @@ const getServerIsOld: Selector<boolean> = createSelector(
export const getRecentConversations = (state: GlobalState): PmConversationData[] =>
getServerIsOld(state) ? getRecentConversationsLegacy(state) : getRecentConversationsModern(state);

export const getUnreadConversations: Selector<PmConversationData[]> = createSelector(
getRecentConversations,
conversations => conversations.filter(c => c.unread > 0),
export const getUnreadConversations: Selector<
PmConversationData[],
> = createSelector(getRecentConversations, conversations =>
conversations.filter(c => c.unread > 0),
);
6 changes: 3 additions & 3 deletions src/presence/presenceReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export default (state: PresenceState = initialState, action: Action): PresenceSt

case EVENT_PRESENCE: {
// A presence event should have either "active" or "idle" status
const isPresenceEventValid = !!objectEntries(action.presence).find(
([device, devicePresence]) => ['active', 'idle'].includes(devicePresence.status),
);
const isPresenceEventValid = !!objectEntries(
action.presence,
).find(([device, devicePresence]) => ['active', 'idle'].includes(devicePresence.status));
if (!isPresenceEventValid) {
return state;
}
Expand Down
2 changes: 2 additions & 0 deletions src/subscriptions/__tests__/subscriptionSelectors-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('getStreamsById', () => {
streams: [{ stream_id: 1 }, { stream_id: 2 }],
});

// prettier-ignore
const expectedState = new Map([[1, { stream_id: 1 }], [2, { stream_id: 2 }]]);

const streamsById = getStreamsById(state);
Expand All @@ -50,6 +51,7 @@ describe('getSubscriptionsById', () => {
subscriptions: [{ stream_id: 1 }, { stream_id: 2 }],
});

// prettier-ignore
const expectedState = new Map([[1, { stream_id: 1 }], [2, { stream_id: 2 }]]);

const subscriptionsById = getSubscriptionsById(state);
Expand Down
4 changes: 3 additions & 1 deletion src/topics/__tests__/topicsSelectors-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ describe('getTopicsForNarrow', () => {
const state = eg.reduxState({
streams: [stream],
topics: {
[stream.stream_id]: [{ name: 'hi', max_id: 123 }, { name: 'wow', max_id: 234 }],
// prettier-ignore
[stream.stream_id]: [{ name: 'hi', max_id: 123 }, { name: 'wow', max_id: 234 }]
},
});

Expand Down Expand Up @@ -104,6 +105,7 @@ describe('getTopicsForStream', () => {
{ name: 'topic 5', max_id: 9 },
],
},
// prettier-ignore
mute: [['stream 1', 'topic 1'], ['stream 1', 'topic 3'], ['stream 2', 'topic 2']],
unread: [
eg.streamMessage({ stream_id: 1, subject: 'topic 2', id: 1 }),
Expand Down
5 changes: 2 additions & 3 deletions src/unread/unreadSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ export const getUnreadByPms: Selector<{| [number]: number |}> = createSelector(
*
* See also `getUnreadHuddlesTotal`, for group PMs.
*/
export const getUnreadPmsTotal: Selector<number> = createSelector(
getUnreadPms,
unreadPms => unreadPms.reduce((total, pm) => total + pm.unread_message_ids.length, 0),
export const getUnreadPmsTotal: Selector<number> = createSelector(getUnreadPms, unreadPms =>
unreadPms.reduce((total, pm) => total + pm.unread_message_ids.length, 0),
);

/**
Expand Down
8 changes: 2 additions & 6 deletions src/users/userSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,8 @@ export const getUsersById: Selector<Map<UserId, User>> = createSelector(
*
* See `getAllUsers`.
*/
export const getSortedUsers: Selector<User[]> = createSelector(
getUsers,
users =>
[...users].sort((x1, x2) =>
x1.full_name.toLowerCase().localeCompare(x2.full_name.toLowerCase()),
),
export const getSortedUsers: Selector<User[]> = createSelector(getUsers, users =>
[...users].sort((x1, x2) => x1.full_name.toLowerCase().localeCompare(x2.full_name.toLowerCase())),
);

/**
Expand Down
5 changes: 4 additions & 1 deletion src/utils/recipient.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ export const pmKeyRecipientsFromMessage = (
if (message.type !== 'private') {
throw new Error('pmKeyRecipientsFromMessage: expected PM, got stream message');
}
return pmKeyRecipientsFromIds(recipientsOfPrivateMessage(message).map(r => r.id), ownUserId);
return pmKeyRecipientsFromIds(
recipientsOfPrivateMessage(message).map(r => r.id),
ownUserId,
);
};

/**
Expand Down
5 changes: 4 additions & 1 deletion src/utils/unread.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ export const filterUnreadMessagesInRange = (
const messagesInRange = messages
.filter(msg => !msg.isOutbox)
.filter(msg => msg.id >= fromId && msg.id <= toId);
return filterUnreadMessageIds(messagesInRange.map(x => x.id), flags);
return filterUnreadMessageIds(
messagesInRange.map(x => x.id),
flags,
);
};
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9556,9 +9556,9 @@ prettier-linter-helpers@^1.0.0:
fast-diff "^1.1.2"

prettier@^1.18.2, prettier@^1.7.0:
version "1.18.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.18.2.tgz#6823e7c5900017b4bd3acf46fe9ac4b4d7bda9ea"
integrity sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw==
version "1.19.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==

prettier@^2.0.0, prettier@^2.1.1:
version "2.3.1"
Expand Down

0 comments on commit 7b712e0

Please sign in to comment.