Skip to content

Commit

Permalink
Fixed linting issues
Browse files Browse the repository at this point in the history
Some of our linting rules became more strict and required refactors and opting out of specific instances
  • Loading branch information
paustint committed Dec 27, 2024
1 parent a70144c commit 60d4f50
Show file tree
Hide file tree
Showing 25 changed files with 84 additions and 67 deletions.
4 changes: 3 additions & 1 deletion apps/api/src/app/controllers/socket.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ export function initSocketServer(app: express.Express, middlewareFns: express.Re
// TODO: should we distinguish specific reason for disconnect before unsubscribing from cometd?
// If browser did not really disconnect, how will it know that it is no longer subscribed to cometd?
Object.values(userSocketState.cometdConnections).forEach(({ cometd, subscriptions }) => {
cometd && socketUtils.disconnectCometD(cometd, socket, user);
if (cometd) {
socketUtils.disconnectCometD(cometd, socket, user);
}
subscriptions.clear();
});
userSocketState.cometdConnections = {};
Expand Down
12 changes: 10 additions & 2 deletions apps/download-zip-sw/src/app/Zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,19 @@ class Zip {

// To also work with the node version of readable stream (for testing)
enqueue = (data) => {
this.outputController ? this.outputController.enqueue(data) : this.outputStream.push(data);
if (this.outputController) {
this.outputController.enqueue(data);
} else {
this.outputStream.push(data);
}
};

close = () => {
this.outputController ? this.outputController.close() : this.outputStream.destroy();
if (this.outputController) {
this.outputController.close();
} else {
this.outputStream.destroy();
}
};

// Generators
Expand Down
2 changes: 1 addition & 1 deletion apps/download-zip-sw/src/main.sw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const zipMap: Map<
files: DownZipFile[];
name: string;
zip: Zip;
sizeBig: BigInt;
sizeBig: bigint;
}
> = new Map();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ export class LoadSingleObjectPage {

async validateHeaderButtonState(startOver: boolean, goBack: boolean, nextStep: boolean) {
async function validate(enabled: boolean, locator: Locator) {
enabled ? await expect(locator).toBeEnabled() : await expect(locator).toBeDisabled();
if (enabled) {
await expect(locator).toBeEnabled();
} else {
await expect(locator).toBeDisabled();
}
}
await validate(startOver, this.page.getByTestId('start-over-button'));
await validate(goBack, this.page.getByTestId('prev-step-button'));
Expand Down
18 changes: 11 additions & 7 deletions apps/jetstream-e2e/src/pageObjectModels/QueryPage.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,11 @@ export class QueryPage {
await condition.locator(`#${operator}`).click();

await condition.getByLabel('Value').click();
(await value.type) === 'text'
? condition.getByLabel('Value').fill(value.value)
: condition.getByRole('option', { name: value.value }).click();
if (value.type === 'text') {
await condition.getByLabel('Value').fill(value.value);
} else {
await condition.getByRole('option', { name: value.value }).click();
}
}

async addCondition() {
Expand Down Expand Up @@ -180,8 +182,8 @@ export class QueryPage {

async waitForQueryResults(query: string) {
const { queryResults } = await this.apiRequestUtils.makeRequest<QueryResults>('POST', `/api/query`, { query });
await expect(queryResults.records.length).toBeGreaterThan(0);
await this.page.getByText(`Showing ${formatNumber(queryResults.records.length)} of ${formatNumber(queryResults.totalSize)} records`);
expect(queryResults.records.length).toBeGreaterThan(0);
this.page.getByText(`Showing ${formatNumber(queryResults.records.length)} of ${formatNumber(queryResults.totalSize)} records`);
return queryResults;
}

Expand All @@ -190,8 +192,10 @@ export class QueryPage {

// validate first 15 records - check that id is present
for (const record of queryResults.records.slice(0, 15)) {
await expect(isRecordWithId(record)).toBeTruthy();
isRecordWithId(record) && (await expect(this.page.getByRole('gridcell', { name: record.Id })).toBeVisible());
expect(isRecordWithId(record)).toBeTruthy();
if (isRecordWithId(record)) {
await expect(this.page.getByRole('gridcell', { name: record.Id })).toBeVisible();
}
}

// FIXME: this was causing the browser to crash - could not reproduce or identify cause
Expand Down
1 change: 1 addition & 0 deletions apps/jetstream-e2e/src/setup/global.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ setup('login and ensure org exists', async ({ page, request }) => {

await page.waitForURL(`${baseApiURL}/app`);

// eslint-disable-next-line playwright/no-standalone-expect
await expect(page.getByRole('button', { name: 'Avatar' })).toBeVisible();

await page.evaluate(async () => {
Expand Down
1 change: 0 additions & 1 deletion apps/jetstream-e2e/src/tests/api/misc.api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ test.describe('API - Misc', () => {
);

expect(file).toBeTruthy();
file;
});

test('Request - POST', async ({ apiRequestUtils }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ test.describe('Auth Page Navigation', () => {
await authenticationPage.goToSignUp();

await page.waitForURL(authenticationPage.routes.signup());
await expect(page.url()).toContain(authenticationPage.routes.signup());
expect(page.url()).toContain(authenticationPage.routes.signup());
await authenticationPage.signInFromFormLink.click();

await page.waitForURL(authenticationPage.routes.login());
await expect(page.url()).toContain(authenticationPage.routes.login());
expect(page.url()).toContain(authenticationPage.routes.login());
await authenticationPage.signUpFromFormLink.click();
await page.waitForURL(authenticationPage.routes.signup());
await expect(page.url()).toContain(authenticationPage.routes.signup());
expect(page.url()).toContain(authenticationPage.routes.signup());
await authenticationPage.forgotPasswordLink.click();
await page.waitForURL(authenticationPage.routes.passwordReset());
await expect(page.url()).toContain(authenticationPage.routes.passwordReset());
expect(page.url()).toContain(authenticationPage.routes.passwordReset());
await authenticationPage.loginPageFromPasswordReset.click();
await page.waitForURL(authenticationPage.routes.login());
await expect(page.url()).toContain(authenticationPage.routes.login());
expect(page.url()).toContain(authenticationPage.routes.login());

await authenticationPage.goToLogin();
await page.waitForURL(authenticationPage.routes.login());
await expect(page.url()).toContain(authenticationPage.routes.login());
expect(page.url()).toContain(authenticationPage.routes.login());
});

test('Should not be able to go to password reset form without proper URL parameters', async ({ page, authenticationPage }) => {
Expand All @@ -47,7 +47,7 @@ test.describe('Auth Page Navigation', () => {
test('Should not be able to go to mfa page without verification session', async ({ page, authenticationPage }) => {
await authenticationPage.goToMfaVerify();
await page.waitForURL(authenticationPage.routes.login(true));
await expect(page.url()).toContain(authenticationPage.routes.login());
expect(page.url()).toContain(authenticationPage.routes.login());
});
});

Expand Down Expand Up @@ -145,22 +145,22 @@ test.describe('Auth Form Validation', () => {
await expect(page.getByText('Passwords do not match')).toBeVisible();
});

test('Test showing and hiding password', async ({ page, authenticationPage }) => {
test('showing and hiding password', async ({ page, authenticationPage }) => {
const PASSWORD = 'pwd';
await authenticationPage.fillOutLoginForm('[email protected]', PASSWORD);

let typeAttribute = await authenticationPage.passwordInput.getAttribute('type');
await expect(typeAttribute).toEqual('password');
let typeAttribute = authenticationPage.passwordInput;
await expect(typeAttribute).toHaveAttribute('type', 'password');
await expect(authenticationPage.passwordInput).toHaveValue(PASSWORD);

await authenticationPage.showHidePasswordButton.click();
typeAttribute = await authenticationPage.passwordInput.getAttribute('type');
await expect(typeAttribute).toEqual('text');
typeAttribute = authenticationPage.passwordInput;
await expect(typeAttribute).toHaveAttribute('type', 'text');
await expect(authenticationPage.passwordInput).toHaveValue(PASSWORD);

await authenticationPage.showHidePasswordButton.click();
typeAttribute = await authenticationPage.passwordInput.getAttribute('type');
await expect(typeAttribute).toEqual('password');
typeAttribute = authenticationPage.passwordInput;
await expect(typeAttribute).toHaveAttribute('type', 'password');
await expect(authenticationPage.passwordInput).toHaveValue(PASSWORD);
});
});
Expand Down
13 changes: 7 additions & 6 deletions apps/jetstream-e2e/src/tests/query/query-results.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ test.beforeEach(async ({ page }) => {

test.describe.configure({ mode: 'parallel' });

test.describe('QUERY RESULTS', async () => {
test.describe('QUERY RESULTS', () => {
// eslint-disable-next-line playwright/expect-expect
test('should work', async ({ queryPage }) => {
const query = `SELECT Id, BillingAddress, CreatedBy.Id, CreatedBy.Name, CreatedBy.IsActive, Type FROM Account`;
await queryPage.gotoResults(query);
Expand All @@ -25,23 +26,23 @@ test.describe('QUERY RESULTS', async () => {
await queryPage.waitForQueryResults(query1);

await queryPage.performQueryHistoryAction(query1, 'EXECUTE');
await expect(page.url()).toContain('/query/results');
expect(page.url()).toContain('/query/results');
await queryPage.waitForQueryResults(query1);

const query2 = `SELECT Id, Name FROM Contact`;
await queryPage.gotoResults(query2);
await queryPage.waitForQueryResults(query2);

await queryPage.performQueryHistoryAction(query2, 'EXECUTE');
await expect(page.url()).toContain('/query/results');
expect(page.url()).toContain('/query/results');
await queryPage.waitForQueryResults(query2);

const query3 = `SELECT Id, Name, IsActive FROM Product2`;
await queryPage.gotoResults(query3);
await queryPage.waitForQueryResults(query3);

await queryPage.performQueryHistoryAction(query3, 'EXECUTE');
await expect(page.url()).toContain('/query/results');
expect(page.url()).toContain('/query/results');
await queryPage.waitForQueryResults(query3);
});

Expand All @@ -54,7 +55,7 @@ test.describe('QUERY RESULTS', async () => {
// FIXME: this query intermittently does not show up in query history
const query2 = `SELECT Id, Name, (SELECT Id, Name, AccountId, Email FROM Contacts) FROM Account`;
await queryPage.gotoResults(query2);
await expect(page.url()).toContain('/query/results');
expect(page.url()).toContain('/query/results');
await queryPage.waitForQueryResults(query2);

// const query3 = `SELECT Id, Name, IsActive FROM Product2`;
Expand All @@ -63,7 +64,7 @@ test.describe('QUERY RESULTS', async () => {
// await queryPage.waitForQueryResults(query3);

await queryPage.performQueryHistoryAction(query2, 'RESTORE');
await page.getByTestId('query-builder-page').getByText('Query Records');
page.getByTestId('query-builder-page').getByText('Query Records');

await queryPage.validateQueryByLine([
'SELECT Id, Name',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import {
import { FunctionComponent, useEffect, useState } from 'react';
import { Resetter, useRecoilValue, useResetRecoilState } from 'recoil';

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface AppStateResetOnOrgChangeProps {}

export const AppStateResetOnOrgChange: FunctionComponent<AppStateResetOnOrgChangeProps> = () => {
export const AppStateResetOnOrgChange = () => {
const selectedOrg = useRecoilValue<SalesforceOrgUi>(fromAppState.selectedOrgState);
const [priorSelectedOrg, setPriorSelectedOrg] = useState<string | null>(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useTitle } from '@jetstream/shared/ui-utils';
import { Card, FeedbackLink, Grid, Icon } from '@jetstream/ui';
import { FunctionComponent, useRef } from 'react';

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface FeedbackFormProps {}

export const FeedbackForm: FunctionComponent<FeedbackFormProps> = () => {
Expand Down
6 changes: 5 additions & 1 deletion libs/shared/ui-utils/src/lib/download-zip/downzip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ class DownZip {

sendMessage(command: string, data?: any, port?: Transferable) {
if (this.worker) {
port ? this.worker.postMessage({ command, data }, [port]) : this.worker.postMessage({ command, data });
if (port) {
this.worker.postMessage({ command, data }, [port]);
} else {
this.worker.postMessage({ command, data });
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions libs/shared/ui-utils/src/lib/hooks/useAsync.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState, useCallback, useRef } from 'react';
import { useCallback, useEffect, useRef, useState } from 'react';

// CREDIT: https://dev.to/dglsparsons/3-amazing-react-hooks-to-keep-your-code-organized-neatly-ghe

Expand All @@ -16,7 +16,7 @@ import { useEffect, useState, useCallback, useRef } from 'react';
* @param asyncFunction
* @param immediate
*/
// eslint-disable-next-line @typescript-eslint/ban-types
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
export const useAsync = (asyncFunction: Function, immediate = true) => {
const [loading, setLoading] = useState(false);
const [result, setResult] = useState(null);
Expand Down
6 changes: 3 additions & 3 deletions libs/shared/ui-utils/src/lib/hooks/useLoadGoogleApi.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { logger } from '@jetstream/shared/client-logger';
import { Maybe } from '@jetstream/types';
import { useNonInitialEffect } from 'libs/shared/ui-utils/src/lib/hooks/useNonInitialEffect';
import { useRollbar } from 'libs/shared/ui-utils/src/lib/hooks/useRollbar';
import { useCallback, useEffect, useRef, useState } from 'react';
import { getUseInjectScript } from './useInjectScript';
import { useNonInitialEffect } from './useNonInitialEffect';
import { useRollbar } from './useRollbar';

const useInjectScript = getUseInjectScript('https://accounts.google.com/gsi/client');

Expand Down Expand Up @@ -38,7 +38,7 @@ export interface GoogleApiData {
apiConfig: ApiConfig;
authorized: boolean;
authResponse: Maybe<gapi.auth2.AuthResponse>;
error?: string;
error?: Maybe<string>;
gapiAuthInstance: gapi.auth2.GoogleAuth;
hasApisLoaded: boolean;
hasInitialized: boolean;
Expand Down
10 changes: 5 additions & 5 deletions libs/shared/utils/src/lib/regex.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
export const REGEX = {
LEADING_TRAILING_QUOTES: /(^")|("$)/g,
NUMERIC: /^[0-9\.]+$/, // FIXME: should not allow multiple decimal places
NUMERIC: /^[0-9.]+$/, // FIXME: should not allow multiple decimal places
NOT_NUMERIC: /[^0-9]/g,
NOT_ALPHA: /[^A-Za-z]/g,
NOT_ALPHANUMERIC: /[^A-Za-z0-9]/g,
NOT_ALPHANUMERIC_OR_UNDERSCORE: /[^A-Za-z0-9_]/g,
VALID_EMAIL:
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
SALESFORCE_ID: /[a-zA-Z0-9]{18}/,
NOT_UNSIGNED_NUMERIC: /[^0-9]/g,
// SAFE_FILENAME: /[^a-zA-Z0-9-\.]/g,
SAFE_FILENAME: /[\/\?<>\\:\*\|"]/g,
SAFE_FILENAME: /[/?<>\\:*|"]/g,
ISO_DATE:
/[0-9]{4}-[0-9]{2}-[0-9]{2}($|T[0-9]{2}| [0-9]{2}(\+[0-9]{2}:[0-9]{2}|z|-[0-9]{4}|:[0-9]{2}:[0-9]{2}\.[0-9]{3}\+[0-9]{2}($|:[0-9]{2})|$|:[0-9]{2}($|:[0-9]{2}($|.[0-9]{3}))))/,
BOOLEAN_STR_TRUE: /^t|^1/i,
SAFE_EXCEL_SHEET_CHARS: /[a-zA-Z0-9\ \_\.]/g,
SAFE_EXCEL_SHEET_CHARS: /[a-zA-Z0-9 _.]/g,
HAS_NAMESPACE: /__[a-z0-9]+__/i,
START_END_SINGLE_QUOTE: /^'|'$/g,
START_END_PERCENTAGE: /^%|%$/g,
ESCAPED_SINGLE_QUOTE: /\\'/g,
ESCAPED_PERCENT_QUOTE: /\%/g,
ESCAPED_PERCENT_QUOTE: /%/g,
ESCAPED_BACKSLASH_QUOTE: /\\\\/g,
START_OR_END_QUOTE: /^"|"$/g,
QUOTE: /"/g,
Expand Down
4 changes: 2 additions & 2 deletions libs/ui/.storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import '@salesforce-ux/design-system/assets/styles/salesforce-lightning-design-s
// this is to avoid circular dependency
import './main.scss';

let modalRoot = document.createElement('div');
const modalRoot = document.createElement('div');
modalRoot.setAttribute('id', 'modal-root');
document.querySelector('body').appendChild(modalRoot);
document.querySelector('body')?.appendChild(modalRoot);
2 changes: 1 addition & 1 deletion libs/ui/src/lib/accordion/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const Accordion: FunctionComponent<AccordionProps> = ({
let content = item.content;
if (isFunction(item.content)) {
if (isOpen) {
// eslint-disable-next-line @typescript-eslint/ban-types
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
content = (content as Function)();
} else {
content = '';
Expand Down
7 changes: 3 additions & 4 deletions libs/ui/src/lib/badge/badge-notification.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Icon } from '@jetstream/ui';
import { Meta, Story } from '@storybook/react';
import React from 'react';
import { Meta, StoryFn } from '@storybook/react';
import Icon from '../widgets/Icon';
import BadgeNotificationComponent, { BadgeNotificationProps } from './BadgeNotification';

export default {
Expand All @@ -12,7 +11,7 @@ export default {
},
} as Meta;

const Template: Story<BadgeNotificationProps> = ({ children, ...args }) => (
const Template: StoryFn<BadgeNotificationProps> = ({ children, ...args }) => (
<button className="slds-button slds-button_icon">
<BadgeNotificationComponent {...args}>{children}</BadgeNotificationComponent>
<Icon type="utility" icon="notification" className="slds-button__icon slds-button__icon_large" omitContainer />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import { MIME_TYPES } from '@jetstream/shared/constants';
import { getFilename, isEnterKey } from '@jetstream/shared/ui-utils';
import {
Expand Down
3 changes: 1 addition & 2 deletions libs/ui/src/lib/form/combobox/ComboboxListItemLoadMore.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { FunctionComponent } from 'react';
import { FunctionComponent } from 'react';
import Spinner from '../../widgets/Spinner';

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ComboboxListItemLoadMoreProps {}

export const ComboboxListItemLoadMore: FunctionComponent<ComboboxListItemLoadMoreProps> = () => {
Expand Down
2 changes: 1 addition & 1 deletion libs/ui/src/lib/layout/ViewDocsLink.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Icon, Tooltip } from '@jetstream/ui';
import classNames from 'classnames';
import { FunctionComponent } from 'react';
import Icon from '../widgets/Icon';

const DOCS_BASE_PATH = 'https://docs.getjetstream.app';

Expand Down
Loading

0 comments on commit 60d4f50

Please sign in to comment.