react-doctor/rn-no-deep-imports
Import from the "react-native" package root, not the deprecated "react-native/Libraries/..." subpath: import { Alert } from "react-native"
- Category: Bugs
- Severity: warn
- Source:
oxlint-plugin-react-doctor - Framework: react-native
- Enabled when: framework=react-native and capabilities=react-native
- Tags: react-native
- Default: Enabled
Validate the diagnostic
Confirm the reported code matches this rule before you edit it.
Fires on an ImportDeclaration, re-export ExportNamedDeclaration (one with a source), or ExportAllDeclaration whose module string starts with "react-native/Libraries/" AND whose final path segment is one of the curated PUBLIC_RN_ROOT_EXPORTS (View, Text, Image, ScrollView, FlatList, TextInput, Pressable, Button, StyleSheet, Alert, Animated, Platform, Dimensions, Keyboard, StatusBar, etc.) — or any path under "react-native/Libraries/NewAppScreen", which gets a tailored message. Default and named value imports both count; a mixed import like { View, type ViewProps } still fires because a value specifier is present. Suppress: it must NOT fire on a pure type-only import/re-export — "import type { ViewProps } from ..." OR the inline all-type form "import { type ColorSchemeName } from ..." / "export { type ViewProps } from ..." — since many RN internal types are not root-exported. Also suppress on Codegen/internal-only deep paths with no root equivalent whose leaf segment is NOT in the set (TurboModule/RCTExport, Image/resolveAssetSource, Utilities/PolyfillFunctions), on namespace-module sub-exports like { linear } from "react-native/Libraries/Animated/Easing" (root only exports the Easing object), on tooling subpaths outside Libraries/ ("react-native/jest-preset", "react-native/jest/setup"), on relative paths that merely contain the substring ("./react-native/Libraries/Alert/Alert"), and on jest.mock("react-native/Libraries/...") calls since those are not import statements.
How to fix
Follow the rule guidance while preserving unrelated behavior.
Copyable fix prompt
Copy this self-contained prompt into your coding agent after you confirm the diagnostic.
Related rules
More Bugs rules from the rules reference:
react-doctor/rn-no-deprecated-modules: Import from the community package instead — deprecated modules were removed from the react-native corereact-doctor/rn-no-dimensions-get: Use `const { width, height } = useWindowDimensions()` — it updates reactively on rotation and resizereact-doctor/rn-no-falsy-and-render: Guard numeric-looking conditions: {count > 0 && <X/>}, {Boolean(count) && <X/>}, or {count ? <X/> : null}react-doctor/rn-no-image-children: Replace <Image> with <ImageBackground> to render content over the image: <ImageBackground source={src}>...children...</ImageBackground>react-doctor/rn-no-inline-flatlist-renderitem: Extract renderItem to a named function or wrap in useCallback to avoid re-creating on every render