Skip to content

Commit

Permalink
Enable brace-style eslint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiebuilds-signal committed Sep 13, 2022
1 parent 73bdcdf commit 5a8f484
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 13 deletions.
13 changes: 12 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down Expand Up @@ -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',
Expand Down
4 changes: 3 additions & 1 deletion ts/components/stickers/StickerButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]
);
Expand Down
12 changes: 9 additions & 3 deletions ts/quill/emoji/completion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion ts/quill/mentions/completion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
4 changes: 3 additions & 1 deletion ts/test-node/quill/mentions/matchers_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
3 changes: 3 additions & 0 deletions ts/textsecure/ContactsParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ export type ModifiedGroupDetails = MessageWithAvatar<Proto.GroupDetails>;

export type ModifiedContactDetails = MessageWithAvatar<Proto.ContactDetails>;

/* eslint-disable @typescript-eslint/brace-style -- Prettier conflicts with ESLint */
abstract class ParserBase<
Message extends OptionalAvatar,
Decoder extends DecoderBase<Message>,
Result
> implements Iterable<Result>
{
/* eslint-enable @typescript-eslint/brace-style */

protected readonly reader: protobuf.Reader;

constructor(bytes: Uint8Array, private readonly decoder: Decoder) {
Expand Down
3 changes: 3 additions & 0 deletions ts/textsecure/MessageReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 15 additions & 5 deletions ts/textsecure/storage/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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]);
}

Expand Down Expand Up @@ -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];
}
}
4 changes: 3 additions & 1 deletion ts/util/iterables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ class CollectIterator<T, S> implements Iterator<S> {
// 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 {
Expand Down

0 comments on commit 5a8f484

Please sign in to comment.