Skip to content

Commit 8e010d1

Browse files
authored
[eslint] Consistent import rules (#4087)
## Description This PR aims to add new eslint rules, that: - Require sorted imports - Require `type` when importing only types As there would be too many changes, I've decided to split this into two PRs. This one will be base, similarly as in monorepo migration. - #4088 - #4089 ## Test plan - `yarn lint-js` - `yarn ts-check` <img width="1069" height="482" alt="image" src="https://github.com/user-attachments/assets/5f4e79f6-ae0a-4ec4-9073-b23f89a0f569" />
1 parent 090e822 commit 8e010d1

301 files changed

Lines changed: 1504 additions & 1710 deletions

File tree

Some content is hidden

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

.eslintrc.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
"@typescript-eslint/no-unsafe-return": "warn",
4444
"@typescript-eslint/no-non-null-assertion": "warn",
4545
"@typescript-eslint/ban-types": "warn",
46+
"@typescript-eslint/consistent-type-imports": "error",
47+
"@typescript-eslint/consistent-type-exports": "error",
4648

4749
// common
4850
"@typescript-eslint/explicit-module-boundary-types": "off",
@@ -85,6 +87,7 @@
8587
],
8688
"curly": "error",
8789
"spaced-comment": "error",
88-
"no-alert": "warn"
90+
"no-alert": "warn",
91+
"sort-imports": "error"
8992
}
9093
}

apps/basic-example/src/App.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import * as React from 'react';
2-
import { SafeAreaView, Platform } from 'react-native';
2+
import { Platform, SafeAreaView } from 'react-native';
3+
import ContentsButton from './ContentsButton';
34
import { GestureHandlerRootView } from 'react-native-gesture-handler';
4-
5-
import Navigator from './Navigator';
6-
7-
import Text from './Text';
85
import NativeDetector from './NativeDetector';
6+
import Navigator from './Navigator';
97
import RuntimeDecoration from './RuntimeDecoration';
10-
import ContentsButton from './ContentsButton';
8+
import Text from './Text';
119

1210
const EXAMPLES = [
1311
{

apps/basic-example/src/ContentsButton.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import React from 'react';
2-
import { View, StyleSheet, Text, SafeAreaView } from 'react-native';
31
import {
42
GestureHandlerRootView,
5-
ScrollView,
63
RectButton,
4+
ScrollView,
75
} from 'react-native-gesture-handler';
6+
import { SafeAreaView, StyleSheet, Text, View } from 'react-native';
7+
import React from 'react';
88

99
export default function ComplexUI() {
1010
return (

apps/basic-example/src/NativeDetector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as React from 'react';
22
import { Animated, Button, useAnimatedValue } from 'react-native';
33
import {
4-
GestureHandlerRootView,
54
GestureDetector,
5+
GestureHandlerRootView,
66
usePanGesture,
77
} from 'react-native-gesture-handler';
88

apps/basic-example/src/Navigator.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { BackHandler, Pressable, Text, View } from 'react-native';
12
import React, { useEffect, useState } from 'react';
2-
import { View, Text, Pressable, BackHandler } from 'react-native';
33

44
export interface RouteInfo {
55
component: React.ComponentType;

apps/basic-example/src/RuntimeDecoration.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import * as React from 'react';
2-
import { StyleSheet, Text, View } from 'react-native';
3-
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
4-
5-
import { COLORS } from './colors';
62
import Animated, {
73
runOnJS,
84
useAnimatedStyle,
95
useSharedValue,
106
} from 'react-native-reanimated';
7+
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
8+
import { StyleSheet, Text, View } from 'react-native';
9+
import { COLORS } from './colors';
1110
import { useState } from 'react';
1211

1312
export function RuntimeChecker({

apps/basic-example/src/Text.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import * as React from 'react';
2-
import { StyleSheet, Text, View } from 'react-native';
32
import {
43
Gesture,
54
GestureDetector,
65
InterceptingGestureDetector,
76
VirtualGestureDetector,
87
useTapGesture,
98
} from 'react-native-gesture-handler';
10-
9+
import { StyleSheet, Text, View } from 'react-native';
1110
import { COLORS } from './colors';
1211

1312
function NativeDetectorExample() {

apps/common-app/src/ListWithHeader/Header.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import React, { useEffect } from 'react';
2-
import { Platform, StyleSheet } from 'react-native';
31
import Animated, {
42
Easing,
5-
SharedValue,
63
interpolate,
74
measure,
85
useAnimatedRef,
@@ -11,7 +8,10 @@ import Animated, {
118
useSharedValue,
129
withTiming,
1310
} from 'react-native-reanimated';
11+
import { Platform, StyleSheet } from 'react-native';
12+
import React, { useEffect } from 'react';
1413
import { COLORS } from '../common';
14+
import type { SharedValue } from 'react-native-reanimated';
1515

1616
// eslint-disable-next-line import-x/no-commonjs, @typescript-eslint/no-var-requires
1717
const SIGNET = require('./signet.png');

apps/common-app/src/ListWithHeader/ListWithHeader.tsx

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
1-
import React, { useEffect } from 'react';
2-
import {
3-
Platform,
4-
ScrollViewProps,
5-
SectionList,
6-
SectionListProps,
7-
StyleSheet,
8-
} from 'react-native';
91
import Animated, {
10-
SharedValue,
2+
runOnJS,
3+
useAnimatedProps,
4+
useAnimatedReaction,
115
useAnimatedRef,
6+
useAnimatedStyle,
127
useScrollViewOffset,
13-
useAnimatedReaction,
148
useSharedValue,
15-
useAnimatedProps,
16-
useAnimatedStyle,
17-
runOnJS,
189
withSpring,
19-
AnimatedRef,
2010
} from 'react-native-reanimated';
11+
import type { AnimatedRef, SharedValue } from 'react-native-reanimated';
12+
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
2113
import Header, { HEADER_HEIGHT } from './Header';
22-
import {
23-
Gesture,
24-
GestureDetector,
25-
GestureType,
26-
} from 'react-native-gesture-handler';
14+
import { Platform, SectionList, StyleSheet } from 'react-native';
15+
import React, { useEffect } from 'react';
16+
import type { ScrollViewProps, SectionListProps } from 'react-native';
17+
import type { GestureType } from 'react-native-gesture-handler';
2718

2819
const IS_ANDROID = Platform.OS === 'android';
2920

apps/common-app/src/common.tsx

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
1+
import Animated, {
2+
Easing,
3+
useAnimatedStyle,
4+
useSharedValue,
5+
withTiming,
6+
} from 'react-native-reanimated';
7+
import type { Platform, StyleProp, ViewStyle } from 'react-native';
18
import React, {
2-
RefObject,
39
useCallback,
410
useEffect,
511
useImperativeHandle,
612
useRef,
713
useState,
814
} from 'react';
9-
import {
10-
Text,
11-
StyleSheet,
12-
ViewStyle,
13-
StyleProp,
14-
View,
15-
Platform,
16-
} from 'react-native';
17-
import Animated, {
18-
Easing,
19-
useAnimatedStyle,
20-
useSharedValue,
21-
withTiming,
22-
} from 'react-native-reanimated';
15+
import { StyleSheet, Text, View } from 'react-native';
16+
import type { RefObject } from 'react';
2317

2418
export interface Example {
2519
name: string;

0 commit comments

Comments
 (0)