chore: ensure consistent use of import type (#1971)

We hit issues when building react-native-svg because of inconsistent use of import type. This change adds ESLint result to ensure consistency. I also ran yarn lint --fix to fix up the code.
This commit is contained in:
Tommy Nguyen
2023-01-31 14:12:21 +01:00
committed by GitHub
parent cb87e7510f
commit f2f533a292
47 changed files with 136 additions and 108 deletions

View File

@@ -1,4 +1,12 @@
module.exports = {
extends: '@react-native-community',
rules: { 'no-bitwise': 0, '@typescript-eslint/no-explicit-any': 2 },
parserOptions: {
project: ["./tsconfig.json"],
},
rules: {
'no-bitwise': 'off',
'@typescript-eslint/consistent-type-exports': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/no-explicit-any': 'error',
},
};

View File

@@ -1,9 +1,10 @@
import React, { useState, useEffect, Component } from 'react';
import { Platform, Image, ImageSourcePropType } from 'react-native';
import type { ImageSourcePropType } from 'react-native';
import { Platform, Image } from 'react-native';
import { fetchText } from './xml';
import { SvgCss, SvgWithCss } from './css';
import { SvgProps } from './elements/Svg';
import type { SvgProps } from './elements/Svg';
import type { Spec } from './fabric/NativeSvgRenderableModule';
export function getUriFromSource(source: ImageSourcePropType) {

View File

@@ -1,12 +1,15 @@
import * as React from 'react';
import type { GestureResponderEvent, TransformsStyle } from 'react-native';
import {
GestureResponderEvent,
// @ts-ignore
unstable_createElement as ucE,
createElement as cE,
TransformsStyle,
} from 'react-native';
import { NumberArray, NumberProp, TransformProps } from './lib/extract/types';
import type {
NumberArray,
NumberProp,
TransformProps,
} from './lib/extract/types';
import SvgTouchableMixin from './lib/SvgTouchableMixin';
import { resolve } from './lib/resolve';
import { transformsArrayToProps } from './lib/extract/extractTransform';

View File

@@ -1,33 +1,30 @@
import React, { Component, useEffect, useMemo, useState } from 'react';
import {
camelCase,
err,
fetchText,
import type {
JsxAST,
Middleware,
parse,
Styles,
SvgAst,
UriProps,
UriState,
XmlAST,
XmlProps,
XmlState,
} from './xml';
import csstree, {
import { camelCase, err, fetchText, parse, SvgAst } from './xml';
import type {
Atrule,
AtrulePrelude,
CssNode,
Declaration,
DeclarationList,
List,
ListItem,
PseudoClassSelector,
Rule,
Selector,
SelectorList,
} from 'css-tree';
import cssSelect, { Options } from 'css-select';
import csstree, { List } from 'css-tree';
import type { Options } from 'css-select';
import cssSelect from 'css-select';
/*
* Style element inlining experiment based on SVGO

View File

@@ -1,9 +1,9 @@
import React from 'react';
import { extract, stringifyPropsForFabric } from '../lib/extract/extractProps';
import { CommonPathProps, NumberProp } from '../lib/extract/types';
import type { CommonPathProps, NumberProp } from '../lib/extract/types';
import Shape from './Shape';
import RNSVGCircle from '../fabric/CircleNativeComponent';
import { NativeMethods } from 'react-native';
import type { NativeMethods } from 'react-native';
export interface CircleProps extends CommonPathProps {
cx?: NumberProp;

View File

@@ -1,4 +1,5 @@
import React, { ReactNode } from 'react';
import type { ReactNode } from 'react';
import React from 'react';
import { extract } from '../lib/extract/extractProps';
import Shape from './Shape';
import RNSVGClipPath from '../fabric/ClipPathNativeComponent';

View File

@@ -1,9 +1,9 @@
import React from 'react';
import { extract, stringifyPropsForFabric } from '../lib/extract/extractProps';
import { CommonPathProps, NumberProp } from '../lib/extract/types';
import type { CommonPathProps, NumberProp } from '../lib/extract/types';
import Shape from './Shape';
import RNSVGEllipse from '../fabric/EllipseNativeComponent';
import { NativeMethods } from 'react-native';
import type { NativeMethods } from 'react-native';
export interface EllipseProps extends CommonPathProps {
cx?: NumberProp;

View File

@@ -1,12 +1,13 @@
import React, { ReactNode } from 'react';
import type { ReactNode } from 'react';
import React from 'react';
import {
withoutXY,
stringifyPropsForFabric,
} from '../lib/extract/extractProps';
import { NumberProp } from '../lib/extract/types';
import type { NumberProp } from '../lib/extract/types';
import G from './G';
import RNSVGForeignObject from '../fabric/ForeignObjectNativeComponent';
import { NativeMethods } from 'react-native';
import type { NativeMethods } from 'react-native';
export interface ForeignObjectProps {
children?: ReactNode;

View File

@@ -1,8 +1,9 @@
import React, { ReactNode } from 'react';
import type { ReactNode } from 'react';
import React from 'react';
import extractProps, { propsAndStyles } from '../lib/extract/extractProps';
import { extractFont } from '../lib/extract/extractText';
import extractTransform from '../lib/extract/extractTransform';
import {
import type {
CommonPathProps,
FontProps,
NumberProp,
@@ -10,7 +11,7 @@ import {
} from '../lib/extract/types';
import Shape from './Shape';
import RNSVGGroup from '../fabric/GroupNativeComponent';
import { NativeMethods } from 'react-native';
import type { NativeMethods } from 'react-native';
export interface GProps extends CommonPathProps, FontProps {
children?: ReactNode;

View File

@@ -1,11 +1,12 @@
import React from 'react';
import { Image, ImageProps as RNImageProps, NativeMethods } from 'react-native';
import type { ImageProps as RNImageProps, NativeMethods } from 'react-native';
import { Image } from 'react-native';
import { alignEnum, meetOrSliceTypes } from '../lib/extract/extractViewBox';
import {
stringifyPropsForFabric,
withoutXY,
} from '../lib/extract/extractProps';
import {
import type {
ClipProps,
CommonMaskProps,
NativeProps,

View File

@@ -1,9 +1,9 @@
import React from 'react';
import { extract, stringifyPropsForFabric } from '../lib/extract/extractProps';
import { CommonPathProps, NumberProp } from '../lib/extract/types';
import type { CommonPathProps, NumberProp } from '../lib/extract/types';
import Shape from './Shape';
import RNSVGLine from '../fabric/LineNativeComponent';
import { NativeMethods } from 'react-native';
import type { NativeMethods } from 'react-native';
export interface LineProps extends CommonPathProps {
opacity?: NumberProp;

View File

@@ -1,10 +1,11 @@
import React, { ReactElement } from 'react';
import type { ReactElement } from 'react';
import React from 'react';
import extractGradient from '../lib/extract/extractGradient';
import { NumberProp, TransformProps, Units } from '../lib/extract/types';
import type { NumberProp, TransformProps, Units } from '../lib/extract/types';
import Shape from './Shape';
import RNSVGLinearGradient from '../fabric/LinearGradientNativeComponent';
import { stringifyPropsForFabric } from '../lib/extract/extractProps';
import { NativeMethods } from 'react-native';
import type { NativeMethods } from 'react-native';
export interface LinearGradientProps {
children?: ReactElement[];

View File

@@ -1,10 +1,11 @@
import React, { ReactNode } from 'react';
import type { ReactNode } from 'react';
import React from 'react';
import extractViewBox from '../lib/extract/extractViewBox';
import { NumberProp } from '../lib/extract/types';
import type { NumberProp } from '../lib/extract/types';
import Shape from './Shape';
import RNSVGMarker from '../fabric/MarkerNativeComponent';
import { stringifyPropsForFabric } from '../lib/extract/extractProps';
import { NativeMethods } from 'react-native';
import type { NativeMethods } from 'react-native';
export type MarkerUnits = 'strokeWidth' | 'userSpaceOnUse';

View File

@@ -1,13 +1,14 @@
import React, { ReactNode } from 'react';
import type { ReactNode } from 'react';
import React from 'react';
import {
stringifyPropsForFabric,
withoutXY,
} from '../lib/extract/extractProps';
import { CommonPathProps, NumberProp } from '../lib/extract/types';
import type { CommonPathProps, NumberProp } from '../lib/extract/types';
import units from '../lib/units';
import Shape from './Shape';
import RNSVGMask from '../fabric/MaskNativeComponent';
import { NativeMethods } from 'react-native';
import type { NativeMethods } from 'react-native';
export type TMaskUnits = 'userSpaceOnUse' | 'objectBoundingBox';

View File

@@ -2,8 +2,8 @@ import React from 'react';
import { extract } from '../lib/extract/extractProps';
import Shape from './Shape';
import RNSVGPath from '../fabric/PathNativeComponent';
import { CommonPathProps, NumberProp } from '../lib/extract/types';
import { NativeMethods } from 'react-native';
import type { CommonPathProps, NumberProp } from '../lib/extract/types';
import type { NativeMethods } from 'react-native';
export interface PathProps extends CommonPathProps {
d?: string;

View File

@@ -1,12 +1,13 @@
import React, { ReactNode } from 'react';
import type { ReactNode } from 'react';
import React from 'react';
import extractTransform from '../lib/extract/extractTransform';
import extractViewBox from '../lib/extract/extractViewBox';
import { NumberProp, TransformProps, Units } from '../lib/extract/types';
import type { NumberProp, TransformProps, Units } from '../lib/extract/types';
import units from '../lib/units';
import Shape from './Shape';
import RNSVGPattern from '../fabric/PatternNativeComponent';
import { stringifyPropsForFabric } from '../lib/extract/extractProps';
import { NativeMethods } from 'react-native';
import type { NativeMethods } from 'react-native';
export interface PatternProps extends TransformProps {
children?: ReactNode;

View File

@@ -1,7 +1,7 @@
import React from 'react';
import Path from './Path';
import Shape from './Shape';
import { CommonPathProps, NumberProp } from '../lib/extract/types';
import type { CommonPathProps, NumberProp } from '../lib/extract/types';
import extractPolyPoints from '../lib/extract/extractPolyPoints';
export interface PolygonProps extends CommonPathProps {

View File

@@ -1,7 +1,7 @@
import React from 'react';
import Path from './Path';
import Shape from './Shape';
import { CommonPathProps, NumberProp } from '../lib/extract/types';
import type { CommonPathProps, NumberProp } from '../lib/extract/types';
import extractPolyPoints from '../lib/extract/extractPolyPoints';
export interface PolylineProps extends CommonPathProps {

View File

@@ -1,10 +1,11 @@
import React, { ReactElement } from 'react';
import type { ReactElement } from 'react';
import React from 'react';
import extractGradient from '../lib/extract/extractGradient';
import { NumberProp, TransformProps, Units } from '../lib/extract/types';
import type { NumberProp, TransformProps, Units } from '../lib/extract/types';
import Shape from './Shape';
import RNSVGRadialGradient from '../fabric/RadialGradientNativeComponent';
import { stringifyPropsForFabric } from '../lib/extract/extractProps';
import { NativeMethods } from 'react-native';
import type { NativeMethods } from 'react-native';
export interface RadialGradientProps {
children?: ReactElement[];

View File

@@ -3,10 +3,10 @@ import {
stringifyPropsForFabric,
withoutXY,
} from '../lib/extract/extractProps';
import { CommonPathProps, NumberProp } from '../lib/extract/types';
import type { CommonPathProps, NumberProp } from '../lib/extract/types';
import Shape from './Shape';
import RNSVGRect from '../fabric/RectNativeComponent';
import { NativeMethods } from 'react-native';
import type { NativeMethods } from 'react-native';
export interface RectProps extends CommonPathProps {
x?: NumberProp;

View File

@@ -1,8 +1,9 @@
import { Component } from 'react';
import SvgTouchableMixin from '../lib/SvgTouchableMixin';
import extractBrush from '../lib/extract/extractBrush';
import { ColorValue, findNodeHandle, NativeMethods } from 'react-native';
import {
import type { ColorValue, NativeMethods } from 'react-native';
import { findNodeHandle } from 'react-native';
import type {
ColumnMajorTransformMatrix,
TransformProps,
} from '../lib/extract/types';

View File

@@ -1,6 +1,6 @@
import { Component } from 'react';
import { ColorValue } from 'react-native';
import { NumberProp } from '../lib/extract/types';
import type { ColorValue } from 'react-native';
import type { NumberProp } from '../lib/extract/types';
export interface StopProps {
stopColor?: ColorValue;

View File

@@ -1,18 +1,17 @@
import React, { Component } from 'react';
import {
import type { Component } from 'react';
import React from 'react';
import type {
ColorValue,
findNodeHandle,
MeasureInWindowOnSuccessCallback,
MeasureLayoutOnSuccessCallback,
MeasureOnSuccessCallback,
NativeMethods,
Platform,
StyleProp,
StyleSheet,
ViewProps,
ViewStyle,
} from 'react-native';
import {
import { findNodeHandle, Platform, StyleSheet } from 'react-native';
import type {
extractedProps,
NumberProp,
ResponderInstanceProps,
@@ -20,7 +19,8 @@ import {
import extractResponder from '../lib/extract/extractResponder';
import extractViewBox from '../lib/extract/extractViewBox';
import Shape from './Shape';
import G, { GProps } from './G';
import type { GProps } from './G';
import G from './G';
import RNSVGSvgAndroid from '../fabric/AndroidSvgViewNativeComponent';
import RNSVGSvgIOS from '../fabric/IOSSvgViewNativeComponent';
import type { Spec } from '../fabric/NativeSvgViewModule';

View File

@@ -1,9 +1,10 @@
import React, { ReactNode } from 'react';
import type { ReactNode } from 'react';
import React from 'react';
import extractViewBox from '../lib/extract/extractViewBox';
import Shape from './Shape';
import RNSVGSymbol from '../fabric/SymbolNativeComponent';
import { NumberProp } from '../lib/extract/types';
import { NativeMethods } from 'react-native';
import type { NumberProp } from '../lib/extract/types';
import type { NativeMethods } from 'react-native';
export interface SymbolProps {
children?: ReactNode;

View File

@@ -1,10 +1,12 @@
import React, { Component } from 'react';
import type { Component } from 'react';
import React from 'react';
import extractProps, { propsAndStyles } from '../lib/extract/extractProps';
import extractTransform from '../lib/extract/extractTransform';
import extractText, { setTSpan, TextChild } from '../lib/extract/extractText';
import type { TextChild } from '../lib/extract/extractText';
import extractText, { setTSpan } from '../lib/extract/extractText';
import { pickNotNil } from '../lib/util';
import Shape from './Shape';
import {
import type {
ColumnMajorTransformMatrix,
CommonPathProps,
FontProps,

View File

@@ -1,8 +1,9 @@
import React, { Component, ReactNode } from 'react';
import type { Component, ReactNode } from 'react';
import React from 'react';
import extractText from '../lib/extract/extractText';
import extractProps, { propsAndStyles } from '../lib/extract/extractProps';
import extractTransform from '../lib/extract/extractTransform';
import {
import type {
ColumnMajorTransformMatrix,
NumberArray,
NumberProp,

View File

@@ -1,7 +1,8 @@
import React, { Component } from 'react';
import type { Component } from 'react';
import React from 'react';
import extractTransform from '../lib/extract/extractTransform';
import { withoutXY } from '../lib/extract/extractProps';
import {
import type {
ColumnMajorTransformMatrix,
NumberProp,
TextPathMethod,
@@ -10,7 +11,8 @@ import {
TextSpecificProps,
TransformProps,
} from '../lib/extract/types';
import extractText, { TextChild } from '../lib/extract/extractText';
import type { TextChild } from '../lib/extract/extractText';
import extractText from '../lib/extract/extractText';
import { idPattern, pickNotNil } from '../lib/util';
import Shape from './Shape';
import TSpan from './TSpan';

View File

@@ -1,13 +1,14 @@
import React, { ReactNode } from 'react';
import type { ReactNode } from 'react';
import React from 'react';
import {
stringifyPropsForFabric,
withoutXY,
} from '../lib/extract/extractProps';
import { CommonPathProps, NumberProp } from '../lib/extract/types';
import type { CommonPathProps, NumberProp } from '../lib/extract/types';
import { idPattern } from '../lib/util';
import Shape from './Shape';
import RNSVGUse from '../fabric/UseNativeComponent';
import { NativeMethods } from 'react-native';
import type { NativeMethods } from 'react-native';
export interface UseProps extends CommonPathProps {
children?: ReactNode;

View File

@@ -1,5 +1,5 @@
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
import {
import type {
Float,
Int32,
WithDefault,

View File

@@ -1,5 +1,6 @@
import { TurboModuleRegistry, TurboModule } from 'react-native';
import { Int32, Float } from 'react-native/Libraries/Types/CodegenTypes';
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';
import type { Int32, Float } from 'react-native/Libraries/Types/CodegenTypes';
type Rect = {
x: Float;

View File

@@ -1,5 +1,6 @@
import { TurboModuleRegistry, TurboModule } from 'react-native';
import { Int32 } from 'react-native/Libraries/Types/CodegenTypes';
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';
import type { Int32 } from 'react-native/Libraries/Types/CodegenTypes';
export interface Spec extends TurboModule {
toDataURL(

View File

@@ -1,5 +1,6 @@
// @ts-ignore
import { Touchable, GestureResponderEvent } from 'react-native';
import type { GestureResponderEvent } from 'react-native';
import { Touchable } from 'react-native';
const PRESS_RETENTION_OFFSET = { top: 20, left: 20, right: 20, bottom: 30 };
// @ts-ignore
const { Mixin } = Touchable;

View File

@@ -1,4 +1,5 @@
import { ColorValue, processColor } from 'react-native';
import type { ColorValue } from 'react-native';
import { processColor } from 'react-native';
const urlIdPattern = /^url\(#(.+)\)$/;

View File

@@ -1,6 +1,6 @@
import extractBrush from './extractBrush';
import extractOpacity from './extractOpacity';
import { extractedProps, FillProps } from './types';
import type { extractedProps, FillProps } from './types';
import { processColor } from 'react-native';
const fillRules: { evenodd: number; nonzero: number } = {

View File

@@ -1,9 +1,10 @@
import React, { Children, ReactElement } from 'react';
import type { ReactElement } from 'react';
import React, { Children } from 'react';
import { processColor } from 'react-native';
import extractOpacity from './extractOpacity';
import extractTransform from './extractTransform';
import { TransformProps } from './types';
import type { TransformProps } from './types';
import units from '../units';
const percentReg = /^([+-]?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)(%?)$/;

View File

@@ -1,4 +1,4 @@
import { NumberProp } from './types';
import type { NumberProp } from './types';
const spaceReg = /\s+/;
const commaReg = /,/g;

View File

@@ -1,4 +1,4 @@
import { NumberProp } from './types';
import type { NumberProp } from './types';
export default function extractOpacity(opacity: NumberProp | void) {
const value = +opacity;

View File

@@ -1,4 +1,4 @@
import { NumberProp } from './types';
import type { NumberProp } from './types';
export default function extractPolyPoints(
points: string | readonly NumberProp[],

View File

@@ -4,7 +4,7 @@ import extractTransform from './extractTransform';
import extractResponder from './extractResponder';
import extractOpacity from './extractOpacity';
import { idPattern } from '../util';
import {
import type {
ClipProps,
extractedProps,
FillProps,

View File

@@ -4,7 +4,7 @@ import extractTransform from './extractTransform';
import extractResponder from './extractResponder';
import extractOpacity from './extractOpacity';
import { idPattern } from '../util';
import {
import type {
ClipProps,
extractedProps,
FillProps,

View File

@@ -1,5 +1,5 @@
import { PanResponder } from 'react-native';
import {
import type {
extractedProps,
ResponderInstanceProps,
ResponderProps,

View File

@@ -1,7 +1,7 @@
import extractBrush from './extractBrush';
import extractOpacity from './extractOpacity';
import extractLengthList from './extractLengthList';
import { extractedProps, StrokeProps } from './types';
import type { extractedProps, StrokeProps } from './types';
const caps = {
butt: 0,

View File

@@ -1,7 +1,8 @@
import React, { Children, ComponentType } from 'react';
import type { ComponentType } from 'react';
import React, { Children } from 'react';
import extractLengthList from './extractLengthList';
import { pickNotNil } from '../util';
import { NumberArray, NumberProp } from './types';
import type { NumberArray, NumberProp } from './types';
import { stringifyPropsForFabric } from './extractProps';
const fontRegExp =

View File

@@ -1,7 +1,7 @@
import { TransformsStyle } from 'react-native';
import type { TransformsStyle } from 'react-native';
import { append, appendTransform, identity, reset, toArray } from '../Matrix2D';
import { parse } from './transform';
import {
import type {
ColumnMajorTransformMatrix,
NumberProp,
TransformedProps,

View File

@@ -1,4 +1,4 @@
import { NumberProp } from './types';
import type { NumberProp } from './types';
export const meetOrSliceTypes: {
[meetOrSlice: string]: number;

View File

@@ -1,10 +1,10 @@
import {
import type {
ColorValue,
GestureResponderEvent,
GestureResponderHandlers,
LayoutChangeEvent,
} from 'react-native';
import React from 'react';
import type React from 'react';
import type { TransformsStyle } from 'react-native';
export type NumberProp = string | number;

View File

@@ -1,17 +1,13 @@
import React, {
Component,
ComponentType,
useEffect,
useMemo,
useState,
} from 'react';
import type { ComponentType } from 'react';
import React, { Component, useEffect, useMemo, useState } from 'react';
import Rect from './elements/Rect';
import Circle from './elements/Circle';
import Ellipse from './elements/Ellipse';
import Polygon from './elements/Polygon';
import Polyline from './elements/Polyline';
import Line from './elements/Line';
import Svg, { SvgProps } from './elements/Svg';
import type { SvgProps } from './elements/Svg';
import Svg from './elements/Svg';
import Path from './elements/Path';
import G from './elements/G';
import Text from './elements/Text';