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

Enable no-unsafe-member-access eslint rule #43557

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b825ac9
enable no-member-access rule
bgawkuc Jun 6, 2024
2286f81
add draft solution for require errors
bgawkuc Jun 6, 2024
b60e0ba
override node require interface
bgawkuc Jun 6, 2024
372319f
fix no member access error in navigation files
bgawkuc Jun 6, 2024
f4730ca
fix no member access error in require usages
bgawkuc Jun 6, 2024
4f82ac1
use generic type with require
bgawkuc Jun 6, 2024
7a68f02
fix crashing desktop
bgawkuc Jun 6, 2024
37a8032
fix no member access error for error type
bgawkuc Jun 7, 2024
933a865
fix more no member access errors
bgawkuc Jun 7, 2024
3a80440
fix no unsafe member access errors in tests
bgawkuc Jun 10, 2024
73df95f
fix no unsafe member access errors in tests 2
bgawkuc Jun 11, 2024
74c8147
simplify types
bgawkuc Jun 12, 2024
d5fd866
Merge branch 'main' into ts/enable-no-unsafe-member-access
bgawkuc Jun 12, 2024
a4e6bc6
review adjustments
bgawkuc Jun 12, 2024
d4fbe38
fix kie/act-js types
bgawkuc Jun 13, 2024
64ca929
Merge branch 'main' into ts/enable-no-unsafe-member-access
bgawkuc Jun 13, 2024
04fcd4b
fix kie/act-js types
bgawkuc Jun 13, 2024
852ef29
wip
bgawkuc Jun 14, 2024
d7b053c
improve custom step identifier type
bgawkuc Jun 14, 2024
0dfd63c
remove redundant module
bgawkuc Jun 14, 2024
ba0b925
Merge branch 'main' into ts/enable-no-unsafe-member-access
bgawkuc Jun 17, 2024
c708fe4
Fix @kie/act-js types
blazejkustra Jun 17, 2024
9859158
move EventJSON export to custom module
bgawkuc Jun 17, 2024
2156f68
review adjustments
bgawkuc Jun 18, 2024
feec659
Merge branch 'main' into ts/enable-no-unsafe-member-access
bgawkuc Jun 18, 2024
c47a908
review adjustments
bgawkuc Jun 18, 2024
ece8190
Merge branch 'main' into ts/enable-no-unsafe-member-access
bgawkuc Jun 18, 2024
c5b93db
add error type
bgawkuc Jun 18, 2024
f139618
update RN type
bgawkuc Jun 18, 2024
fefc1a2
Merge branch 'main' into ts/enable-no-unsafe-member-access
blazejkustra Jun 19, 2024
9783a00
Merge branch 'main' into ts/enable-no-unsafe-member-access
blazejkustra Jun 20, 2024
1212d13
Merge branch 'main' into ts/enable-no-unsafe-member-access
blazejkustra Jun 24, 2024
e5907c2
Fix new lint errors
blazejkustra Jun 24, 2024
81a96d8
Merge branch 'main' into ts/enable-no-unsafe-member-access
blazejkustra Jun 24, 2024
683e4c0
Fix lint error
blazejkustra Jun 24, 2024
05f12a4
Merge branch 'main' into ts/enable-no-unsafe-member-access
blazejkustra Jun 25, 2024
15a5db2
Add generic argument to require
blazejkustra Jun 25, 2024
0bb01b7
Remove unnecessary assertion
blazejkustra Jun 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
simplify types
  • Loading branch information
bgawkuc committed Jun 12, 2024
commit 74c81475fd0888b0e2052df6036157c289a35577
11 changes: 3 additions & 8 deletions src/components/Hoverable/ActiveHoverable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@ import type HoverableProps from './types';

type ActiveHoverableProps = Omit<HoverableProps, 'disabled'>;

type OnMouseEvent = (e: MouseEvent) => void;
type MouseEvents = 'onMouseEnter' | 'onMouseLeave' | 'onMouseMove' | 'onBlur';

