Skip to content

Commit

Permalink
chore: enable eslint and remove tslint for react-native packages (#13079
Browse files Browse the repository at this point in the history
)

* chore: enable eslint and remove tslint for packages:

1. packages/react-native
2. packages/rtn-push-notification
3. packages/rtn-web-browser

* chore(react-native): run yarn lint:fix

* chore(react-native): manual fix of linter reported errors

* chore(rtn-push-notification): run yarn lint:fix

* chore(rtn-web-browser): run yarn lint:fix
  • Loading branch information
HuiSF authored Mar 19, 2024
1 parent 22d042d commit 0e0c496
Show file tree
Hide file tree
Showing 19 changed files with 53 additions and 183 deletions.
6 changes: 3 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ module.exports = {
'packages/notifications',
// 'packages/predictions',
// 'packages/pubsub',
'packages/react-native',
'packages/rtn-push-notification',
'packages/rtn-web-browser',
// 'packages/react-native',
// 'packages/rtn-push-notification',
// 'packages/rtn-web-browser',
// 'packages/storage',
],
rules: {
Expand Down
11 changes: 5 additions & 6 deletions packages/react-native/example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import * as React from 'react';

import { StyleSheet, View, Text, Platform } from 'react-native';
import { Platform, StyleSheet, Text, View } from 'react-native';
import { computeModPow, computeS } from '@aws-amplify/react-native';

const computeModPowPayload = {
Expand Down Expand Up @@ -31,10 +30,10 @@ export default function App() {

React.useEffect(() => {
async function calc() {
const computeModPowResult = await computeModPow(computeModPowPayload);
setComputeModPowResult(computeModPowResult);
const computeSResult = await computeS(computeSPayload);
setComputeSResult(computeSResult);
const modPowResult = await computeModPow(computeModPowPayload);
setComputeModPowResult(modPowResult);
const sResult = await computeS(computeSPayload);
setComputeSResult(sResult);
}
calc();
}, []);
Expand Down
3 changes: 2 additions & 1 deletion packages/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"build": "npm run clean && npm run build:esm-cjs",
"clean": "rimraf lib-esm lib dist",
"format": "echo \"Not implemented\"",
"lint": "tslint 'src/**/*.ts' && npm run ts-coverage",
"lint": "eslint '**/*.{ts,tsx}' && npm run ts-coverage",
"lint:fix": "eslint '**/*.{ts,tsx}' --fix",
"ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 88.21"
},
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/react-native/src/nativeModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { NativeModules, Platform } from 'react-native';

import { RTNCore } from './types';

const LINKING_ERROR =
Expand Down
50 changes: 0 additions & 50 deletions packages/react-native/tslint.json

This file was deleted.

3 changes: 2 additions & 1 deletion packages/rtn-push-notification/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"build": "npm run clean && npm run build:esm-cjs",
"clean": "rimraf lib-esm lib dist",
"format": "echo \"Not implemented\"",
"lint": "tslint 'src/**/*.ts' && npm run ts-coverage",
"lint": "eslint '**/*.{ts,tsx}' && npm run ts-coverage",
"lint:fix": "eslint '**/*.{ts,tsx}' --fix",
"ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 99"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { EmitterSubscription } from 'react-native';

import { nativeEventEmitter } from '../nativeModule';
import { NativeMessage, PushNotificationMessage } from '../types';
import { normalizeNativeMessage } from '../utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { EmitterSubscription } from 'react-native';

import { nativeEventEmitter } from '../nativeModule';
import { TokenPayload } from '../types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
// SPDX-License-Identifier: Apache-2.0

import { AppRegistry } from 'react-native';
import { getConstants } from './getConstants';

import { NativeMessage, PushNotificationMessage } from '../types';
import { normalizeNativeMessage } from '../utils';

import { getConstants } from './getConstants';

export const registerHeadlessTask = (
task: (message: PushNotificationMessage | null) => Promise<void>,
): void => {
Expand Down
1 change: 1 addition & 0 deletions packages/rtn-push-notification/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
requestPermissions,
setBadgeCount,
} from './apis';

export {
PushNotificationMessage,
PushNotificationPermissionStatus,
Expand Down
3 changes: 2 additions & 1 deletion packages/rtn-push-notification/src/nativeModule.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { NativeModules, NativeEventEmitter } from 'react-native';
import { NativeEventEmitter, NativeModules } from 'react-native';

import { LINKING_ERROR } from './constants';
import { PushNotificationNativeModule } from './types';

Expand Down
33 changes: 17 additions & 16 deletions packages/rtn-push-notification/src/types/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// SPDX-License-Identifier: Apache-2.0

import { NativeModule } from 'react-native';

import { PushNotificationMessage, PushNotificationPermissions } from './module';

export interface PushNotificationNativeModule extends NativeModule {
completeNotification?: (completionHandlerId: string) => void;
getConstants: () => {
completeNotification?(completionHandlerId: string): void;
getConstants(): {
NativeEvent: {
BACKGROUND_MESSAGE_RECEIVED?: string;
FOREGROUND_MESSAGE_RECEIVED: string;
Expand All @@ -16,19 +17,19 @@ export interface PushNotificationNativeModule extends NativeModule {
};
NativeHeadlessTaskKey?: string;
};
getLaunchNotification: () => Promise<NativeMessage | null>;
getBadgeCount?: () => Promise<number>;
setBadgeCount?: (count: number) => void;
getPermissionStatus: () => Promise<NativePermissionStatus>;
requestPermissions: (
getLaunchNotification(): Promise<NativeMessage | null>;
getBadgeCount?(): Promise<number>;
setBadgeCount?(count: number): void;
getPermissionStatus(): Promise<NativePermissionStatus>;
requestPermissions(
permissions: PushNotificationPermissions,
) => Promise<boolean>;
): Promise<boolean>;
}

export type NativeAction = {
export interface NativeAction {
deeplink?: string;
url?: string;
};
}

export type NativeMessage = (ApnsMessage | FcmMessage) & {
token?: never;
Expand All @@ -48,7 +49,7 @@ export interface NormalizedValues {
}

// iOS
export type ApnsMessage = {
export interface ApnsMessage {
aps: {
alert?: {
body?: string;
Expand All @@ -62,12 +63,12 @@ export type ApnsMessage = {
};
rawData?: never;
completionHandlerId?: string;
};
}

export type IosPermissionStatus = 'NotDetermined' | 'Authorized' | 'Denied';

// Android
export type FcmMessage = {
export interface FcmMessage {
action?: NativeAction;
aps?: never;
body?: string;
Expand All @@ -79,14 +80,14 @@ export type FcmMessage = {
senderId?: string;
sendTime?: number;
completionHandlerId?: never;
};
}

export type AndroidPermissionStatus =
| 'ShouldRequest'
| 'ShouldExplainThenRequest'
| 'Granted'
| 'Denied';

export type TokenPayload = {
export interface TokenPayload {
token: string;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import isEmpty from 'lodash/isEmpty.js';

import {
ApnsMessage,
FcmMessage,
Expand All @@ -26,6 +27,7 @@ export const normalizeNativeMessage = (
return null;
}
const { body, imageUrl, title, action, options, data } = normalized;

return {
body,
data,
Expand All @@ -42,13 +44,15 @@ const normalizeApnsMessage = (apnsMessage: ApnsMessage): NormalizedValues => {
const action = getApnsAction(data?.pinpoint) ?? {};
const imageUrl = data?.['media-url'];
const options = getApnsOptions(apnsMessage);

return { body, imageUrl, title, action, options, data };
};

const normalizeFcmMessage = (fcmMessage: FcmMessage): NormalizedValues => {
const { body, imageUrl, rawData: data, title } = fcmMessage;
const action = getFcmAction(fcmMessage.action) ?? {};
const options = getFcmOptions(fcmMessage);

return { body, imageUrl, title, action, options, data };
};

Expand Down Expand Up @@ -76,6 +80,7 @@ const getApnsOptions = ({
}: ApnsMessage): Pick<PushNotificationMessage, 'apnsOptions'> => {
const { subtitle } = aps.alert ?? {};
const apnsOptions = { ...(subtitle && { subtitle }) };

return { ...(!isEmpty(apnsOptions) && { apnsOptions }) };
};

Expand All @@ -91,6 +96,7 @@ const getFcmOptions = ({
senderId,
sendTime: new Date(sendTime),
};

return { ...(!isEmpty(fcmOptions) && { fcmOptions }) };
};

Expand Down
50 changes: 0 additions & 50 deletions packages/rtn-push-notification/tslint.json

This file was deleted.

3 changes: 2 additions & 1 deletion packages/rtn-web-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"build": "npm run clean && npm run build:esm-cjs",
"clean": "rimraf dist lib lib-esm",
"format": "echo \"Not implemented\"",
"lint": "tslint 'src/**/*.ts' && npm run ts-coverage",
"lint": "eslint '**/*.{ts,tsx}' && npm run ts-coverage",
"lint:fix": "eslint '**/*.{ts,tsx}' --fix",
"ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 88.21"
},
"devDependencies": {
Expand Down
5 changes: 4 additions & 1 deletion packages/rtn-web-browser/src/apis/openAuthSessionAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
NativeEventSubscription,
Platform,
} from 'react-native';

import { nativeModule } from '../nativeModule';

let appStateListener: NativeEventSubscription | undefined;
Expand All @@ -31,12 +32,13 @@ export const openAuthSessionAsync = async (
const openAuthSessionIOS = async (
url: string,
redirectUrls: string[],
prefersEphemeralSession: boolean = false,
prefersEphemeralSession = false,
) => {
const redirectUrl = redirectUrls.find(
// take the first non-web url as the deeplink
item => !item.startsWith('https://') && !item.startsWith('http://'),
);

return nativeModule.openAuthSessionAsync(
url,
redirectUrl,
Expand All @@ -56,6 +58,7 @@ const openAuthSessionAndroid = async (url: string, redirectUrls: string[]) => {
// open chrome tab
nativeModule.openAuthSessionAsync(url),
]);

return redirectUrl;
} finally {
appStateListener?.remove();
Expand Down
1 change: 1 addition & 0 deletions packages/rtn-web-browser/src/nativeModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { NativeModules } from 'react-native';

import { LINKING_ERROR } from './constants';
import { WebBrowserNativeModule } from './types';

Expand Down
Loading

0 comments on commit 0e0c496

Please sign in to comment.