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

[No QA] Remove all inline named exports. Update style guide. #6013

Merged
merged 4 commits into from
Oct 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion STORYBOOK.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ export default {
const Template = args => <Button {...args} />;

// Each story must be exported with a named export
export const Default = Template.bind({});
const Default = Template.bind({});
Default.args = {
text: 'Save & Continue',
success: true,
};
export {
Default,
};
```

That will give us an interactive playground to test out various component attributes with the defaults we passed.
Expand Down
18 changes: 17 additions & 1 deletion STYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,23 @@ ES6 provides two ways to export a module from a file: `named export` and `defaul
- Files with multiple exports should always use named exports
- Files with a single method or variable export are OK to use named exports
- Mixing default and named exports in a single file is OK (e.g. in a self contained module), but should rarely be used
- All exports should be declared at the bottom of the file
- All exports (both default and named) should happen at the bottom of the file
- Do **not** export individual features inline.

```javascript
// Bad
export const something = 'nope';
export const somethingElse = 'stop';

// Good
const something = 'yep';
const somethingElse = 'go';

export {
something,
somethingElse,
};
```

## Classes and constructors

Expand Down
33 changes: 23 additions & 10 deletions __mocks__/react-native-permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ const {RESULTS} = require('react-native-permissions/dist/commonjs/results');

export {PERMISSIONS, RESULTS};

export const openLimitedPhotoLibraryPicker = jest.fn((() => {}));
export const openSettings = jest.fn(() => {});
export const check = jest.fn(() => RESULTS.GRANTED);
export const request = jest.fn(() => RESULTS.GRANTED);
export const checkLocationAccuracy = jest.fn(() => 'full');
export const requestLocationAccuracy = jest.fn(() => 'full');
const openLimitedPhotoLibraryPicker = jest.fn((() => {}));
const openSettings = jest.fn(() => {});
const check = jest.fn(() => RESULTS.GRANTED);
const request = jest.fn(() => RESULTS.GRANTED);
const checkLocationAccuracy = jest.fn(() => 'full');
const requestLocationAccuracy = jest.fn(() => 'full');

const notificationOptions = ['alert', 'badge', 'sound', 'carPlay', 'criticalAlert', 'provisional'];

Expand All @@ -23,12 +23,12 @@ const notificationSettings = {
notificationCenter: true,
};

export const checkNotifications = jest.fn(() => ({
const checkNotifications = jest.fn(() => ({
status: RESULTS.GRANTED,
settings: notificationSettings,
}));

export const requestNotifications = jest.fn(options => ({
const requestNotifications = jest.fn(options => ({
status: RESULTS.GRANTED,
settings: options
.filter(option => notificationOptions.includes(option))
Expand All @@ -38,12 +38,12 @@ export const requestNotifications = jest.fn(options => ({
}),
}));

export const checkMultiple = jest.fn(permissions => permissions.reduce((acc, permission) => ({
const checkMultiple = jest.fn(permissions => permissions.reduce((acc, permission) => ({
...acc,
[permission]: RESULTS.GRANTED,
})));

export const requestMultiple = jest.fn(permissions => permissions.reduce((acc, permission) => ({
const requestMultiple = jest.fn(permissions => permissions.reduce((acc, permission) => ({
...acc,
[permission]: RESULTS.GRANTED,
})));
Expand All @@ -63,3 +63,16 @@ export default {
requestMultiple,
requestNotifications,
};

export {
openLimitedPhotoLibraryPicker,
openSettings,
check,
request,
checkLocationAccuracy,
requestLocationAccuracy,
checkNotifications,
requestNotifications,
checkMultiple,
requestMultiple,
};
8 changes: 4 additions & 4 deletions __mocks__/urbanairship-react-native.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export default {
setUserNotificationsEnabled: jest.fn(),
};

const EventType = {
NotificationResponse: 'notificationResponse',
PushReceived: 'pushReceived',
};

export default {
setUserNotificationsEnabled: jest.fn(),
};

export {
EventType,
};
6 changes: 5 additions & 1 deletion src/components/withDrawerState.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import {useDrawerStatus} from '@react-navigation/drawer';
import getComponentDisplayName from '../libs/getComponentDisplayName';

export const withDrawerPropTypes = {
const withDrawerPropTypes = {
isDrawerOpen: PropTypes.bool.isRequired,
};

Expand Down Expand Up @@ -36,3 +36,7 @@ export default function withDrawerState(WrappedComponent) {
<WithDrawerState {...props} forwardedRef={ref} />
));
}

export {
withDrawerPropTypes,
};
6 changes: 5 additions & 1 deletion src/libs/Growl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import CONST from '../CONST';

export const growlRef = React.createRef();
const growlRef = React.createRef();

/**
* Show the growl notification
Expand Down Expand Up @@ -39,3 +39,7 @@ export default {
error,
success,
};

export {
growlRef,
};
6 changes: 5 additions & 1 deletion src/libs/Navigation/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Onyx.connect({
callback: val => isLoggedIn = Boolean(val && val.authToken),
});

export const navigationRef = createNavigationContainerRef();
const navigationRef = createNavigationContainerRef();

// This flag indicates that we're trying to deeplink to a report when react-navigation is not fully loaded yet.
// If true, this flag will cause the drawer to start in a closed state (which is not the default for small screens)
Expand Down Expand Up @@ -204,3 +204,7 @@ export default {
getDefaultDrawerState,
setDidTapNotification,
};

export {
navigationRef,
};
9 changes: 7 additions & 2 deletions src/libs/canCaptureMetrics/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import CONFIG from '../../CONFIG';

// We don't capture performance metrics on web as there are enough tools available
export const canCapturePerformanceMetrics = () => false;
const canCapturePerformanceMetrics = () => false;

export const canCaptureOnyxMetrics = () => Boolean(CONFIG.ONYX_METRICS);
const canCaptureOnyxMetrics = () => Boolean(CONFIG.ONYX_METRICS);

export {
canCapturePerformanceMetrics,
canCaptureOnyxMetrics,
};
9 changes: 7 additions & 2 deletions src/libs/canCaptureMetrics/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ import CONFIG from '../../CONFIG';
*
* @returns {Boolean}
*/
export const canCapturePerformanceMetrics = () => CONFIG.CAPTURE_METRICS;
const canCapturePerformanceMetrics = () => CONFIG.CAPTURE_METRICS;

/**
* Is capturing Onyx stats enabled.
*
* @returns {Boolean}
*/
export const canCaptureOnyxMetrics = () => CONFIG.ONYX_METRICS;
const canCaptureOnyxMetrics = () => CONFIG.ONYX_METRICS;

export {
canCapturePerformanceMetrics,
canCaptureOnyxMetrics,
};
6 changes: 5 additions & 1 deletion src/pages/home/report/ContextMenu/ContextMenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function getActionText(reportAction) {
return lodashGet(message, 'html', '');
}

export const CONTEXT_MENU_TYPES = {
const CONTEXT_MENU_TYPES = {
LINK: 'LINK',
REPORT_ACTION: 'REPORT_ACTION',
};
Expand Down Expand Up @@ -132,3 +132,7 @@ export default [
},
},
];

export {
CONTEXT_MENU_TYPES,
};
9 changes: 7 additions & 2 deletions src/stories/Button.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const Template = args => <Button {...args} />;

// Arguments can be passed to the component by binding
// See: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
export const Default = Template.bind({});
export const Loading = Template.bind({});
const Default = Template.bind({});
const Loading = Template.bind({});
Default.args = {
text: 'Save & Continue',
success: true,
Expand All @@ -27,3 +27,8 @@ Loading.args = {
isLoading: true,
success: true,
};

export {
Default,
Loading,
};
6 changes: 5 additions & 1 deletion src/stories/ButtonWithDropdown.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ const Template = args => <ButtonWithDropdown {...args} />;

// Arguments can be passed to the component by binding
// See: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
export const Default = Template.bind({});
const Default = Template.bind({});
Default.args = {
buttonText: 'Pay with Venmo',
};

export {
Default,
};
6 changes: 5 additions & 1 deletion src/stories/Checkbox.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ const Template = args => <Checkbox {...args} />;

// Arguments can be passed to the component by binding
// See: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
export const Default = Template.bind({});
const Default = Template.bind({});
Default.args = {
onPress: () => {},
isChecked: true,
};

export {
Default,
};
12 changes: 9 additions & 3 deletions src/stories/CheckboxWithLabel.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const Template = args => <CheckboxWithLabel {...args} />;

// Arguments can be passed to the component by binding
// See: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
export const Default = Template.bind({});
export const WithLabelComponent = Template.bind({});
export const WithErrors = Template.bind({});
const Default = Template.bind({});
const WithLabelComponent = Template.bind({});
const WithErrors = Template.bind({});
Default.args = {
isChecked: true,
label: 'Plain text label',
Expand All @@ -46,3 +46,9 @@ WithErrors.args = {
onPress: () => {},
label: 'I accept the Terms & Conditions',
};

export {
Default,
WithLabelComponent,
WithErrors,
};
9 changes: 7 additions & 2 deletions src/stories/Datepicker.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const Template = args => <DatePicker {...args} />;

// Arguments can be passed to the component by binding
// See: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
export const Default = Template.bind({});
export const PreFilled = Template.bind({});
const Default = Template.bind({});
const PreFilled = Template.bind({});
Default.args = {
label: 'Select Date',
};
Expand All @@ -36,3 +36,8 @@ PreFilled.args = {
label: 'Select Date',
value: new Date(2018, 7, 21),
};

export {
Default,
PreFilled,
};
6 changes: 5 additions & 1 deletion src/stories/Header.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ const Template = args => <Header {...args} />;

// Arguments can be passed to the component by binding
// See: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
export const Default = Template.bind({});
const Default = Template.bind({});
Default.args = {
title: 'Chats',
shouldShowEnvironmentBadge: true,
};

export {
Default,
};
12 changes: 9 additions & 3 deletions src/stories/HeaderWithCloseButton.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const Template = args => <HeaderWithCloseButton {...args} />;

// Arguments can be passed to the component by binding
// See: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
export const Default = Template.bind({});
export const Attachment = Template.bind({});
export const Profile = Template.bind({});
const Default = Template.bind({});
const Attachment = Template.bind({});
const Profile = Template.bind({});
Default.args = {
title: 'Settings',
};
Expand All @@ -30,3 +30,9 @@ Profile.args = {
title: 'Profile',
shouldShowBackButton: true,
};

export {
Default,
Attachment,
Profile,
};