Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Fix some check/lint warnings #32048

Merged
merged 10 commits into from
Apr 9, 2024
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ API.v1.addRoute(
{ authRequired: true, twoFactorRequired: true },
{
async post() {
if (!this.bodyParams.name || !this.bodyParams.name.trim()) {
if (!this.bodyParams.name?.trim()) {
throw new Meteor.Error('error-name-param-not-provided', 'The parameter "name" is required');
}

Expand Down
1 change: 1 addition & 0 deletions apps/meteor/app/apps/server/bridges/listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class AppListenerBridge {
}

async handleEvent(event, ...payload) {
// eslint-disable-next-line complexity
const method = (() => {
switch (event) {
case AppInterface.IPreMessageSentPrevent:
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/authorization/lib/AuthorizationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const AuthorizationUtils = class {
}

const rules = restrictedRolePermissions.get(roleId);
if (!rules || !rules.size) {
if (!rules?.size) {
return false;
}

Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/app/cors/server/cors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Logger } from '@rocket.chat/logger';
import { Meteor } from 'meteor/meteor';
import type { StaticFiles } from 'meteor/webapp';
import { WebApp, WebAppInternals } from 'meteor/webapp';
import _ from 'underscore';

import { settings } from '../../settings/server';

Expand Down Expand Up @@ -174,7 +173,7 @@ WebApp.httpServer.addListener('request', (req, res, ...args) => {

const isLocal =
localhostRegexp.test(remoteAddress) &&
(!req.headers['x-forwarded-for'] || _.all((req.headers['x-forwarded-for'] as string).split(','), localhostTest));
(!req.headers['x-forwarded-for'] || (req.headers['x-forwarded-for'] as string).split(',').every(localhostTest));
// @ts-expect-error - `pair` is valid, but doesnt exists on types
const isSsl = req.connection.pair || (req.headers['x-forwarded-proto'] && req.headers['x-forwarded-proto'].indexOf('https') !== -1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export async function getAvatarSuggestionForUser(
let blob = `data:${response.headers.get('content-type')};base64,`;
blob += Buffer.from(await response.arrayBuffer()).toString('base64');
newAvatar.blob = blob;
newAvatar.contentType = response.headers.get('content-type')!;
newAvatar.contentType = response.headers.get('content-type') as string;
validAvatars[avatar.service] = newAvatar;
}
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions packages/gazzodown/src/elements/Timestamp/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Component } from 'react';
import React, { Component, ReactNode } from 'react';

export class ErrorBoundary extends Component<{ fallback: React.ReactNode }, { hasError: boolean }> {
constructor(props: { fallback: React.ReactNode }) {
super(props);
this.state = { hasError: false };
}

static getDerivedStateFromError() {
static getDerivedStateFromError(): { hasError: boolean } {
return { hasError: true };
}

render() {
render(): ReactNode {
if (this.state.hasError) {
// You can render any custom fallback UI
return this.props.fallback;
Expand Down
12 changes: 6 additions & 6 deletions packages/livechat/src/components/Composer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { createClassName } from '../../helpers/createClassName';
import { parse } from '../../helpers/parse';
import styles from './styles.scss';

const findLastTextNode = (node: Node): Text | null => {
const findLastTextNode = (node: Node): Node | null => {
if (node.nodeType === Node.TEXT_NODE) {
return node as Text;
return node;
}
const children = node.childNodes;
for (let i = children.length - 1; i >= 0; i--) {
Expand All @@ -26,7 +26,7 @@ const replaceCaret = (el: Element) => {
const target = findLastTextNode(el);
// do not move caret if element was not focused
const isTargetFocused = document.activeElement === el;
if (target !== null && target.nodeValue !== null && isTargetFocused) {
if (!!target?.nodeValue && isTargetFocused) {
const range = document.createRange();
const sel = window.getSelection();
range.setStart(target, target.nodeValue.length);
Expand Down Expand Up @@ -241,18 +241,18 @@ export class Composer extends Component<ComposerProps, ComposerState> {
}

if (typeof win.getSelection !== 'undefined' && (win.getSelection()?.rangeCount ?? 0) > 0) {
const range = win.getSelection()!.getRangeAt(0);
const range = win.getSelection()?.getRangeAt(0) as Range;
const preCaretRange = range.cloneRange();
preCaretRange.selectNodeContents(element);
preCaretRange.setEnd(range.endContainer, range.endOffset);
return preCaretRange.toString().length;
}

if (doc.selection && doc.selection.type !== 'Control') {
const textRange = doc.selection.createRange!();
const textRange = doc.selection.createRange?.();
const preCaretTextRange = doc.body.createTextRange?.();
preCaretTextRange?.moveToElementText?.(element);
preCaretTextRange?.setEndPoint?.('EndToEnd', textRange);
preCaretTextRange?.setEndPoint?.('EndToEnd', textRange as Range);
return preCaretTextRange?.text?.length ?? 0;
}

Expand Down
Loading