Skip to content

Enable ESLint rule / DEV alert() to match with useOnyx canBeMissing option #59191

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

Merged
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
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
1 change: 1 addition & 0 deletions .eslintrc.changed.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
rules: {
'deprecation/deprecation': 'error',
'rulesdir/no-default-id-values': 'error',
'rulesdir/provide-canBeMissing-in-useOnyx': 'error',
'no-restricted-syntax': [
'error',
{
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
"electron-builder": "25.0.0",
"eslint": "^8.57.0",
"eslint-config-airbnb-typescript": "^18.0.0",
"eslint-config-expensify": "2.0.75",
"eslint-config-expensify": "2.0.78",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-deprecation": "^3.0.0",
"eslint-plugin-jest": "^28.6.0",
Expand Down
17 changes: 13 additions & 4 deletions src/Expensify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import {AppState, Linking, Platform} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import Onyx, {useOnyx} from 'react-native-onyx';
import alert from './components/Alert';
import ConfirmModal from './components/ConfirmModal';
import DeeplinkWrapper from './components/DeeplinkWrapper';
import EmojiPicker from './components/EmojiPicker/EmojiPicker';
Expand All @@ -24,6 +25,7 @@
import * as Report from './libs/actions/Report';
import * as User from './libs/actions/User';
import * as ActiveClientManager from './libs/ActiveClientManager';
import * as Environment from './libs/Environment/Environment';
import FS from './libs/Fullstory';
import * as Growl from './libs/Growl';
import Log from './libs/Log';
Expand All @@ -45,14 +47,21 @@
import SplashScreenStateContext from './SplashScreenStateContext';
import type {ScreenShareRequest} from './types/onyx';

Onyx.registerLogger(({level, message}) => {
Onyx.registerLogger(({level, message, parameters}) => {
if (level === 'alert') {
Log.alert(message);
Log.alert(message, parameters);
console.error(message);

// useOnyx() calls with "canBeMissing" config set to false will display a visual alert in dev environment
// when they doesn't return data.
const shouldShowAlert = typeof parameters === 'object' && !Array.isArray(parameters) && 'showAlert' in parameters && 'key' in parameters;
if (Environment.isDevelopment() && shouldShowAlert) {
alert(`${message} Key: ${parameters.key as string}`);
}
} else if (level === 'hmmm') {
Log.hmmm(message);
Log.hmmm(message, parameters);
} else {
Log.info(message);
Log.info(message, undefined, parameters);
}
});

Expand Down Expand Up @@ -85,16 +94,16 @@
const {splashScreenState, setSplashScreenState} = useContext(SplashScreenStateContext);
const [hasAttemptedToOpenPublicRoom, setAttemptedToOpenPublicRoom] = useState(false);
const {translate} = useLocalize();
const [account] = useOnyx(ONYXKEYS.ACCOUNT);

Check failure on line 97 in src/Expensify.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

useOnyx() calls require you to pass the "canBeMissing" param
const [session] = useOnyx(ONYXKEYS.SESSION);

Check failure on line 98 in src/Expensify.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

useOnyx() calls require you to pass the "canBeMissing" param
const [lastRoute] = useOnyx(ONYXKEYS.LAST_ROUTE);

Check failure on line 99 in src/Expensify.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

useOnyx() calls require you to pass the "canBeMissing" param
const [userMetadata] = useOnyx(ONYXKEYS.USER_METADATA);

Check failure on line 100 in src/Expensify.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

useOnyx() calls require you to pass the "canBeMissing" param
const [isCheckingPublicRoom] = useOnyx(ONYXKEYS.IS_CHECKING_PUBLIC_ROOM, {initWithStoredValues: false});

Check failure on line 101 in src/Expensify.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

useOnyx() calls require you to pass the "canBeMissing" param
const [updateAvailable] = useOnyx(ONYXKEYS.UPDATE_AVAILABLE, {initWithStoredValues: false});

Check failure on line 102 in src/Expensify.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

useOnyx() calls require you to pass the "canBeMissing" param
const [updateRequired] = useOnyx(ONYXKEYS.UPDATE_REQUIRED, {initWithStoredValues: false});

Check failure on line 103 in src/Expensify.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

useOnyx() calls require you to pass the "canBeMissing" param
const [isSidebarLoaded] = useOnyx(ONYXKEYS.IS_SIDEBAR_LOADED);

Check failure on line 104 in src/Expensify.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

useOnyx() calls require you to pass the "canBeMissing" param
const [screenShareRequest] = useOnyx(ONYXKEYS.SCREEN_SHARE_REQUEST);

Check failure on line 105 in src/Expensify.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

useOnyx() calls require you to pass the "canBeMissing" param
const [focusModeNotification] = useOnyx(ONYXKEYS.FOCUS_MODE_NOTIFICATION, {initWithStoredValues: false});

Check failure on line 106 in src/Expensify.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

useOnyx() calls require you to pass the "canBeMissing" param
const [lastVisitedPath] = useOnyx(ONYXKEYS.LAST_VISITED_PATH);

useDebugShortcut();
Expand Down
Loading