Skip to content

Commit

Permalink
Code Quality: Restrict usage of direct React imports (#28278)
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Jan 19, 2021
1 parent f6129f6 commit 8198daa
Show file tree
Hide file tree
Showing 29 changed files with 90 additions and 93 deletions.
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ module.exports = {
importNames: [ 'memoize' ],
message: 'Please use `memize` instead.',
},
{
name: 'react',
message:
'Please use React API through `@wordpress/element` instead.',
},
{
name: 'reakit',
message:
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

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

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* External dependencies
*/
import React from 'react';
import { View } from 'react-native';

/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { Spinner } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import {
Expand All @@ -31,7 +31,7 @@ export const MEDIA_SAVE_STATE_RESET = 8;
export const MEDIA_SAVE_FINAL_STATE_RESULT = 9;
export const MEDIA_SAVE_MEDIAID_CHANGED = 10;

export class BlockMediaUpdateProgress extends React.Component {
export class BlockMediaUpdateProgress extends Component {
constructor( props ) {
super( props );

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/**
* External dependencies
*/
import React from 'react';
import { View } from 'react-native';

/**
* WordPress dependencies
*/
import { Children } from '@wordpress/element';
import { createSlotFill, BottomSheetConsumer } from '@wordpress/components';

/**
* Internal dependencies
*/
Expand All @@ -30,7 +32,7 @@ const FillWithSettingsButton = ( { children, ...props } ) => {
</BottomSheetConsumer>
}
</Fill>
{ React.Children.count( children ) > 0 && <BlockSettingsButton /> }
{ Children.count( children ) > 0 && <BlockSettingsButton /> }
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* External dependencies
*/
import React from 'react';
import { View } from 'react-native';

/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { Spinner } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { subscribeMediaUpload } from '@wordpress/react-native-bridge';
Expand All @@ -21,7 +21,7 @@ export const MEDIA_UPLOAD_STATE_SUCCEEDED = 2;
export const MEDIA_UPLOAD_STATE_FAILED = 3;
export const MEDIA_UPLOAD_STATE_RESET = 4;

export class MediaUploadProgress extends React.Component {
export class MediaUploadProgress extends Component {
constructor( props ) {
super( props );

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
/**
* External dependencies
*/
import React from 'react';

/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { Picker } from '@wordpress/components';
import {
Expand All @@ -29,7 +25,7 @@ export const OPTION_TAKE_VIDEO = __( 'Take a Video' );
export const OPTION_TAKE_PHOTO = __( 'Take a Photo' );
export const OPTION_TAKE_PHOTO_OR_VIDEO = __( 'Take a Photo or Video' );

export class MediaUpload extends React.Component {
export class MediaUpload extends Component {
constructor( props ) {
super( props );
this.onPickerPresent = this.onPickerPresent.bind( this );
Expand Down
1 change: 0 additions & 1 deletion packages/block-library/src/file/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import { View, Clipboard, TouchableWithoutFeedback, Text } from 'react-native';
import React from 'react';

/**
* WordPress dependencies
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/image/edit.native.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* External dependencies
*/
import React from 'react';
import { View, TouchableWithoutFeedback } from 'react-native';
import { isEmpty, get, find, map } from 'lodash';

/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import {
requestMediaImport,
mediaUploadSync,
Expand Down Expand Up @@ -61,7 +61,7 @@ const getUrlForSlug = ( image, { sizeSlug } ) => {
return get( image, [ 'media_details', 'sizes', sizeSlug, 'source_url' ] );
};

export class ImageEdit extends React.Component {
export class ImageEdit extends Component {
constructor( props ) {
super( props );

Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/video/edit.native.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* External dependencies
*/
import React from 'react';
import { View, TouchableWithoutFeedback, Text } from 'react-native';
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import {
mediaUploadSync,
requestImageFailedRetryDialog,
Expand Down Expand Up @@ -49,7 +49,7 @@ const ICON_TYPE = {
UPLOAD: 'upload',
};

class VideoEdit extends React.Component {
class VideoEdit extends Component {
constructor( props ) {
super( props );

Expand Down
1 change: 0 additions & 1 deletion packages/components/src/color-picker/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import { View, Text, TouchableWithoutFeedback, Platform } from 'react-native';
import React from 'react';
import HsvColorPicker from 'react-native-hsv-color-picker';
import tinycolor from 'tinycolor2';
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
import React from 'react';
import {
Keyboard,
LayoutAnimation,
Expand All @@ -11,14 +10,19 @@ import {
Dimensions,
} from 'react-native';

/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';

/**
* This is a simplified version of Facebook's KeyboardAvoidingView.
* It's meant to work specifically with BottomSheets.
* This fixes an issue in the bottom padding calculation, when the
* BottomSheet was presented on Landscape, with the keyboard already present,
* and a TextField on Autofocus (situation present on Links UI)
*/
class KeyboardAvoidingView extends React.Component {
class KeyboardAvoidingView extends Component {
constructor() {
super( ...arguments );

Expand Down
7 changes: 3 additions & 4 deletions packages/components/src/mobile/color-settings/index.native.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/**
* External dependencies
*/
import React from 'react';
import { useRoute } from '@react-navigation/native';

/**
* WordPress dependencies
*/
import { useEffect, useContext } from '@wordpress/element';
import { memo, useEffect, useContext } from '@wordpress/element';
import { BottomSheetContext, BottomSheet } from '@wordpress/components';
import { useRoute } from '@react-navigation/native';

/**
* Internal dependencies
Expand All @@ -19,7 +18,7 @@ import PaletteScreen from './palette.screen';

import { colorsUtils } from './utils';

const ColorSettingsMemo = React.memo(
const ColorSettingsMemo = memo(
( {
defaultSettings,
onHandleClosingBottomSheet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import { useRoute, useNavigation } from '@react-navigation/native';
import React from 'react';

/**
* WordPress dependencies
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/**
* External dependencies
*/
import React from 'react';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
import { FlatList } from 'react-native';
import { isEqual } from 'lodash';

/**
* WordPress dependencies
*/
import { memo } from '@wordpress/element';

const List = React.memo( FlatList, isEqual );
const List = memo( FlatList, isEqual );

export const KeyboardAwareFlatList = ( {
extraScrollHeight,
Expand Down
3 changes: 1 addition & 2 deletions packages/components/src/mobile/link-picker/index.native.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/**
* External dependencies
*/
import { useState } from 'react';
import { SafeAreaView, TouchableOpacity, View } from 'react-native';
import { lowerCase, startsWith } from 'lodash';

/**
* WordPress dependencies
*/

import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { BottomSheet, Icon } from '@wordpress/components';
import { getProtocol, prependHTTP } from '@wordpress/url';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* External dependencies
*/
import React from 'react';
import { useNavigation, useRoute } from '@react-navigation/native';

/**
* WordPress dependencies
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/**
* External dependencies
*/
import React from 'react';
import { useNavigation, useRoute } from '@react-navigation/native';

/**
* WordPress dependencies
*/
import { useMemo } from '@wordpress/element';

/**
* Internal dependencies
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/mobile/media-edit/index.native.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* External dependencies
*/
import React from 'react';
import { compact } from 'lodash';

/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { Picker } from '@wordpress/components';
import {
Expand All @@ -32,7 +32,7 @@ const replaceOption = {
types: [ MEDIA_TYPE_IMAGE ],
};

export class MediaEdit extends React.Component {
export class MediaEdit extends Component {
constructor( props ) {
super( props );
this.onPickerPresent = this.onPickerPresent.bind( this );
Expand Down
1 change: 0 additions & 1 deletion packages/components/src/mobile/picker/index.android.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
import React from 'react';
import { View } from 'react-native';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* External dependencies
*/
import { useRef } from 'react';
import { ScrollView, View } from 'react-native';

/**
* WordPress dependencies
*/
import { useRef } from '@wordpress/element';
import { compose, withPreferredColorScheme } from '@wordpress/compose';
import { withSelect, withDispatch } from '@wordpress/data';
import { withViewportMatch } from '@wordpress/viewport';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/**
* External dependencies
*/
import React from 'react';
/**
* WordPress dependencies
*/
import { memo } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { withDispatch, withSelect } from '@wordpress/data';
import { compose, withPreferredColorScheme } from '@wordpress/compose';
Expand All @@ -16,7 +13,7 @@ import { ReadableContentView } from '@wordpress/components';
*/
import styles from './style.scss';

const Header = React.memo(
const Header = memo(
function EditorHeader( {
editTitle,
setTitleRef,
Expand Down
4 changes: 2 additions & 2 deletions packages/element/src/create-interpolate-element.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
* Internal dependencies
*/
import { createElement, cloneElement, Fragment, isValidElement } from 'react';
import { createElement, cloneElement, Fragment, isValidElement } from './react';

/** @typedef {import('./react').WPElement} WPElement */

Expand Down
1 change: 1 addition & 0 deletions packages/element/src/react.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* External dependencies
*/
// eslint-disable-next-line no-restricted-imports
import {
Children,
cloneElement,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
import React from 'react';
import { Platform, Keyboard } from 'react-native';
import { useNavigation, useRoute } from '@react-navigation/native';
import { delay } from 'lodash';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
import React from 'react';
import { useNavigation, useRoute } from '@react-navigation/native';
/**
* WordPress dependencies
Expand Down
Loading

0 comments on commit 8198daa

Please sign in to comment.