From 5a8f484a03d3ac0cfde1c1a0b3500ac8575de67a Mon Sep 17 00:00:00 2001 From: jamiebuilds-signal <113370520+jamiebuilds-signal@users.noreply.github.com> Date: Tue, 13 Sep 2022 14:48:09 -0700 Subject: [PATCH] Enable brace-style eslint rules --- .eslintrc.js | 13 ++++++++++++- ts/components/stickers/StickerButton.tsx | 4 +++- ts/quill/emoji/completion.tsx | 12 +++++++++--- ts/quill/mentions/completion.tsx | 4 +++- ts/test-node/quill/mentions/matchers_test.ts | 4 +++- ts/textsecure/ContactsParser.ts | 3 +++ ts/textsecure/MessageReceiver.ts | 3 +++ ts/textsecure/storage/User.ts | 20 +++++++++++++++----- ts/util/iterables.ts | 4 +++- 9 files changed, 54 insertions(+), 13 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 15f5ecd0a..facd2e136 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -15,6 +15,10 @@ const rules = { }, ], + // No omitting braces, keep on the same line + 'brace-style': ['error', '1tbs', { allowSingleLine: false }], + curly: ['error', 'all'], + // prevents us from accidentally checking in exclusive tests (`.only`): 'mocha/no-exclusive-tests': 'error', @@ -109,12 +113,19 @@ const rules = { '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.', }, ], - curly: 'error', }; const typescriptRules = { ...rules, + // Override brace style to enable typescript-specific syntax + 'brace-style': 'off', + '@typescript-eslint/brace-style': [ + 'error', + '1tbs', + { allowSingleLine: false }, + ], + '@typescript-eslint/array-type': ['error', { default: 'generic' }], 'no-restricted-imports': 'off', diff --git a/ts/components/stickers/StickerButton.tsx b/ts/components/stickers/StickerButton.tsx index 1c80262df..56ce05329 100644 --- a/ts/components/stickers/StickerButton.tsx +++ b/ts/components/stickers/StickerButton.tsx @@ -70,7 +70,9 @@ export const StickerButton = React.memo( const setOpen = React.useCallback( (value: boolean) => { internalSetOpen(value); - if (onOpenStateChanged) onOpenStateChanged(value); + if (onOpenStateChanged) { + onOpenStateChanged(value); + } }, [internalSetOpen, onOpenStateChanged] ); diff --git a/ts/quill/emoji/completion.tsx b/ts/quill/emoji/completion.tsx index 4b1a8cc0c..eb2d2f00b 100644 --- a/ts/quill/emoji/completion.tsx +++ b/ts/quill/emoji/completion.tsx @@ -119,7 +119,9 @@ export class EmojiCompletion { const range = this.quill.getSelection(); - if (!range) return PASS_THROUGH; + if (!range) { + return PASS_THROUGH; + } const [blot, index] = this.quill.getLeaf(range.index); const [leftTokenTextMatch, rightTokenTextMatch] = matchBlotTextPartitions( @@ -200,14 +202,18 @@ export class EmojiCompletion { completeEmoji(): void { const range = this.quill.getSelection(); - if (range === null) return; + if (range === null) { + return; + } const emoji = this.results[this.index]; const [leafText] = this.getCurrentLeafTextPartitions(); const tokenTextMatch = /:([-+0-9a-z_]*)(:?)$/.exec(leafText); - if (tokenTextMatch === null) return; + if (tokenTextMatch === null) { + return; + } const [, tokenText] = tokenTextMatch; diff --git a/ts/quill/mentions/completion.tsx b/ts/quill/mentions/completion.tsx index 7e6652f18..d5193945f 100644 --- a/ts/quill/mentions/completion.tsx +++ b/ts/quill/mentions/completion.tsx @@ -151,7 +151,9 @@ export class MentionCompletion { const range = this.quill.getSelection(); - if (range === null) return; + if (range === null) { + return; + } const member = this.results[resultIndex]; diff --git a/ts/test-node/quill/mentions/matchers_test.ts b/ts/test-node/quill/mentions/matchers_test.ts index 6d0f9c6fb..10e0d73da 100644 --- a/ts/test-node/quill/mentions/matchers_test.ts +++ b/ts/test-node/quill/mentions/matchers_test.ts @@ -79,7 +79,9 @@ type MentionInsert = { const isMention = (insert?: unknown): insert is MentionInsert => { if (insert) { - if (Object.getOwnPropertyNames(insert).includes('mention')) return true; + if (Object.getOwnPropertyNames(insert).includes('mention')) { + return true; + } } return false; }; diff --git a/ts/textsecure/ContactsParser.ts b/ts/textsecure/ContactsParser.ts index a83ba7a18..ddb47bf84 100644 --- a/ts/textsecure/ContactsParser.ts +++ b/ts/textsecure/ContactsParser.ts @@ -30,12 +30,15 @@ export type ModifiedGroupDetails = MessageWithAvatar; export type ModifiedContactDetails = MessageWithAvatar; +/* eslint-disable @typescript-eslint/brace-style -- Prettier conflicts with ESLint */ abstract class ParserBase< Message extends OptionalAvatar, Decoder extends DecoderBase, Result > implements Iterable { + /* eslint-enable @typescript-eslint/brace-style */ + protected readonly reader: protobuf.Reader; constructor(bytes: Uint8Array, private readonly decoder: Decoder) { diff --git a/ts/textsecure/MessageReceiver.ts b/ts/textsecure/MessageReceiver.ts index 6a146c57e..637baa968 100644 --- a/ts/textsecure/MessageReceiver.ts +++ b/ts/textsecure/MessageReceiver.ts @@ -229,10 +229,13 @@ function getEnvelopeId(envelope: ProcessedEnvelope): string { return `${prefix} ${timestamp} (${envelope.id})`; } +/* eslint-disable @typescript-eslint/brace-style -- Prettier conflicts with ESLint */ export default class MessageReceiver extends EventTarget implements IRequestHandler { + /* eslint-enable @typescript-eslint/brace-style */ + private server: WebAPIType; private storage: Storage; diff --git a/ts/textsecure/storage/User.ts b/ts/textsecure/storage/User.ts index cff2b6a1b..9888f138a 100644 --- a/ts/textsecure/storage/User.ts +++ b/ts/textsecure/storage/User.ts @@ -55,14 +55,18 @@ export class User { public getNumber(): string | undefined { const numberId = this.storage.get('number_id'); - if (numberId === undefined) return undefined; + if (numberId === undefined) { + return undefined; + } return Helpers.unencodeNumber(numberId)[0]; } public getUuid(uuidKind = UUIDKind.ACI): UUID | undefined { if (uuidKind === UUIDKind.PNI) { const pni = this.storage.get('pni'); - if (pni === undefined) return undefined; + if (pni === undefined) { + return undefined; + } return new UUID(pni); } @@ -71,7 +75,9 @@ export class User { `Unsupported uuid kind: ${uuidKind}` ); const uuid = this.storage.get('uuid_id'); - if (!uuid) return undefined; + if (!uuid) { + return undefined; + } return new UUID(Helpers.unencodeNumber(uuid.toLowerCase())[0]); } @@ -161,13 +167,17 @@ export class User { private _getDeviceIdFromUuid(): string | undefined { const uuid = this.storage.get('uuid_id'); - if (uuid === undefined) return undefined; + if (uuid === undefined) { + return undefined; + } return Helpers.unencodeNumber(uuid)[1]; } private _getDeviceIdFromNumber(): string | undefined { const numberId = this.storage.get('number_id'); - if (numberId === undefined) return undefined; + if (numberId === undefined) { + return undefined; + } return Helpers.unencodeNumber(numberId)[1]; } } diff --git a/ts/util/iterables.ts b/ts/util/iterables.ts index 92d51753d..e50b53d73 100644 --- a/ts/util/iterables.ts +++ b/ts/util/iterables.ts @@ -133,7 +133,9 @@ class CollectIterator implements Iterator { // eslint-disable-next-line no-constant-condition while (true) { const nextIteration = this.iterator.next(); - if (nextIteration.done) return nextIteration; + if (nextIteration.done) { + return nextIteration; + } const nextValue = this.fn(nextIteration.value); if (nextValue !== undefined) { return {