type MouseEvents = {
onMouseEnter: OnMouseEvent;
onMouseLeave: OnMouseEvent;
onMouseMove: OnMouseEvent;
onBlur: OnMouseEvent;
};
type OnMouseEvents = Record<MouseEvents, (e: MouseEvent) => void>;

function ActiveHoverable({onHoverIn, onHoverOut, shouldHandleScroll, shouldFreezeCapture, children}: ActiveHoverableProps, outerRef: Ref<HTMLElement>) {
const [isHovered, setIsHovered] = useState(false);
Expand Down Expand Up @@ -107,7 +102,7 @@ function ActiveHoverable({onHoverIn, onHoverOut, shouldHandleScroll, shouldFreez

const child = useMemo(() => getReturnValue(children, !isScrollingRef.current && isHovered), [children, isHovered]);

const {onMouseEnter, onMouseLeave, onMouseMove, onBlur}: MouseEvents = child.props;
const {onMouseEnter, onMouseLeave, onMouseMove, onBlur}: OnMouseEvents = child.props;

const hoverAndForwardOnMouseEnter = useCallback(
(e: MouseEvent) => {
Expand Down
5 changes: 3 additions & 2 deletions src/components/SignInButtons/GoogleSignIn/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ function googleSignInRequest() {
- The common status codes documentation: https://developers.google.com/android/reference/com/google/android/gms/common/api/CommonStatusCodes
- The Google Sign In codes documentation: https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInStatusCodes
*/
if ((error as GoogleError).code === statusCodes.SIGN_IN_CANCELLED) {
const googleError = error as GoogleError;
bgawkuc marked this conversation as resolved.
Show resolved Hide resolved
if (googleError.code === statusCodes.SIGN_IN_CANCELLED) {
bgawkuc marked this conversation as resolved.
Show resolved Hide resolved
Log.info('[Google Sign In] Google Sign In cancelled');
} else {
Log.alert(`[Google Sign In] Error Code: ${(error as GoogleError).code}. ${(error as GoogleError).message}`, {}, false);
Log.alert(`[Google Sign In] Error Code: ${googleError.code}. ${googleError.message}`, {}, false);
bgawkuc marked this conversation as resolved.
Show resolved Hide resolved
}
});
}
Expand Down
7 changes: 1 addition & 6 deletions src/libs/E2E/reactNativeLaunchingTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@
* By doing this, we avoid bundling any E2E testing code
* into the actual release app.
*/
import type {ValueOf} from 'type-fest';
import * as Metrics from '@libs/Metrics';
import Performance from '@libs/Performance';
import Config from 'react-native-config';
import E2EConfig from '../../../tests/e2e/config';
import E2EClient from './client';
import installNetworkInterceptor from './utils/NetworkInterceptor';
import LaunchArgs from './utils/LaunchArgs';
import type { TestConfig } from './types';

type Test = (config: TestConfig) => void;
type TestModule = { default: Test}
type Tests = Record<ValueOf<typeof E2EConfig.TEST_NAMES>, Test>;
import type { TestModule, Tests } from './types';
bgawkuc marked this conversation as resolved.
Show resolved Hide resolved

console.debug('==========================');
console.debug('==== Running e2e test ====');
Expand Down
9 changes: 8 additions & 1 deletion src/libs/E2E/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {TEST_NAMES} from 'tests/e2e/config';
import type {ValueOf} from 'type-fest';
import type E2EConfig from '../../../tests/e2e/config';

type SigninParams = {
email?: string;
Expand All @@ -26,6 +27,12 @@ type TestConfig = {
[key: string]: string | {autoFocus: boolean};
};

type Test = (config: TestConfig) => void;

type TestModule = {default: Test};

type Tests = Record<ValueOf<typeof E2EConfig.TEST_NAMES>, Test>;

type TestResult = {
/** Name of the test */
name: string;
Expand All @@ -49,4 +56,4 @@ type TestResult = {
renderCount?: number;
};

export type {SigninParams, IsE2ETestSession, NetworkCacheMap, NetworkCacheEntry, TestConfig, TestResult};
export type {SigninParams, IsE2ETestSession, NetworkCacheMap, NetworkCacheEntry, TestConfig, TestResult, TestModule, Tests};
2 changes: 1 addition & 1 deletion src/libs/Environment/betaChecker/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function isBetaBuild(): IsBetaBuild {
fetch(CONST.GITHUB_RELEASE_URL)
.then((res) => res.json())
.then((json: GithubReleaseJSON) => {
const productionVersion: string | semver.SemVer = json.tag_name;
const productionVersion = json.tag_name;
if (!productionVersion) {
AppUpdate.setIsAppInBeta(false);
resolve(false);
Expand Down
12 changes: 3 additions & 9 deletions src/libs/Navigation/linkTo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,7 @@ import type {Route} from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import getActionForBottomTabNavigator from './getActionForBottomTabNavigator';
import getMinimalAction from './getMinimalAction';

type ActionParams = {
screen: string;
params?: {
policyIDs?: string;
};
};
import type {ActionPayloadParams} from './types';

export default function linkTo(navigation: NavigationContainerRef<RootStackParamList> | null, path: Route, type?: string, isActiveRoute?: boolean) {
if (!navigation) {
Expand Down Expand Up @@ -75,7 +69,7 @@ export default function linkTo(navigation: NavigationContainerRef<RootStackParam

// If action type is different than NAVIGATE we can't change it to the PUSH safely
if (action?.type === CONST.NAVIGATION.ACTION_TYPE.NAVIGATE) {
const actionParams: ActionParams | undefined = action.payload.params;
const actionParams: ActionPayloadParams = action.payload.params;
const topRouteName = rootState?.routes?.at(-1)?.name;

const isTargetNavigatorOnTop = topRouteName === action.payload.name;
Expand Down Expand Up @@ -112,7 +106,7 @@ export default function linkTo(navigation: NavigationContainerRef<RootStackParam

// If we navigate to SCREENS.SEARCH.CENTRAL_PANE, it's necessary to pass the current policyID, but we have to remember that this param is called policyIDs on this page
if (actionParams?.screen === SCREENS.SEARCH.CENTRAL_PANE && actionParams?.params && policyID) {
actionParams.params.policyIDs = policyID;
(actionParams.params as Record<string, string | undefined>).policyIDs = policyID;
}

// If this action is navigating to ModalNavigator or FullScreenNavigator and the last route on the root navigator is not already opened Navigator then push
Expand Down
2 changes: 1 addition & 1 deletion src/libs/NetworkConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function subscribeToBackendAndInternetReachability(): () => void {
}
return response
.json()
.then((json) => Promise.resolve((json as ResponseJSON).jsonCode === 200))
.then((json: ResponseJSON) => Promise.resolve(json.jsonCode === 200))
.catch(() => Promise.resolve(false));
})
.then((isBackendReachable: boolean) => {
Expand Down
6 changes: 3 additions & 3 deletions src/libs/fileDownload/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {PhotoIdentifier} from '@react-native-camera-roll/camera-roll';
import RNFetchBlob from 'react-native-blob-util';
import CONST from '@src/CONST';
import * as FileUtils from './FileUtils';
import type {FileDownload} from './types';
import type {FileDownload, FileDownloadError} from './types';

/**
* Downloads the file to Documents section in iOS
Expand Down Expand Up @@ -94,10 +94,10 @@ const fileDownload: FileDownload = (fileUrl, fileName, successMessage) =>

FileUtils.showSuccessAlert(successMessage);
})
.catch((err) => {
.catch((err: FileDownloadError) => {
// iOS shows permission popup only once. Subsequent request will only throw an error.
// We catch the error and show a redirection link to the settings screen
if ((err as {message?: string}).message === CONST.IOS_CAMERAROLL_ACCESS_ERROR) {
if (err.message === CONST.IOS_CAMERAROLL_ACCESS_ERROR) {
FileUtils.showPermissionErrorAlert();
} else {
FileUtils.showGeneralErrorAlert();
Expand Down
5 changes: 4 additions & 1 deletion src/libs/fileDownload/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type {Asset} from 'react-native-image-picker';

type FileDownload = (url: string, fileName?: string, successMessage?: string, shouldOpenExternalLink?: boolean) => Promise<void>;
type FileDownloadError = Error & {
message?: string;
bgawkuc marked this conversation as resolved.
Show resolved Hide resolved
};

type ImageResolution = {width: number; height: number};
type GetImageResolution = (url: File | Asset) => Promise<ImageResolution>;
Expand All @@ -17,4 +20,4 @@ type AttachmentDetails = {
};
type GetAttachmentDetails = (html: string) => AttachmentDetails;

export type {SplitExtensionFromFileName, GetAttachmentDetails, ReadFileAsync, FileDownload, GetImageResolution};
export type {SplitExtensionFromFileName, GetAttachmentDetails, ReadFileAsync, FileDownload, FileDownloadError, GetImageResolution};
5 changes: 2 additions & 3 deletions tests/e2e/testRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ import withFailTimeout from './utils/withFailTimeout';
type Result = Record<string, number[]>;

type CustomConfig = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
default: any;
default: unknown;
};

// VARIABLE CONFIGURATION
Expand All @@ -51,7 +50,7 @@ const setConfigPath = (configPathParam: string | undefined) => {
if (!configPath?.startsWith('.')) {
configPath = `./${configPath}`;
}
const customConfig = (require(configPath) as CustomConfig).default;
const customConfig = require<CustomConfig>(configPath).default;
config = Object.assign(defaultConfig, customConfig);
};

Expand Down
7 changes: 3 additions & 4 deletions tests/perf-test/ReportActionsList.perf-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,20 @@ import * as ReportTestUtils from '../utils/ReportTestUtils';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates';

type LHNTestUtilsProps = {
type LazyLoadLHNTestUtils = {
fakePersonalDetails: PersonalDetailsList;
};

const mockedNavigate = jest.fn();

jest.mock('@components/withCurrentUserPersonalDetails', () => {
// Lazy loading of LHNTestUtils
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
const lazyLoadLHNTestUtils = () => require('../utils/LHNTestUtils');
const lazyLoadLHNTestUtils = () => require<LazyLoadLHNTestUtils>('../utils/LHNTestUtils');

return <TProps extends WithCurrentUserPersonalDetailsProps>(Component: ComponentType<TProps>) => {
function WrappedComponent(props: Omit<TProps, keyof WithCurrentUserPersonalDetailsProps>) {
const currentUserAccountID = 5;
const LHNTestUtils: LHNTestUtilsProps = lazyLoadLHNTestUtils(); // Load LHNTestUtils here
const LHNTestUtils = lazyLoadLHNTestUtils(); // Load LHNTestUtils here

return (
<Component
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/NetworkTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import type ReactNativeOnyxMock from '../../__mocks__/react-native-onyx';
import * as TestHelper from '../utils/TestHelper';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';

type OnResolved = (params: {jsonCode?: string | number}) => void;

const Onyx = MockedOnyx as typeof ReactNativeOnyxMock;

jest.mock('@src/libs/Log');
Expand Down Expand Up @@ -289,7 +291,7 @@ describe('NetworkTests', () => {
test('test Failed to fetch error for non-retryable requests resolve with unable to retry jsonCode', () => {
// Setup xhr handler that rejects once with a Failed to Fetch
global.fetch = jest.fn().mockRejectedValue(new Error(CONST.ERROR.FAILED_TO_FETCH));
const onResolved = jest.fn() as jest.MockedFunction<(params: {jsonCode?: string | number}) => void>;
const onResolved = jest.fn() as jest.MockedFunction<OnResolved>;

// Given we have a request made while online
return Onyx.set(ONYXKEYS.NETWORK, {isOffline: false, isBackendReachable: true})
Expand Down