Skip to content

Commit b73fe14

Browse files
committed
Add local-rules/require-top-level-exports ESLint rule
It enforces that all top-level declarations in test files are exported. The rule is implemented as a local ESLint plugin (eslint-plugin-local-rules) linked via file: dependency — no external packages needed. Applied to apps/src/tests/** via an override in apps/.eslintrc.js. All existing test files (1411 declarations) have been updated to comply.
1 parent 6757f87 commit b73fe14

261 files changed

Lines changed: 1552 additions & 1417 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.

apps/.eslintrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,12 @@ module.exports = {
88
'react-native/no-inline-styles': 'off',
99
},
1010
},
11+
{
12+
files: ['src/tests/**/*.tsx', 'src/tests/**/*.ts'],
13+
plugins: ['local-rules'],
14+
rules: {
15+
'local-rules/require-top-level-exports': 'error',
16+
},
17+
},
1118
],
1219
};

apps/src/tests/IssueTestsScreen.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from '@apps/shared/styling/adapter/react-navigation';
1414
import { createNativeStackNavigator } from '@react-navigation/native-stack';
1515

16-
const SCREENS: Record<
16+
export const SCREENS: Record<
1717
string,
1818
{
1919
title: string;
@@ -35,15 +35,15 @@ Object.keys(Tests).forEach(testName => {
3535
};
3636
});
3737

