Skip to content

Commit f2f533a

Browse files
authored
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.
1 parent cb87e75 commit f2f533a

47 files changed

Lines changed: 136 additions & 108 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
module.exports = {
22
extends: '@react-native-community',
3-
rules: { 'no-bitwise': 0, '@typescript-eslint/no-explicit-any': 2 },
3+
parserOptions: {
4+
project: ["./tsconfig.json"],
5+
},
6+
rules: {
7+
'no-bitwise': 'off',
8+
'@typescript-eslint/consistent-type-exports': 'error',
9+
'@typescript-eslint/consistent-type-imports': 'error',
10+
'@typescript-eslint/no-explicit-any': 'error',
11+
},
412
};

src/LocalSvg.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React, { useState, useEffect, Component } from 'react';
2-
import { Platform, Image, ImageSourcePropType } from 'react-native';
2+
import type { ImageSourcePropType } from 'react-native';
3+
import { Platform, Image } from 'react-native';
34

45
import { fetchText } from './xml';
56
import { SvgCss, SvgWithCss } from './css';
6-
import { SvgProps } from './elements/Svg';
7+
import type { SvgProps } from './elements/Svg';
78
import type { Spec } from './fabric/NativeSvgRenderableModule';
89

910
export function getUriFromSource(source: ImageSourcePropType) {

src/ReactNativeSVG.web.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import * as React from 'react';
2+
import type { GestureResponderEvent, TransformsStyle } from 'react-native';
23
import {
3-
GestureResponderEvent,
44
// @ts-ignore
55
unstable_createElement as ucE,
66
createElement as cE,
7-
TransformsStyle,
87
} from 'react-native';
9-
import { NumberArray, NumberProp, TransformProps } from './lib/extract/types';
8+
import type {
9+
NumberArray,
10+
NumberProp,
11+
TransformProps,
12+
} from './lib/extract/types';
1013
import SvgTouchableMixin from './lib/SvgTouchableMixin';
1114
import { resolve } from './lib/resolve';
1215
import { transformsArrayToProps } from './lib/extract/extractTransform';

src/css.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
11
import React, { Component, useEffect, useMemo, useState } from 'react';
2-
import {
3-
camelCase,
4-
err,
5-
fetchText,
2+
import type {
63
JsxAST,
74
Middleware,
8-
parse,
95
Styles,
10-
SvgAst,
116
UriProps,
127
UriState,
138
XmlAST,
149
XmlProps,
1510
XmlState,
1611
} from './xml';
17-
import csstree, {
12+
import { camelCase, err, fetchText, parse, SvgAst } from './xml';
13+
import type {
1814
Atrule,
1915
AtrulePrelude,
2016
CssNode,
2117
Declaration,
2218
DeclarationList,
23-
List,
2419
ListItem,
2520
PseudoClassSelector,
2621
Rule,
2722
Selector,
2823
SelectorList,
2924
} from 'css-tree';
30-
import cssSelect, { Options } from 'css-select';
25+
import csstree, { List } from 'css-tree';
26+
import type { Options } from 'css-select';
27+
import cssSelect from 'css-select';
3128

3229
/*
3330
* Style element inlining experiment based on SVGO

src/elements/Circle.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react';
22
import { extract, stringifyPropsForFabric } from '../lib/extract/extractProps';
3-
import { CommonPathProps, NumberProp } from '../lib/extract/types';
3+
import type { CommonPathProps, NumberProp } from '../lib/extract/types';
44
import Shape from './Shape';
55
import RNSVGCircle from '../fabric/CircleNativeComponent';
6-
import { NativeMethods } from 'react-native';
6+
import type { NativeMethods } from 'react-native';
77

88
export interface CircleProps extends CommonPathProps {
99
cx?: NumberProp;

src/elements/ClipPath.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React, { ReactNode } from 'react';
1+
import type { ReactNode } from 'react';
2+
import React from 'react';
23
import { extract } from '../lib/extract/extractProps';
34
import Shape from './Shape';
45
import RNSVGClipPath from '../fabric/ClipPathNativeComponent';

src/elements/Ellipse.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react';
22
import { extract, stringifyPropsForFabric } from '../lib/extract/extractProps';
3-
import { CommonPathProps, NumberProp } from '../lib/extract/types';
3+
import type { CommonPathProps, NumberProp } from '../lib/extract/types';
44
import Shape from './Shape';
55
import RNSVGEllipse from '../fabric/EllipseNativeComponent';
6-
import { NativeMethods } from 'react-native';
6+
import type { NativeMethods } from 'react-native';
77

88
export interface EllipseProps extends CommonPathProps {
99
cx?: NumberProp;

src/elements/ForeignObject.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import React, { ReactNode } from 'react';
1+
import type { ReactNode } from 'react';
2+
import React from 'react';
23
import {
34
withoutXY,
45
stringifyPropsForFabric,
56
} from '../lib/extract/extractProps';
6-
import { NumberProp } from '../lib/extract/types';
7+
import type { NumberProp } from '../lib/extract/types';
78
import G from './G';
89
import RNSVGForeignObject from '../fabric/ForeignObjectNativeComponent';
9-
import { NativeMethods } from 'react-native';
10+
import type { NativeMethods } from 'react-native';
1011

1112
export interface ForeignObjectProps {
1213
children?: ReactNode;

src/elements/G.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import React, { ReactNode } from 'react';
1+
import type { ReactNode } from 'react';
2+
import React from 'react';
23
import extractProps, { propsAndStyles } from '../lib/extract/extractProps';
34
import { extractFont } from '../lib/extract/extractText';
45
import extractTransform from '../lib/extract/extractTransform';
5-
import {
6+
import type {
67
CommonPathProps,
78
FontProps,
89
NumberProp,
910
TransformProps,
1011
} from '../lib/extract/types';
1112
import Shape from './Shape';
1213
import RNSVGGroup from '../fabric/GroupNativeComponent';
13-
import { NativeMethods } from 'react-native';
14+
import type { NativeMethods } from 'react-native';
1415

1516
export interface GProps extends CommonPathProps, FontProps {
1617
children?: ReactNode;

src/elements/Image.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import React from 'react';
2-
import { Image, ImageProps as RNImageProps, NativeMethods } from 'react-native';
2+
import type { ImageProps as RNImageProps, NativeMethods } from 'react-native';
3+
import { Image } from 'react-native';
34
import { alignEnum, meetOrSliceTypes } from '../lib/extract/extractViewBox';
45
import {
56
stringifyPropsForFabric,
67
withoutXY,
78
} from '../lib/extract/extractProps';
8-
import {
9+
import type {
910
ClipProps,
1011
CommonMaskProps,
1112
NativeProps,

0 commit comments

Comments
 (0)