38-
type IssueTestsStackParamList = {
38+
export type IssueTestsStackParamList = {
3939
Main: undefined;
4040
} & {
4141
[P in keyof typeof SCREENS]: undefined;
4242
};
4343

44-
const issueRegex = /Test(?<issue>\d+)(?<case>.*)/;
44+
export const issueRegex = /Test(?<issue>\d+)(?<case>.*)/;
4545

46-
const screens = Object.keys(SCREENS).sort((name1, name2) => {
46+
export const screens = Object.keys(SCREENS).sort((name1, name2) => {
4747
const spec1 = issueRegex.exec(name1)?.groups;
4848
const spec2 = issueRegex.exec(name2)?.groups;
4949

@@ -65,7 +65,7 @@ const screens = Object.keys(SCREENS).sort((name1, name2) => {
6565
}
6666
});
6767

68-
function MainScreen(props: {
68+
export function MainScreen(props: {
6969
navigation: NavigationProp<IssueTestsStackParamList>;
7070
}) {
7171
const [searchQuery, setSearchQuery] = React.useState('');

apps/src/tests/component-integration-tests/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ export const COMPONENT_SCENARIOS = {
1616
ScrollView: ScrollViewScenarioGroup,
1717
} as const;
1818

19-
type ParamsList = { [k: keyof typeof COMPONENT_SCENARIOS]: undefined } & {
19+
export type ParamsList = { [k: keyof typeof COMPONENT_SCENARIOS]: undefined } & {
2020
Home: undefined;
2121
};
2222

23-
function HomeScreen() {
23+
export function HomeScreen() {
2424
return (
2525
<ScrollView contentInsetAdjustmentBehavior="automatic">
2626
{Object.entries(COMPONENT_SCENARIOS).map(([key, scenarioGroup]) => (
@@ -35,7 +35,7 @@ function HomeScreen() {
3535
);
3636
}
3737

38-
const Stack = createNativeStackNavigator<ParamsList>();
38+
export const Stack = createNativeStackNavigator<ParamsList>();
3939

4040
export default function App() {
4141
return (

apps/src/tests/component-integration-tests/orientation/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ScenarioGroup } from '@apps/tests/shared/helpers';
22
import StackInTabs from './orientation-stack-in-tabs';
33
import TabsInStack from './orientation-tabs-in-stack';
44

5-
const scenarios = { StackInTabs, TabsInStack };
5+
export const scenarios = { StackInTabs, TabsInStack };
66

77
const OrientationScenarioGroup: ScenarioGroup<keyof typeof scenarios> = {
88
name: 'Orientation tests',

apps/src/tests/component-integration-tests/orientation/orientation-stack-in-tabs.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ import {
1616
DEFAULT_TAB_ROUTE_OPTIONS,
1717
} from '@apps/shared/gamma/containers/tabs';
1818

19-
const scenarioDescription: ScenarioDescription = {
19+
export const scenarioDescription: ScenarioDescription = {
2020
name: 'StackInTabs',
2121
details:
2222
'Configuration in Stack contained within TabScreen always takes precedence',
2323
key: 'cit-orientation-stack-in-tabs',
2424
platforms: ['ios'],
2525
};
2626

27-
function ConfigScreen() {
27+
export function ConfigScreen() {
2828
const {
2929
routeKey: tabRouteKey,
3030
routeOptions: tabRouteOptions,
@@ -62,19 +62,19 @@ function ConfigScreen() {
6262
);
6363
}
6464

65-
const STACK_ROUTE_CONFIGS: StackRouteConfig[] = [
65+
export const STACK_ROUTE_CONFIGS: StackRouteConfig[] = [
6666
{
6767
name: 'Screen1',
6868
Component: ConfigScreen,
6969
options: {},
7070
},
7171
];
7272

73-
function StackScreen() {
73+
export function StackScreen() {
7474
return <StackContainer routeConfigs={STACK_ROUTE_CONFIGS} />;
7575
}
7676

77-
const TAB_ROUTE_CONFIGS: TabRouteConfig[] = [
77+
export const TAB_ROUTE_CONFIGS: TabRouteConfig[] = [
7878
{
7979
name: 'Tab1',
8080
Component: StackScreen,

apps/src/tests/component-integration-tests/orientation/orientation-tabs-in-stack.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ import {
1616
DEFAULT_TAB_ROUTE_OPTIONS,
1717
} from '@apps/shared/gamma/containers/tabs';
1818

19-
const scenarioDescription: ScenarioDescription = {
19+
export const scenarioDescription: ScenarioDescription = {
2020
name: 'TabsInStack',
2121
details:
2222
'Configuration in Tabs contained within StackScreen should have precedence over configuraton in Stack contained within TabScreen',
2323
key: 'cit-orientation-tabs-in-stack',
2424
platforms: ['ios'],
2525
};
2626

27-
function ConfigScreen() {
27+
export function ConfigScreen() {
2828
const {
2929
routeKey: stackRouteKey,
3030
routeOptions: stackRouteOptions,
@@ -62,7 +62,7 @@ function ConfigScreen() {
6262
);
6363
}
6464

65-
const TAB_ROUTE_CONFIGS: TabRouteConfig[] = [
65+
export const TAB_ROUTE_CONFIGS: TabRouteConfig[] = [
6666
{
6767
name: 'Tab1',
6868
Component: ConfigScreen,
@@ -81,11 +81,11 @@ const TAB_ROUTE_CONFIGS: TabRouteConfig[] = [
8181
},
8282
];
8383

84-
function TabsScreen() {
84+
export function TabsScreen() {
8585
return <TabsContainer routeConfigs={TAB_ROUTE_CONFIGS} />;
8686
}
8787

88-
const STACK_ROUTE_CONFIGS: StackRouteConfig[] = [
88+
export const STACK_ROUTE_CONFIGS: StackRouteConfig[] = [
8989
{
9090
name: 'Screen1',
9191
Component: TabsScreen,

apps/src/tests/component-integration-tests/scroll-view/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ScenarioGroup } from '@apps/tests/shared/helpers';
22

3-
const scenarios = {};
3+
export const scenarios = {};
44

55
const ScrollViewScenarioGroup: ScenarioGroup<keyof typeof scenarios> = {
66
name: 'ScrollView integration tests',

apps/src/tests/issue-tests/Test1017.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ import { ScrollView } from 'react-native-gesture-handler';
1111

1212
import { Colors } from '@apps/shared/styling';
1313

14-
type DataItem = {
14+
export type DataItem = {
1515
title: string;
1616
value: number;
1717
};
1818

19-
enum Route {
19+
export enum Route {
2020
FirstScreen = 'FirstScreen',
2121
SecondScreen = 'SecondScreen',
2222
}
2323

24-
type RootStackParamList = {
24+
export type RootStackParamList = {
2525
[Route.FirstScreen]: undefined;
2626
[Route.SecondScreen]: undefined;
2727
};
@@ -30,14 +30,14 @@ LogBox.ignoreLogs([
3030
'VirtualizedLists should never be nested inside plain ScrollViews',
3131
]);
3232

33-
const Stack = createStackNavigator();
33+
export const Stack = createStackNavigator();
3434

35-
const dataset = Array.from<unknown, DataItem>({ length: 100 }, (_, i) => ({
35+
export const dataset = Array.from<unknown, DataItem>({ length: 100 }, (_, i) => ({
3636
title: `Title ${i}`,
3737
value: i,
3838
}));
3939

40-
const Screen: React.FC<{
40+
export const Screen: React.FC<{
4141
route: RouteProp<RootStackParamList, any>;
4242
navigation: StackNavigationProp<RootStackParamList, any>;
4343
}> = ({ route, navigation }) => {
@@ -102,7 +102,7 @@ const App: React.FC = () => {
102102
);
103103
};
104104

105-
const styles = StyleSheet.create({
105+
export const styles = StyleSheet.create({
106106
headerWrapper: {
107107
overflow: 'hidden',
108108
},

apps/src/tests/issue-tests/Test1031.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from '@react-navigation/native-stack';
88
import { useHeaderHeight } from '@react-navigation/elements';
99

10-
const Stack = createNativeStackNavigator();
10+
export const Stack = createNativeStackNavigator();
1111

1212
export default function App() {
1313
return (
@@ -21,7 +21,7 @@ export default function App() {
2121
);
2222
}
2323

24-
function First({
24+
export function First({
2525
navigation,
2626
}: {
2727
navigation: NativeStackNavigationProp<ParamListBase>;
@@ -35,7 +35,7 @@ function First({
3535
);
3636
}
3737

38-
function Second({
38+
export function Second({
3939
navigation,
4040
}: {
4141
navigation: NativeStackNavigationProp<ParamListBase>;

apps/src/tests/issue-tests/Test1032.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
NativeStackNavigationProp,
77
} from '@react-navigation/native-stack';
88

9-
const Stack = createNativeStackNavigator();
9+
export const Stack = createNativeStackNavigator();
1010

1111
export default function App() {
1212
const [gestureEnabled, setGestureEnable] = React.useState(false);
@@ -26,7 +26,7 @@ export default function App() {
2626
);
2727
}
2828

29-
function First({
29+
export function First({
3030
navigation,
3131
}: {
3232
navigation: NativeStackNavigationProp<ParamListBase>;
@@ -41,7 +41,7 @@ function First({
4141
);
4242
}
4343

44-
function Second() {
44+
export function Second() {
4545
return (
4646
<View style={{ backgroundColor: '#FFF' }}>
4747
<Button

0 commit comments

Comments
 (0)